добавил переделывание паспортов

This commit is contained in:
Дмитрий Шиманский
2023-10-26 19:57:40 +03:00
parent b4f1dfdbb4
commit d612c80bc9
13 changed files with 622 additions and 63 deletions

View File

@@ -8,7 +8,9 @@ using Microsoft.EntityFrameworkCore;
using spworlds.Types;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Linq;
namespace DiscordApp.Justice.Interactions
{
@@ -18,9 +20,90 @@ namespace DiscordApp.Justice.Interactions
[ComponentInteraction("newPassport")]
public async Task AplyWork()
=> await Context.Interaction.RespondWithModalAsync<NewPassportModal>("passportModal");
[ComponentInteraction("reworkPassport")]
public async Task reCreatePassport()
=> await Context.Interaction.RespondWithModalAsync<ReWorkPassportModal>("reworkpassportModal");
[ComponentInteraction("reNewPassportButton")]
public async Task reNewPassportModal() => await Context.Interaction.RespondWithModalAsync<NewPassportModal>("ReNewPassportModal");
[ModalInteraction("passportModal")]
public async Task createPassportInteraction(NewPassportModal modal)
[ModalInteraction("reworkpassportModal")]
public async Task reCreatePassportInteraction(ReWorkPassportModal modal)
{
await DeferAsync(true);
double passportId = modal.Id;
bool recreatePassport = modal.IsNewPassport == 1;
if (recreatePassport)
{
await FollowupAsync("Нажмите на кнопку ниже", components: new ComponentBuilder().WithButton(new ButtonBuilder("Кнопочка", "reNewPassportButton")).Build(), ephemeral: true);
}
else
{
var passport = Startup.appDbContext.Passport.Where(x => x.Id == passportId).FirstOrDefault();
if (passport == null) { await FollowupAsync("ID паспорта не правильный, или не существует.", ephemeral: true); return; }
SocketGuildUser user = Context.Guild.GetUser(Context.User.Id);
Random random = new();
User spUser = await User.CreateUser(passport.Applicant);
DateTimeOffset toTime = DateTime.Now.AddDays(31);
int id = random.Next(00001, 99999);
long unixTime = toTime.ToUnixTimeSeconds();
long nowUnixTime = DateTimeOffset.Now.ToUnixTimeSeconds();
passport.Id = id;
passport.Date = nowUnixTime;
var passportData = new EmbedFieldBuilder()
.WithName("Данные паспорта:")
.WithValue(@$"
Имя: {passport.Applicant}
РП Имя: {passport.RpName}
Айди: {id}
Благотворитель: {passport.Support}
Гендер: {passport.Gender}
Дата рождения: <t:{passport.birthDate}:D>")
.WithIsInline(true);
var author = new EmbedAuthorBuilder()
.WithName(user.DisplayName)
.WithIconUrl(user.GetDisplayAvatarUrl());
var embed = new EmbedBuilder()
.WithTitle("**Паспорт переделан**")
.AddField(passportData)
.AddField(new EmbedFieldBuilder().WithName("Составитель: ").WithValue(user.GlobalName).WithIsInline(true))
.AddField(new EmbedFieldBuilder().WithName("Доступен до: ").WithValue($"<t:{toTime.ToUnixTimeSeconds()}:D>").WithIsInline(true))
.WithThumbnailUrl(spUser.GetSkinPart(SkinPart.face))
.WithColor(Color.DarkBlue)
.WithAuthor(author)
.WithTimestamp(toTime)
.Build();
if (Startup.appDbContext.Passport.FindAsync(passport.Id).Result != null)
{
bool isUnical = false;
while (!isUnical)
{
id = random.Next(00001, 99999);
passport.Id = id;
Console.WriteLine(passport.Id);
if (Startup.appDbContext.Passport.FindAsync(passport.Id).Result == null) { break; }
}
}
await Startup.appDbContext.Passport.AddAsync(passport);
await Startup.appDbContext.SaveChangesAsync();
await FollowupAsync($"ID для паспорта: {id}", embed: embed, ephemeral: true);
var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel;
var message = await channel.SendMessageAsync(embed: embed);
}
}
[ModalInteraction("ReNewPassportModal")]
public async Task renewPassportInteraction(NewPassportModal modal)
{
await DeferAsync(true);
string name = modal.NickName;
@@ -32,21 +115,17 @@ namespace DiscordApp.Justice.Interactions
SocketGuildUser user = Context.Guild.GetUser(Context.User.Id);
Supporter supporter;
Random random = new();
spworlds.Types.User spUser = await spworlds.Types.User.CreateUser(name);
User spUser = await User.CreateUser(name);
DateTimeOffset toTime = DateTime.Now.AddDays(14);
DateTimeOffset toTime = DateTime.Now.AddDays(31);
DateTime birthDate;
int id = random.Next(00001, 99999);
long unixTime;
long unixTime = toTime.ToUnixTimeSeconds();
long toUnixTime = DateTimeOffset.Now.ToUnixTimeSeconds();
try
{
birthDate = DateTime.Parse(birthday);
unixTime = ((DateTimeOffset)birthDate).ToUnixTimeSeconds();
if (birthDate.AddDays(14) < DateTime.Now)
{
await FollowupAsync($"Возможно, игрок {name} больше не новичек, и бесплатный паспорт ему не положен!", ephemeral: true);
}
}
catch
{
@@ -74,29 +153,121 @@ namespace DiscordApp.Justice.Interactions
return;
}
Passport passport = new()
{
Employee = user.Id,
RpName = RpName,
Gender = gender,
Date = unixTime,
birthDate = ((DateTimeOffset)birthDate).ToUnixTimeSeconds(),
Applicant = name,
Id = id,
Support = supporter
};
if (Startup.appDbContext.Passport.FindAsync(passport.Id).Result != null)
{
bool isUnical = false;
while (!isUnical)
{
id = random.Next(00001, 99999);
passport.Id = id;
Console.WriteLine(passport.Id);
if (Startup.appDbContext.Passport.FindAsync(passport.Id).Result == null) { break; }
}
}
var passportData = new EmbedFieldBuilder()
.WithName("Данные паспорта:")
.WithValue($"```\nИмя: {name}\nРП Имя: {RpName}\nАйди: {id}\nБлаготворитель: {supporter}\nГендер: {gender}\nДата рождения: {birthDate.ToShortDateString()}```")
.WithIsInline(true);
.WithValue(@$"
Имя: {passport.Applicant}
РП Имя: {passport.RpName}
Айди: {id}
Благотворитель: {passport.Support}
Гендер: {passport.Gender}
Дата рождения: <t:{passport.birthDate}:D>").WithIsInline(true);
var author = new EmbedAuthorBuilder()
.WithName(user.DisplayName)
.WithIconUrl(user.GetDisplayAvatarUrl());
var faceUrl = "https://visage.surgeplay.com/face/64/" + spUser.Uuid;
Console.WriteLine(faceUrl);
var embed = new EmbedBuilder()
.WithTitle("**Новый паспорт**")
.WithTitle("**Паспорт переделан**")
.AddField(passportData)
.AddField(new EmbedFieldBuilder().WithName("Составитель: ").WithValue(user.GlobalName).WithIsInline(true))
.AddField(new EmbedFieldBuilder().WithName("Доступен до: ").WithValue($"<t:{toTime.ToUnixTimeSeconds()}:D>").WithIsInline(true))
.WithThumbnailUrl(faceUrl)
.WithThumbnailUrl(spUser.GetSkinPart(SkinPart.face))
.WithColor(Color.DarkBlue)
.WithAuthor(author)
.WithTimestamp(toTime)
.Build();
await Startup.appDbContext.Passport.AddAsync(passport);
await Startup.appDbContext.SaveChangesAsync();
await FollowupAsync($"ID для паспорта: {id}", embed: embed, ephemeral: true);
var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel;
var message = await channel.SendMessageAsync(embed: embed);
}
[ModalInteraction("passportModal")]
public async Task createPassportInteraction(NewPassportModal modal)
{
await DeferAsync(true);
string name = modal.NickName;
string RpName = modal.RPName;
int supporterInt = modal.Supporter;
string birthday = modal.Birthday;
string gender = modal.Gender;
SocketGuildUser user = Context.Guild.GetUser(Context.User.Id);
Supporter supporter;
Random random = new();
User spUser = await User.CreateUser(name);
DateTimeOffset toTime = DateTime.Now.AddDays(14);
DateTime birthDate;
int id = random.Next(00001, 99999);
long unixTime;
try
{
birthDate = DateTime.Parse(birthday);
unixTime = ((DateTimeOffset)birthDate).ToUnixTimeSeconds();
if (birthDate.AddDays(14) < DateTime.Now)
{
await FollowupAsync($"Возможно, игрок {name} больше не новичек, и бесплатный паспорт ему не положен! Оформляю паспорт на месяц...0", ephemeral: true);
toTime = DateTimeOffset.Now.AddDays(31);
}
}
catch (Exception ex)
{
await FollowupAsync($"Возможно, с датой {modal.Birthday} какая-то ошибка, попробуйте такой тип: 14.02.2023", ephemeral: true);
Console.WriteLine($"Error in 237-243 line. Error: {ex.Message}");
return;
}
switch (supporterInt)
{
case 0:
supporter = Supporter.None;
break;
case 1:
supporter = Supporter.FirstLvl;
break;
case 2:
supporter = Supporter.SecondLvl;
break;
case 3:
supporter = Supporter.ThirdLvl;
break;
default:
await FollowupAsync("Неправильно указан уровень благотворителя. Используйте числа от 0 до 3(в зависимости от уровня)", ephemeral: true);
return;
}
Passport passport = new()
{
Employee = user.Id,
@@ -113,7 +284,6 @@ namespace DiscordApp.Justice.Interactions
bool isUnical = false;
while (!isUnical)
{
id = random.Next(00001, 99999);
passport.Id = id;
Console.WriteLine(passport.Id);
@@ -121,7 +291,31 @@ namespace DiscordApp.Justice.Interactions
}
}
var passportData = new EmbedFieldBuilder()
.WithName("Данные паспорта:")
.WithValue(@$"
Имя: {passport.Applicant}
РП Имя: {passport.RpName}
Айди: {id}
Благотворитель: {passport.Support}
Гендер: {passport.Gender}
Дата рождения: <t:{passport.birthDate}:D>")
.WithIsInline(true);
var author = new EmbedAuthorBuilder()
.WithName(user.DisplayName)
.WithIconUrl(user.GetDisplayAvatarUrl());
var embed = new EmbedBuilder()
.WithTitle("**Новый паспорт**")
.AddField(passportData)
.AddField(new EmbedFieldBuilder().WithName("Составитель: ").WithValue(user.GlobalName).WithIsInline(true))
.AddField(new EmbedFieldBuilder().WithName("Доступен до: ").WithValue($"<t:{toTime.ToUnixTimeSeconds()}:D>").WithIsInline(true))
.WithThumbnailUrl(spUser.GetSkinPart(SkinPart.face))
.WithColor(Color.DarkBlue)
.WithAuthor(author)
.WithTimestamp(toTime)
.Build();
await Startup.appDbContext.Passport.AddAsync(passport);
@@ -159,4 +353,18 @@ namespace DiscordApp.Justice.Interactions
}
public class ReWorkPassportModal : IModal
{
public string Title => "Создание паспорта";
[InputLabel("ID паспорта")]
[ModalTextInput("id", TextInputStyle.Short, placeholder: "82-777", maxLength: 7)]
public double Id { get; set; }
[InputLabel("Новые данные(0/1)")]
[ModalTextInput("isNewPassportData", TextInputStyle.Short, placeholder: "1 - да, 0 - нет", maxLength: 1, initValue: "0")]
public int IsNewPassport { get; set; }
}
}