diff --git a/Justice/Interactions/BiznessInteractions.cs b/Justice/Interactions/BiznessInteractions.cs index 63d9c31..0fab448 100644 --- a/Justice/Interactions/BiznessInteractions.cs +++ b/Justice/Interactions/BiznessInteractions.cs @@ -92,6 +92,7 @@ namespace DiscordApp.Justice.Interactions else { await FollowupAsync($"У {passportId} указан неправильный номер паспорта.", ephemeral: true); + return; } } diff --git a/Justice/Interactions/PassportInteraction.cs b/Justice/Interactions/PassportInteraction.cs index 460a8fb..851b73b 100644 --- a/Justice/Interactions/PassportInteraction.cs +++ b/Justice/Interactions/PassportInteraction.cs @@ -5,6 +5,8 @@ using DiscordApp.Database.Tables; using DiscordApp.Enums; using spworlds.Types; using DiscordApp.Justice.Modals; +using System; + namespace DiscordApp.Justice.Interactions { public class PassportInteraction : InteractionModuleBase @@ -34,7 +36,7 @@ namespace DiscordApp.Justice.Interactions 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; } @@ -123,15 +125,25 @@ namespace DiscordApp.Justice.Interactions Random random = new(); User spUser = await User.CreateUser(name); - DateTimeOffset toTime = DateTime.Now.AddDays(_AddDays); - DateTime birthDate; + DateTimeOffset toTime; + DateOnly birthDate; int id = random.Next(00001, 99999); while (id.ToString().Length < 5) { id = random.Next(00001, 99999); } - long unixTime = toTime.ToUnixTimeSeconds(); + long unixBirthDateTime; try { - birthDate = DateTime.Parse(birthday); + birthDate = DateOnly.Parse(birthday); + unixBirthDateTime = DateTimeOffset.Parse(birthDate.ToString()).ToUnixTimeSeconds(); + if (birthDate.AddDays(14) < DateOnly.FromDateTime(DateTime.Now)) + { + await FollowupAsync($"Возможно, игрок {name} больше не новичек, и бесплатный паспорт ему не положен! Оформляю паспорт на месяц...", ephemeral: true); + toTime = DateTimeOffset.Now.AddMonths(2); + } + else + { + toTime = DateTimeOffset.Now.AddDays(14); + } } catch { @@ -164,15 +176,15 @@ namespace DiscordApp.Justice.Interactions Employee = user.Id, RpName = RpName, Gender = gender, - Date = unixTime, - birthDate = ((DateTimeOffset)birthDate).ToUnixTimeSeconds(), + Date = toTime.ToUnixTimeSeconds(), + birthDate = unixBirthDateTime, Applicant = name, Id = id, Support = supporter }; Reports report = new() { - Employee = ((IGuildUser)Context.User).DisplayName, + Employee = Startup.sp.GetUser(Context.User.Id.ToString()).Result.Name, type = Types.ReportTypes.editPassport }; await Startup.appDbContext.Reports.AddAsync(report); @@ -235,33 +247,43 @@ namespace DiscordApp.Justice.Interactions string gender = modal.Gender; SocketGuildUser user = Context.Guild.GetUser(Context.User.Id); - Supporter supporter; Random random = new(); - User spUser = await User.CreateUser(name); - + Supporter supporter; + User spUser; DateTimeOffset toTime; - DateTime birthDate; - int id = random.Next(00001, 99999); - long unixTime; + DateOnly birthDate; + long unixBirthDateTime; try { - birthDate = DateTime.Parse(birthday); - unixTime = ((DateTimeOffset)birthDate).ToUnixTimeSeconds(); - if (birthDate.AddDays(14) < DateTime.Now) + spUser = await User.CreateUser(name); + } + catch + { + await FollowupAsync("Игрок с таким ником не найден!", ephemeral: true); + return; + } + + int id = random.Next(00001, 99999); + while (id.ToString().Length < 5) { id = random.Next(00001, 99999); } + + try + { + birthDate = DateOnly.Parse(birthday); + unixBirthDateTime = DateTimeOffset.Parse(birthDate.ToString()).ToUnixTimeSeconds(); + if (birthDate.AddDays(14) < DateOnly.FromDateTime(DateTime.Now)) { - await FollowupAsync($"Возможно, игрок {name} больше не новичек, и бесплатный паспорт ему не положен! Оформляю паспорт на месяц...", ephemeral: true); + await FollowupAsync($"Возможно, игрок {name} играет больше двух недель, и бесплатный паспорт ему не положен! Оформляю паспорт на два месяца...", ephemeral: true); toTime = DateTimeOffset.Now.AddMonths(2); } else { - toTime = DateTime.Now.AddDays(14); + toTime = DateTimeOffset.Now.AddDays(14); } } - catch (Exception ex) + catch { - await FollowupAsync($"Возможно, с датой {modal.Birthday} какая-то ошибка, попробуйте такой тип: 14.02.2023", ephemeral: true); - Console.WriteLine($"Error in 237-243 line. Error: {ex.Message}"); + await FollowupAsync($"Возможно, с датой `{modal.Birthday}` какая-то ошибка, попробуйте такой тип: 14.02.2023", ephemeral: true); return; } @@ -290,7 +312,8 @@ namespace DiscordApp.Justice.Interactions Employee = user.Id, RpName = RpName, Gender = gender, - Date = unixTime, + Date = DateTimeOffset.Now.ToUnixTimeSeconds(), + birthDate = unixBirthDateTime, Applicant = name, Id = id, Support = supporter @@ -303,7 +326,7 @@ namespace DiscordApp.Justice.Interactions { id = random.Next(00001, 99999); passport.Id = id; - Console.WriteLine(passport.Id); + while (id.ToString().Length < 5) { id = random.Next(00001, 99999); } if (Startup.appDbContext.Passport.FindAsync(passport.Id).Result == null) { break; } } } @@ -314,7 +337,7 @@ namespace DiscordApp.Justice.Interactions Имя: {passport.Applicant} РП Имя: {passport.RpName} Айди: {id} -Благотворитель: {passport.Support} +Благотворитель: {(int)passport.Support } Гендер: {passport.Gender} Дата рождения: ") .WithIsInline(true); @@ -341,7 +364,7 @@ namespace DiscordApp.Justice.Interactions }; await Startup.appDbContext.Reports.AddAsync(report); await Startup.appDbContext.Passport.AddAsync(passport); - await Startup.appDbContext.SaveChangesAsync(); + if (!RpName.StartsWith("test")) { await Startup.appDbContext.SaveChangesAsync(); } await FollowupAsync($"ID для паспорта: {id}", embed: embed, ephemeral: true); var channel = Context.Guild.GetChannel(1108006685626355733) as ITextChannel; diff --git a/Migrations/20231029182451_InitMigrate292124.Designer.cs b/Migrations/20231029182451_InitMigrate292124.Designer.cs new file mode 100644 index 0000000..37da2c1 --- /dev/null +++ b/Migrations/20231029182451_InitMigrate292124.Designer.cs @@ -0,0 +1,254 @@ +// +using DiscordApp.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DiscordApp.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20231029182451_InitMigrate292124")] + partial class InitMigrate292124 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DiscordApp.Database.Tables.ArtsPatents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Number") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("Size") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("ArtsPatent", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Autobranches", b => + { + b.Property("ChannelId") + .ValueGeneratedOnAdd() + .HasColumnType("numeric(20,0)"); + + b.Property("BranchName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ChannelId"); + + b.ToTable("Autobranches", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApplicantId") + .HasColumnType("integer"); + + b.Property("BiznessEmployes") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("BiznessName") + .IsRequired() + .HasColumnType("text"); + + b.Property("BiznessType") + .IsRequired() + .HasColumnType("text"); + + b.Property("CardNumber") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ApplicantId"); + + b.ToTable("Bizness", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Annotation") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Janre") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("BooksPatent", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Applicant") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .HasColumnType("numeric(20,0)"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("text"); + + b.Property("RpName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Support") + .HasColumnType("integer"); + + b.Property("birthDate") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.ToTable("Passport", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Reports", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Reports", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.ArtsPatents", b => + { + b.HasOne("DiscordApp.Database.Tables.Passport", "passport") + .WithMany() + .HasForeignKey("passportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("passport"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b => + { + b.HasOne("DiscordApp.Database.Tables.Passport", "Applicant") + .WithMany() + .HasForeignKey("ApplicantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Applicant"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b => + { + b.HasOne("DiscordApp.Database.Tables.Passport", "passport") + .WithMany() + .HasForeignKey("passportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("passport"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20231029182451_InitMigrate292124.cs b/Migrations/20231029182451_InitMigrate292124.cs new file mode 100644 index 0000000..9128bef --- /dev/null +++ b/Migrations/20231029182451_InitMigrate292124.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DiscordApp.Migrations +{ + /// + public partial class InitMigrate292124 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameTable( + name: "Bizness", + newName: "Bizness", + newSchema: "public"); + + migrationBuilder.CreateTable( + name: "Reports", + schema: "public", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Employee = table.Column(type: "text", nullable: false), + type = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Reports", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Reports", + schema: "public"); + + migrationBuilder.RenameTable( + name: "Bizness", + schema: "public", + newName: "Bizness"); + } + } +} diff --git a/Migrations/20231101125356_Migrate01111553.Designer.cs b/Migrations/20231101125356_Migrate01111553.Designer.cs new file mode 100644 index 0000000..68749b9 --- /dev/null +++ b/Migrations/20231101125356_Migrate01111553.Designer.cs @@ -0,0 +1,254 @@ +// +using DiscordApp.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DiscordApp.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20231101125356_Migrate01111553")] + partial class Migrate01111553 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DiscordApp.Database.Tables.ArtsPatents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Number") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("Size") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("ArtsPatent", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Autobranches", b => + { + b.Property("ChannelId") + .ValueGeneratedOnAdd() + .HasColumnType("numeric(20,0)"); + + b.Property("BranchName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ChannelId"); + + b.ToTable("Autobranches", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ApplicantId") + .HasColumnType("integer"); + + b.Property("BiznessEmployes") + .IsRequired() + .HasColumnType("integer[]"); + + b.Property("BiznessName") + .IsRequired() + .HasColumnType("text"); + + b.Property("BiznessType") + .IsRequired() + .HasColumnType("text"); + + b.Property("CardNumber") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ApplicantId"); + + b.ToTable("Bizness", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Annotation") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("Janre") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("isAllowedToResell") + .HasColumnType("boolean"); + + b.Property("passportId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("passportId"); + + b.ToTable("BooksPatent", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Applicant") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("bigint"); + + b.Property("Employee") + .HasColumnType("numeric(20,0)"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("text"); + + b.Property("RpName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Support") + .HasColumnType("integer"); + + b.Property("birthDate") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.ToTable("Passport", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Reports", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Reports", "public"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.ArtsPatents", b => + { + b.HasOne("DiscordApp.Database.Tables.Passport", "passport") + .WithMany() + .HasForeignKey("passportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("passport"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b => + { + b.HasOne("DiscordApp.Database.Tables.Passport", "Applicant") + .WithMany() + .HasForeignKey("ApplicantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Applicant"); + }); + + modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b => + { + b.HasOne("DiscordApp.Database.Tables.Passport", "passport") + .WithMany() + .HasForeignKey("passportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("passport"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20231101125356_Migrate01111553.cs b/Migrations/20231101125356_Migrate01111553.cs new file mode 100644 index 0000000..9ad8e39 --- /dev/null +++ b/Migrations/20231101125356_Migrate01111553.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DiscordApp.Migrations +{ + /// + public partial class Migrate01111553 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Migrations/AppDbContextModelSnapshot.cs b/Migrations/AppDbContextModelSnapshot.cs index c93b0c6..a92b542 100644 --- a/Migrations/AppDbContextModelSnapshot.cs +++ b/Migrations/AppDbContextModelSnapshot.cs @@ -113,7 +113,7 @@ namespace DiscordApp.Migrations b.HasIndex("ApplicantId"); - b.ToTable("Bizness"); + b.ToTable("Bizness", "public"); }); modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b => @@ -193,6 +193,26 @@ namespace DiscordApp.Migrations b.ToTable("Passport", "public"); }); + modelBuilder.Entity("DiscordApp.Database.Tables.Reports", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Employee") + .IsRequired() + .HasColumnType("text"); + + b.Property("type") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Reports", "public"); + }); + modelBuilder.Entity("DiscordApp.Database.Tables.ArtsPatents", b => { b.HasOne("DiscordApp.Database.Tables.Passport", "passport")