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

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