This commit is contained in:
Дмитрий Шиманский
2023-11-09 00:24:18 +03:00
parent 0b218a4c6d
commit dde8b38520
16 changed files with 243 additions and 40 deletions

View File

@@ -0,0 +1,31 @@
using Discord.Interactions;
using Discord;
namespace DiscordApp.Justice.Commands
{
public class Getters : InteractionModuleBase<SocketInteractionContext>
{
[SlashCommand("embed-getter-passport", "Отправляет сообщение для поиска паспорта")]
[DefaultMemberPermissions(GuildPermission.Administrator)]
public async Task getPassport()
{
await DeferAsync(true);
var embed = new EmbedBuilder()
.WithTitle("Получение информации о паспорте")
.WithDescription("Нажав на кнопку ниже вы можете получить данные о том, или ином игроке")
.WithColor(Color.DarkBlue)
.Build();
var components = new ComponentBuilder()
.WithButton(new ButtonBuilder()
{
CustomId = "searchPassport",
Label = "Поиск паспорта",
Style = ButtonStyle.Success
})
.Build();
var channel = Context.Channel as ITextChannel;
await channel.SendMessageAsync(embed: embed, components: components);
await FollowupAsync("Готово!", ephemeral: true);
}
}
}

View File

@@ -0,0 +1,26 @@
using Discord.Interactions;
using Discord;
namespace DiscordApp.Justice.Commands
{
public class Notary : InteractionModuleBase<SocketInteractionContext>
{
[SlashCommand("notary-embed", "Отправляет сообщение с кнопками для нотариусов")]
[DefaultMemberPermissions(GuildPermission.Administrator)]
public async Task sendNotaryEmbed()
{
await DeferAsync(true);
var Embed = new EmbedBuilder()
.WithTitle("**Заверка документа**")
.WithDescription("Ниже вы можете нажать на кнопку создания ID для документа и документа заверки")
.WithColor(Color.Blue)
.Build();
var Components = new ComponentBuilder()
.WithButton(new ButtonBuilder() { CustomId = "NewDocumentCertificate", Label = "Заверить документ", Style = ButtonStyle.Primary })
.Build();
await Context.Channel.SendMessageAsync(embed: Embed, components: Components);
await FollowupAsync("OK!");//, ephemeral: true);
}
}
}

View File

@@ -98,13 +98,14 @@ namespace DiscordApp.Discord.Commands
}
}
Startup startup = new();
foreach (var employee in allEmployee)
{
try
{
Startup startup = new ();
await Startup.sp.CreateTransaction(startup.getUserData(employee.Key).Result.cardsOwned.First().number, employee.Value, $"zp {employee.Key}");
var userData = await startup.getUserData(employee.Key);
await Startup.sp.CreateTransaction(userData.cardsOwned.First().number, employee.Value, $"zp {employee.Key}");
await Console.Out.WriteLineAsync($"{employee.Key}, {employee.Value}");
allCount += employee.Value;
}

View File

@@ -0,0 +1,35 @@
using Discord.Interactions;
using DiscordApp.Justice.Modals;
using DiscordApp.Utilities;
namespace DiscordApp.Justice.Interactions
{
public class NotaryInteractions : InteractionModuleBase<SocketInteractionContext>
{
[ComponentInteraction("NewDocumentCertificate")]
public async Task newCertificatedDocument()
=> await Context.Interaction.RespondWithModalAsync<INotaryModal>("newCertificatedDocument");
[ModalInteraction("newCertificatedDocument")]
public async Task newCertificatedDocumentModal(INotaryModal modal)
{
await DeferAsync(true);
int passportId;
int documentId;
int certificateId;
Random random = new Random();
IdChecker.IdLenghtIsLower(out certificateId);
documentId = Startup.appDbContext.Certificates.OrderBy(t => t.Id).First().Id + 1;
bool isInt = int.TryParse(modal.passportId, out passportId);
if (!isInt)
{
await FollowupAsync($"Айди паспорта еще старое, попробуй использовать другого бота.", ephemeral: true);
}
else if (Startup.appDbContext.Passport.Find(passportId) == null)
{
await FollowupAsync($"Паспорт не найден в базе данных, попробуй написать правильно", ephemeral: true);
}
}
}
}

View 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);
}
}
}

View File

@@ -158,8 +158,8 @@ namespace DiscordApp.Justice.Interactions
Root spUserData = await startup.getUserData(name);
DateTimeOffset toTime;
DateOnly birthDate;
int id = random.Next(00001, 99999);
while (id.ToString().Length < 5) { id = random.Next(00001, 99999); }
int id;
Utilities.IdChecker.IdLenghtIsLower(out id);
long unixBirthDateTime;
string cityName;
string cardNumber;
@@ -242,8 +242,7 @@ namespace DiscordApp.Justice.Interactions
bool isUnical = false;
while (!isUnical)
{
id = random.Next(00001, 99999);
while (id.ToString().Length < 5) { id = random.Next(00001, 99999); }
Utilities.IdChecker.IdLenghtIsLower(out id);
passport.Id = id;
Console.WriteLine(passport.Id);
if (Startup.appDbContext.Passport.FindAsync(passport.Id).Result == null) { break; }
@@ -256,7 +255,7 @@ namespace DiscordApp.Justice.Interactions
Имя: {passport.Applicant}
РП Имя: {passport.RpName}
Айди: {id}
Благотворитель: {passport.Support}
Благотворитель: {(int)passport.Support}
Гендер: {passport.Gender}
Дата рождения: <t:{passport.birthDate}:D>
Город: {cityName}

View File

@@ -0,0 +1,22 @@
using Discord;
using Discord.Interactions;
namespace DiscordApp.Justice.Modals
{
public class INotaryModal : IModal
{
public string Title => "Сертификация док-ов";
[InputLabel("ID паспорта")]
[ModalTextInput("passportId", TextInputStyle.Short, placeholder: "96534", maxLength: 10)]
public string passportId { get; set; }
[InputLabel("Тип документа")]
[ModalTextInput("documentType", TextInputStyle.Short, placeholder: "Пользовательское соглашение", maxLength: 100)]
public string documentType { get; set; }
[InputLabel("Текст из документа")]
[ModalTextInput("textFromDocument", TextInputStyle.Paragraph)]
public string documentText { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
using Discord;
using Discord.Interactions;
namespace DiscordApp.Justice.Modals
{
public class IPassportGetter : IModal
{
public string Title => "Поиск паспорта";
[InputLabel("Данные паспорта")]
[ModalTextInput("passport", TextInputStyle.Short, placeholder: "yawaflua или 97652", maxLength: 100)]
public string passport { get; set; }
}
}