mirror of
https://github.com/yawaflua/PL_JusticeBot.git
synced 2025-12-10 12:29:31 +02:00
updated
This commit is contained in:
55
Justice/Interactions/PassportGetterInteraction.cs
Normal file
55
Justice/Interactions/PassportGetterInteraction.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Discord;
|
||||
using Discord.Interactions;
|
||||
using DiscordApp.Database.Tables;
|
||||
using DiscordApp.Justice.Modals;
|
||||
|
||||
namespace DiscordApp.Justice.Interactions
|
||||
{
|
||||
public class PassportGetterInteraction : InteractionModuleBase<SocketInteractionContext>
|
||||
{
|
||||
[ComponentInteraction("searchPassport")]
|
||||
public async Task searchPassportInteraction() => await RespondWithModalAsync<IPassportGetter>("GetPassportModal");
|
||||
|
||||
[ModalInteraction("GetPassportModal")]
|
||||
public async Task getPassportInteraction(IPassportGetter modal)
|
||||
{
|
||||
await DeferAsync(true);
|
||||
int passportId;
|
||||
Passport passport;
|
||||
bool isInteger = int.TryParse(modal.passport, out passportId);
|
||||
if (isInteger)
|
||||
{
|
||||
passport = await Startup.appDbContext.Passport.FindAsync(passportId);
|
||||
}
|
||||
else
|
||||
{
|
||||
passport = Startup.appDbContext.Passport.Where(k => k.Applicant == modal.passport).FirstOrDefault();
|
||||
}
|
||||
|
||||
if (passport == null)
|
||||
{
|
||||
await FollowupAsync("Игрок или паспорт не найден в базе данных, попробуйте использовать старого бота.", ephemeral: true);
|
||||
return;
|
||||
}
|
||||
var fields = new List<EmbedFieldBuilder>()
|
||||
{
|
||||
new EmbedFieldBuilder().WithName("Никнейм").WithValue(passport.Applicant).WithIsInline(true),
|
||||
new EmbedFieldBuilder().WithName("РП Имя").WithValue(passport.RpName).WithIsInline(true),
|
||||
new EmbedFieldBuilder().WithName("Гендер").WithValue(passport.Gender).WithIsInline(false),
|
||||
new EmbedFieldBuilder().WithName("Благотворитель").WithValue((int)passport.Support).WithIsInline(false),
|
||||
new EmbedFieldBuilder().WithName("Дата рождения").WithValue($"<t:{passport.birthDate}:D>").WithIsInline(false),
|
||||
new EmbedFieldBuilder().WithName("Номер паспорта").WithValue(passport.Id).WithIsInline(true),
|
||||
new EmbedFieldBuilder().WithName("Годен до").WithValue($"<t:{passport.Date}:D>").WithIsInline(true),
|
||||
new EmbedFieldBuilder().WithName("Паспортист").WithValue($"<@{passport.Employee}>").WithIsInline(true)
|
||||
};
|
||||
var spUser = await spworlds.Types.User.CreateUser(passport.Applicant);
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle("**Информация о паспорте**")
|
||||
.WithFields(fields)
|
||||
.WithThumbnailUrl(spUser.GetSkinPart(spworlds.Types.SkinPart.face))
|
||||
.Build();
|
||||
await FollowupAsync(embed:embed, ephemeral: true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user