This commit is contained in:
Дмитрий Шиманский
2023-11-02 16:48:36 +03:00
parent 7c3e88376b
commit e977fb2abd
7 changed files with 649 additions and 27 deletions

View File

@@ -92,6 +92,7 @@ namespace DiscordApp.Justice.Interactions
else
{
await FollowupAsync($"У {passportId} указан неправильный номер паспорта.", ephemeral: true);
return;
}
}

View File

@@ -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<SocketInteractionContext>
@@ -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}
Дата рождения: <t:{passport.birthDate}:D>")
.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;

View File

@@ -0,0 +1,254 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<long>("Date")
.HasColumnType("bigint");
b.Property<string>("Employee")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int[]>("Number")
.IsRequired()
.HasColumnType("integer[]");
b.Property<string>("Size")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("isAllowedToResell")
.HasColumnType("boolean");
b.Property<int>("passportId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("passportId");
b.ToTable("ArtsPatent", "public");
});
modelBuilder.Entity("DiscordApp.Database.Tables.Autobranches", b =>
{
b.Property<decimal>("ChannelId")
.ValueGeneratedOnAdd()
.HasColumnType("numeric(20,0)");
b.Property<string>("BranchName")
.IsRequired()
.HasColumnType("text");
b.HasKey("ChannelId");
b.ToTable("Autobranches", "public");
});
modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ApplicantId")
.HasColumnType("integer");
b.Property<int[]>("BiznessEmployes")
.IsRequired()
.HasColumnType("integer[]");
b.Property<string>("BiznessName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("BiznessType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("CardNumber")
.HasColumnType("integer");
b.Property<long>("Date")
.HasColumnType("bigint");
b.Property<string>("Employee")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ApplicantId");
b.ToTable("Bizness", "public");
});
modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Annotation")
.IsRequired()
.HasColumnType("text");
b.Property<long>("Date")
.HasColumnType("bigint");
b.Property<string>("Employee")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Janre")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("isAllowedToResell")
.HasColumnType("boolean");
b.Property<int>("passportId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("passportId");
b.ToTable("BooksPatent", "public");
});
modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Applicant")
.IsRequired()
.HasColumnType("text");
b.Property<long>("Date")
.HasColumnType("bigint");
b.Property<decimal>("Employee")
.HasColumnType("numeric(20,0)");
b.Property<string>("Gender")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RpName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Support")
.HasColumnType("integer");
b.Property<long>("birthDate")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Passport", "public");
});
modelBuilder.Entity("DiscordApp.Database.Tables.Reports", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Employee")
.IsRequired()
.HasColumnType("text");
b.Property<int>("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
}
}
}

View File

@@ -0,0 +1,48 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DiscordApp.Migrations
{
/// <inheritdoc />
public partial class InitMigrate292124 : Migration
{
/// <inheritdoc />
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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Employee = table.Column<string>(type: "text", nullable: false),
type = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Reports", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Reports",
schema: "public");
migrationBuilder.RenameTable(
name: "Bizness",
schema: "public",
newName: "Bizness");
}
}
}

View File

@@ -0,0 +1,254 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<long>("Date")
.HasColumnType("bigint");
b.Property<string>("Employee")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int[]>("Number")
.IsRequired()
.HasColumnType("integer[]");
b.Property<string>("Size")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("isAllowedToResell")
.HasColumnType("boolean");
b.Property<int>("passportId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("passportId");
b.ToTable("ArtsPatent", "public");
});
modelBuilder.Entity("DiscordApp.Database.Tables.Autobranches", b =>
{
b.Property<decimal>("ChannelId")
.ValueGeneratedOnAdd()
.HasColumnType("numeric(20,0)");
b.Property<string>("BranchName")
.IsRequired()
.HasColumnType("text");
b.HasKey("ChannelId");
b.ToTable("Autobranches", "public");
});
modelBuilder.Entity("DiscordApp.Database.Tables.Bizness", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ApplicantId")
.HasColumnType("integer");
b.Property<int[]>("BiznessEmployes")
.IsRequired()
.HasColumnType("integer[]");
b.Property<string>("BiznessName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("BiznessType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("CardNumber")
.HasColumnType("integer");
b.Property<long>("Date")
.HasColumnType("bigint");
b.Property<string>("Employee")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ApplicantId");
b.ToTable("Bizness", "public");
});
modelBuilder.Entity("DiscordApp.Database.Tables.BooksPatents", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Annotation")
.IsRequired()
.HasColumnType("text");
b.Property<long>("Date")
.HasColumnType("bigint");
b.Property<string>("Employee")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Janre")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("isAllowedToResell")
.HasColumnType("boolean");
b.Property<int>("passportId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("passportId");
b.ToTable("BooksPatent", "public");
});
modelBuilder.Entity("DiscordApp.Database.Tables.Passport", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Applicant")
.IsRequired()
.HasColumnType("text");
b.Property<long>("Date")
.HasColumnType("bigint");
b.Property<decimal>("Employee")
.HasColumnType("numeric(20,0)");
b.Property<string>("Gender")
.IsRequired()
.HasColumnType("text");
b.Property<string>("RpName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Support")
.HasColumnType("integer");
b.Property<long>("birthDate")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Passport", "public");
});
modelBuilder.Entity("DiscordApp.Database.Tables.Reports", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Employee")
.IsRequired()
.HasColumnType("text");
b.Property<int>("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
}
}
}

View File

@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DiscordApp.Migrations
{
/// <inheritdoc />
public partial class Migrate01111553 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@@ -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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Employee")
.IsRequired()
.HasColumnType("text");
b.Property<int>("type")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Reports", "public");
});
modelBuilder.Entity("DiscordApp.Database.Tables.ArtsPatents", b =>
{
b.HasOne("DiscordApp.Database.Tables.Passport", "passport")