добавил патенты, верификацию, сделал паспорта, ип ооо

This commit is contained in:
Дмитрий Шиманский
2023-10-29 21:23:50 +03:00
parent 60fcf04532
commit 7c3e88376b
28 changed files with 1814 additions and 71 deletions

View File

@@ -0,0 +1,138 @@
using Discord;
using Discord.Interactions;
using DiscordApp.Database.Tables;
using DiscordApp.Justice.Modals;
using spworlds.Types;
namespace DiscordApp.Justice.Interactions
{
public class BiznessInteraction : InteractionModuleBase<SocketInteractionContext>
{
[ComponentInteraction("NewIndividualEntrepreneur")]
public async Task AplyWork()
=> await Context.Interaction.RespondWithModalAsync<INewIndividualEntrepreneur>("newIndividualEterpreneur");
[ComponentInteraction("NewBizness")]
public async Task reCreatePassport()
=> await Context.Interaction.RespondWithModalAsync<INewBizness>("NewBizness");
[ModalInteraction("newIndividualEterpreneur")]
public async Task newIndividualEterpreneur(INewIndividualEntrepreneur modal)
{
await DeferAsync(true);
Passport? applicant = await Startup.appDbContext.Passport.FindAsync(int.Parse(modal.passportId));
if (applicant == null)
{
await FollowupAsync("Ошибка! Такого паспорта не существует. Попробуйте старого бота.", ephemeral: true);
return;
}
User spApplicant = await User.CreateUser(applicant.Applicant);
var employees = new List<int>();
employees.Add(applicant.Id);
Bizness biznessDB = new()
{
Applicant = applicant,
Employee = ((IGuildUser)Context.User).DisplayName,
BiznessEmployes = employees.ToArray(),
BiznessName = modal.Name,
BiznessType = modal.BiznessType,
CardNumber = modal.CardNumber,
Date = DateTimeOffset.Now.ToUnixTimeSeconds()
};
Reports report = new()
{
Employee = ((IGuildUser)Context.User).DisplayName,
type = Types.ReportTypes.Bizness
};
await Startup.appDbContext.Reports.AddAsync(report);
await Startup.appDbContext.Bizness.AddAsync(biznessDB);
if (!modal.Name.StartsWith("test")) { await Startup.appDbContext.SaveChangesAsync(); }
var fieldBuilder = new EmbedFieldBuilder()
.WithName("Данные:")
.WithValue($"```Аппликант: {applicant.Applicant}\nНазвание: {modal.Name}\nТип деятельности: {modal.BiznessType}\nНомер карты:{modal.CardNumber}```");
var author = new EmbedAuthorBuilder()
.WithIconUrl(Context.User.GetAvatarUrl())
.WithName(((IGuildUser)Context.User).DisplayName);
var embed = new EmbedBuilder()
.WithTitle("Новый ИП зарегестрирован!")
.WithAuthor(author)
.WithFields(fieldBuilder)
.WithThumbnailUrl(spApplicant.GetSkinPart(SkinPart.face))
.WithColor(Color.Blue)
.Build();
await FollowupAsync("Готово!", ephemeral: true);
var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel;
await channel.SendMessageAsync(embed: embed);
}
[ModalInteraction("NewBizness")]
public async Task newBizness(INewBizness modal)
{
await DeferAsync(true);
Passport? applicant = await Startup.appDbContext.Passport.FindAsync(int.Parse(modal.passportId));
if (applicant == null)
{
await FollowupAsync("Ошибка! Такого паспорта не существует. Попробуйте старого бота.", ephemeral: true);
return;
}
User spApplicant = await User.CreateUser(applicant.Applicant);
var employees = new List<int>
{
applicant.Id
};
string employeesNames = "";
foreach (var passportId in modal.BiznessEmployee.Split(","))
{
Passport? employee = await Startup.appDbContext.Passport.FindAsync(int.Parse(passportId));
if (employee != null) { employees.Add(employee.Id); employeesNames += $" {employee.Applicant}"; }
else
{
await FollowupAsync($"У {passportId} указан неправильный номер паспорта.", ephemeral: true);
}
}
Bizness biznessDB = new()
{
Applicant = applicant,
Employee = ((IGuildUser)Context.User).DisplayName,
BiznessEmployes = employees.ToArray(),
BiznessName = modal.Name,
BiznessType = modal.BiznessType,
CardNumber = modal.CardNumber,
Date = DateTimeOffset.Now.ToUnixTimeSeconds()
};
Reports report = new()
{
Employee = ((IGuildUser)Context.User).DisplayName,
type = Types.ReportTypes.Bizness
};
await Startup.appDbContext.Reports.AddAsync(report);
await Startup.appDbContext.Bizness.AddAsync(biznessDB);
if (!modal.Name.StartsWith("test")) { await Startup.appDbContext.SaveChangesAsync(); }
var fieldBuilder = new EmbedFieldBuilder()
.WithName("Данные:")
.WithValue($"```Аппликант: {applicant.Applicant}\nНазвание: {modal.Name}\nТип деятельности: {modal.BiznessType}\nНомер карты:{modal.CardNumber}\nСотрудники:{employeesNames}```");
var author = new EmbedAuthorBuilder()
.WithIconUrl(Context.User.GetAvatarUrl())
.WithName(((IGuildUser)Context.User).DisplayName);
var embed = new EmbedBuilder()
.WithTitle("Новый ООО зарегестрирован!")
.WithAuthor(author)
.WithFields(fieldBuilder)
.WithThumbnailUrl(spApplicant.GetSkinPart(SkinPart.face))
.WithColor(Color.Blue)
.Build();
await FollowupAsync("Готово!", ephemeral: true);
var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel;
await channel.SendMessageAsync(embed: embed);
}
}
}

View File

@@ -4,7 +4,7 @@ using Discord.WebSocket;
using DiscordApp.Database.Tables;
using DiscordApp.Enums;
using spworlds.Types;
using DiscordApp.Justice.Modals;
namespace DiscordApp.Justice.Interactions
{
public class PassportInteraction : InteractionModuleBase<SocketInteractionContext>
@@ -15,16 +15,16 @@ namespace DiscordApp.Justice.Interactions
[ComponentInteraction("newPassport")]
public async Task AplyWork()
=> await Context.Interaction.RespondWithModalAsync<NewPassportModal>("passportModal");
=> await Context.Interaction.RespondWithModalAsync<INewPassportModal>("passportModal");
[ComponentInteraction("reworkPassport")]
public async Task reCreatePassport()
=> await Context.Interaction.RespondWithModalAsync<ReWorkPassportModal>("reworkpassportModal");
=> await Context.Interaction.RespondWithModalAsync<IReWorkPassportModal>("reworkpassportModal");
[ComponentInteraction("reNewPassportButton")]
public async Task reNewPassportModal() => await Context.Interaction.RespondWithModalAsync<NewPassportModal>("ReNewPassportModal");
public async Task reNewPassportModal() => await Context.Interaction.RespondWithModalAsync<INewPassportModal>("ReNewPassportModal");
[ModalInteraction("reworkpassportModal")]
public async Task reCreatePassportInteraction(ReWorkPassportModal modal)
public async Task reCreatePassportInteraction(IReWorkPassportModal modal)
{
await DeferAsync(true);
double passportId = modal.Id;
@@ -109,7 +109,7 @@ namespace DiscordApp.Justice.Interactions
}
}
[ModalInteraction("ReNewPassportModal")]
public async Task renewPassportInteraction(NewPassportModal modal)
public async Task renewPassportInteraction(INewPassportModal modal)
{
await DeferAsync(true);
string name = modal.NickName;
@@ -170,6 +170,12 @@ namespace DiscordApp.Justice.Interactions
Id = id,
Support = supporter
};
Reports report = new()
{
Employee = ((IGuildUser)Context.User).DisplayName,
type = Types.ReportTypes.editPassport
};
await Startup.appDbContext.Reports.AddAsync(report);
if (Startup.appDbContext.Passport.FindAsync(passport.Id).Result != null)
{
@@ -219,7 +225,7 @@ namespace DiscordApp.Justice.Interactions
}
[ModalInteraction("passportModal")]
public async Task createPassportInteraction(NewPassportModal modal)
public async Task createPassportInteraction(INewPassportModal modal)
{
await DeferAsync(true);
string name = modal.NickName;
@@ -233,7 +239,7 @@ namespace DiscordApp.Justice.Interactions
Random random = new();
User spUser = await User.CreateUser(name);
DateTimeOffset toTime = DateTime.Now.AddDays(14);
DateTimeOffset toTime;
DateTime birthDate;
int id = random.Next(00001, 99999);
long unixTime;
@@ -244,8 +250,12 @@ namespace DiscordApp.Justice.Interactions
unixTime = ((DateTimeOffset)birthDate).ToUnixTimeSeconds();
if (birthDate.AddDays(14) < DateTime.Now)
{
await FollowupAsync($"Возможно, игрок {name} больше не новичек, и бесплатный паспорт ему не положен! Оформляю паспорт на месяц...0", ephemeral: true);
toTime = DateTimeOffset.Now.AddDays(60);
await FollowupAsync($"Возможно, игрок {name} больше не новичек, и бесплатный паспорт ему не положен! Оформляю паспорт на месяц...", ephemeral: true);
toTime = DateTimeOffset.Now.AddMonths(2);
}
else
{
toTime = DateTime.Now.AddDays(14);
}
}
catch (Exception ex)
@@ -324,54 +334,20 @@ namespace DiscordApp.Justice.Interactions
.WithTimestamp(toTime)
.Build();
Reports report = new()
{
Employee = ((IGuildUser)Context.User).DisplayName,
type = Types.ReportTypes.NewPassport
};
await Startup.appDbContext.Reports.AddAsync(report);
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);
await channel.SendMessageAsync(embed: embed);
}
}
public class NewPassportModal : IModal
{
public string Title => "Создание паспорта";
[InputLabel("Ник игрока")]
[ModalTextInput("nickname", TextInputStyle.Short, placeholder: "YaFlay", maxLength: 90)]
public string NickName { get; set; }
[InputLabel("Благотворитель")]
[ModalTextInput("Supporter", TextInputStyle.Short, placeholder: "1", maxLength: 5)]
public int Supporter { get; set; }
[InputLabel("РП Имя")]
[ModalTextInput("rolePlayName", TextInputStyle.Short, placeholder: "Олег Бебров", maxLength: 200)]
public string RPName { get; set; }
[InputLabel("Пол")]
[ModalTextInput("gender", TextInputStyle.Short, maxLength: 200)]
public string Gender { get; set; }
[InputLabel("Дата рождения")]
[ModalTextInput("BirthDay", TextInputStyle.Short, placeholder: "16.02.2023", maxLength: 100)]
public string Birthday { get; set; }
}
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; }
}
}

View File

@@ -1,6 +0,0 @@
namespace DiscordApp.Justice.Interactions
{
public class Patents
{
}
}

View File

@@ -0,0 +1,147 @@
using Discord.Interactions;
using DiscordApp.Justice.Modals;
using DiscordApp.Database.Tables;
using Discord.WebSocket;
using Discord;
using spworlds.Types;
namespace DiscordApp.Justice.Interactions
{
public class PatentInteraction : InteractionModuleBase<SocketInteractionContext>
{
[ComponentInteraction("artPatent")]
public async Task artPatentInteractions() => await RespondWithModalAsync<INewArtModal>("newArtCallback");
[ComponentInteraction("bookPatent")]
public async Task bookPatentInteractions() => await RespondWithModalAsync<INewBookModal>("newBookCallback");
[ModalInteraction("newArtCallback")]
public async Task newArtModalInteraction(INewArtModal modal)
{
await DeferAsync(true);
string name = modal.Name;
string maps = modal.MapNumbers;
string size = modal.Size;
int passportId = modal.PassportId;
bool isAllowedToReSell = modal.IsAllowedToResell == 1;
Passport? passport = await Startup.appDbContext.Passport.FindAsync(passportId);
if (passport == null)
{
await FollowupAsync("ID паспорта не найден в базе данных. Попробуйте использовать старого бота.");
return;
}
var mapDictionary = new List<int>();
User spUser = await User.CreateUser(passport.Applicant);
try
{
foreach (var map in maps.Split(','))
{
mapDictionary.Add(int.Parse(map));
}
}
catch (Exception ex)
{
await Console.Out.WriteLineAsync($"new error in patentInteractions 32-37 {ex.Message}");
await FollowupAsync("Возникла ошибка при парсинге ID карт. Вы точно указали через запятую данные?");
return;
}
ArtsPatents artsPatent = new()
{
Name = name,
Employee = ((IGuildUser)Context.User).DisplayName,
Size = size,
Date = DateTimeOffset.Now.ToUnixTimeSeconds(),
Number = mapDictionary.ToArray(),
isAllowedToResell = isAllowedToReSell,
passport = passport
};
Reports report = new()
{
Employee = ((IGuildUser)Context.User).DisplayName,
type = Types.ReportTypes.Patent
};
await Startup.appDbContext.Reports.AddAsync(report);
await Startup.appDbContext.ArtPatents.AddAsync(artsPatent);
if (!name.StartsWith("test")) { await Startup.appDbContext.SaveChangesAsync(); }
var field = new EmbedFieldBuilder()
.WithName("Данные патента")
.WithValue($"```Название арта: {name} \nРазмер: {size} \nНомера: {maps} \nРазрешена перепродажа?: {isAllowedToReSell} \nАппликант: {passport.Applicant}```")
.WithIsInline(false);
var author = new EmbedAuthorBuilder()
.WithIconUrl(Context.User.GetAvatarUrl())
.WithName(((IGuildUser)Context.User).DisplayName);
var Embed = new EmbedBuilder()
.WithTitle("Новый патент!")
.WithFields(field)
.WithAuthor(author)
.WithColor(Color.Blue)
.WithCurrentTimestamp()
.WithThumbnailUrl(spUser.GetSkinPart(SkinPart.face))
.Build();
await FollowupAsync("Готово!", ephemeral: true);
var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel;
await channel.SendMessageAsync(embed: Embed);
}
[ModalInteraction("newBookCallback")]
public async Task newBookModalInteraction(INewBookModal modal)
{
await DeferAsync(true);
string name = modal.Name;
string janre = modal.Janre;
string annotation = modal.Annotation;
int passportId = modal.PassportId;
bool isAllowedToReSell = modal.IsAllowedToResell == 1;
Passport? passport = await Startup.appDbContext.Passport.FindAsync(passportId);
if (passport == null)
{
await FollowupAsync("ID паспорта не найден в базе данных. Попробуйте использовать старого бота.");
return;
}
User spUser = await User.CreateUser(passport.Applicant);
BooksPatents bookPatent = new()
{
Name = name,
Employee = ((IGuildUser)Context.User).DisplayName,
Janre = janre,
Date = DateTimeOffset.Now.ToUnixTimeSeconds(),
Annotation = annotation,
isAllowedToResell = isAllowedToReSell,
passport = passport
};
Reports report = new()
{
Employee = ((IGuildUser)Context.User).DisplayName,
type = Types.ReportTypes.Patent
};
await Startup.appDbContext.Reports.AddAsync(report);
await Startup.appDbContext.BookPatents.AddAsync(bookPatent);
if (!name.StartsWith("test")) { await Startup.appDbContext.SaveChangesAsync(); }
var field = new EmbedFieldBuilder()
.WithName("Данные патента")
.WithValue($"```Название книги: {name} \nАннотация: {annotation} \nЖанр: {janre} \nРазрешена перепродажа?:{isAllowedToReSell} \nАппликант:{passport.Applicant}```")
.WithIsInline(false);
var author = new EmbedAuthorBuilder()
.WithIconUrl(Context.User.GetAvatarUrl())
.WithName(((IGuildUser)Context.User).DisplayName);
var Embed = new EmbedBuilder()
.WithTitle("Новый патент!")
.WithFields(field)
.WithAuthor(author)
.WithColor(Color.Blue)
.WithCurrentTimestamp()
.WithThumbnailUrl(spUser.GetSkinPart(SkinPart.face))
.Build();
await FollowupAsync("Готово!", ephemeral: true);
var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel;
await channel.SendMessageAsync(embed: Embed);
}
}
}

View File

@@ -15,7 +15,7 @@ namespace DiscordApp.Justice.Interactions
{
await FollowupAsync("Готово!", ephemeral: true);
var guildUser = Context.Guild.GetUser(Context.User.Id);
await guildUser.AddRoleAsync(1165687128366268511);
await guildUser.AddRoleAsync(1136564585420304444);
await guildUser.ModifyAsync(func =>
{
func.Nickname = user.Name;