diff --git a/Kehyeedra3/ApplicationDbContext.cs b/Kehyeedra3/ApplicationDbContext.cs index a1f6bb3..43e5458 100644 --- a/Kehyeedra3/ApplicationDbContext.cs +++ b/Kehyeedra3/ApplicationDbContext.cs @@ -15,5 +15,6 @@ namespace Kehyeedra3 public DbSet Battlefish { get; set; } public DbSet Mining { get; set; } public DbSet Farming { get; set; } + public DbSet Guilds { get; set; } } } diff --git a/Kehyeedra3/Commands/Admin.cs b/Kehyeedra3/Commands/Admin.cs index 034a201..dc13570 100644 --- a/Kehyeedra3/Commands/Admin.cs +++ b/Kehyeedra3/Commands/Admin.cs @@ -180,6 +180,58 @@ namespace Kehyeedra3.Commands await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nInvalid type."); } } + [RequireRolePrecondition(AccessLevel.ServerAdmin)] + [Command("enable"),Summary("Enable a bot feature on this server.")] + public async Task EnableServerFeature(string feature) + { + using var Database = new ApplicationDbContextFactory().CreateDbContext(); + var guild = Database.Guilds.FirstOrDefault(x => x.Id == Context.Guild.Id); + if (guild == null) + { + guild = new Guild + { + Id = Context.Guild.Id + }; + Database.Guilds.Add(guild); + } + switch (feature.ToLower()) + { + case "changenick": + { + guild.Changenick = true; + } + break; + } + await Database.SaveChangesAsync(); + await ReplyAsync($"{Context.User.Mention}\nEnabled {feature}"); + + } + + [RequireRolePrecondition(AccessLevel.ServerAdmin)] + [Command("disable"), Summary("Disable a bot feature on this server.")] + public async Task DisableServerFeature(string feature) + { + using var Database = new ApplicationDbContextFactory().CreateDbContext(); + var guild = Database.Guilds.FirstOrDefault(x => x.Id == Context.Guild.Id); + if (guild == null) + { + guild = new Guild + { + Id = Context.Guild.Id + }; + Database.Guilds.Add(guild); + } + switch (feature.ToLower()) + { + case "changenick": + { + guild.Changenick = false; + } + break; + } + await Database.SaveChangesAsync(); + await ReplyAsync($"{Context.User.Mention}\nDisabled {feature}"); + } // test commands diff --git a/Kehyeedra3/Commands/Stuff.cs b/Kehyeedra3/Commands/Stuff.cs index 86c99cf..b95afa7 100644 --- a/Kehyeedra3/Commands/Stuff.cs +++ b/Kehyeedra3/Commands/Stuff.cs @@ -381,24 +381,38 @@ namespace Kehyeedra3.Commands [Command("changenick")] public async Task ChangeNickname(IGuildUser usr = null, [Remainder]string name = null) { - if (Context.Guild.Id != 691361760300761139 && Context.Guild.Id != 912778610300039198) + using var Database = new ApplicationDbContextFactory().CreateDbContext(); + var guild = Database.Guilds.FirstOrDefault(x => x.Id == Context.Guild.Id); + if (guild == null) { - await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nWrong server retard"); - return; + guild = new Guild + { + Id = Context.Guild.Id + }; + Database.Guilds.Add(guild); } - if (usr == null || usr == Context.User || name == null) + if (guild.Changenick) { - await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nYeah you gotta ping someone and write a name, retard"); - return; + if (usr == null || usr == Context.User || name == null) + { + await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nYeah you gotta ping someone else and write a name, retard"); + return; + } + else + { + await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nLet's fucking goooo"); + await usr.ModifyAsync(x => x.Nickname = $"{name}"); + } } else { - await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nLet's fucking goooo"); - await usr.ModifyAsync(x => x.Nickname = $"{name}"); + await ReplyAsync($"{Context.User.Mention}\nServer admins can enable this command using 'enable changenick'."); } + } + } } diff --git a/Kehyeedra3/Kehyeedra3.csproj b/Kehyeedra3/Kehyeedra3.csproj index 5eb8cf1..089b73f 100644 --- a/Kehyeedra3/Kehyeedra3.csproj +++ b/Kehyeedra3/Kehyeedra3.csproj @@ -14,6 +14,7 @@ + all diff --git a/Kehyeedra3/Migrations/20220219105127_GuildFeatures.Designer.cs b/Kehyeedra3/Migrations/20220219105127_GuildFeatures.Designer.cs new file mode 100644 index 0000000..cbda379 --- /dev/null +++ b/Kehyeedra3/Migrations/20220219105127_GuildFeatures.Designer.cs @@ -0,0 +1,308 @@ +// +using System; +using Kehyeedra3; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Kehyeedra3.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220219105127_GuildFeatures")] + partial class GuildFeatures + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.11") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Kehyeedra3.Services.Models.Farming", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("CropInventory") + .HasColumnType("LONGTEXT"); + + b.Property("EmployeeCount") + .HasColumnType("int"); + + b.Property("FXp") + .HasColumnType("bigint unsigned"); + + b.Property("Lvl") + .HasColumnType("bigint unsigned"); + + b.Property("PlotInventory") + .HasColumnType("LONGTEXT"); + + b.Property("TXp") + .HasColumnType("bigint unsigned"); + + b.Property("Tier") + .HasColumnType("int"); + + b.Property("Xp") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("Farming"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.Fishing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("FXp") + .HasColumnType("bigint unsigned"); + + b.Property("Inventory") + .HasColumnType("LONGTEXT"); + + b.Property("LastFish") + .HasColumnType("bigint unsigned"); + + b.Property("Lvl") + .HasColumnType("bigint unsigned"); + + b.Property("Prestige") + .HasColumnType("int"); + + b.Property("RodOwned") + .HasColumnType("tinyint unsigned"); + + b.Property("RodUsed") + .HasColumnType("tinyint unsigned"); + + b.Property("TXp") + .HasColumnType("bigint unsigned"); + + b.Property("Xp") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("Fishing"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.Guild", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Changenick") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("Guilds"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.ItemOffer", b => + { + b.Property("OfferId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("BuyerId") + .HasColumnType("bigint unsigned"); + + b.Property("IsPurchaseFromStore") + .HasColumnType("tinyint(1)"); + + b.Property("IsSellOffer") + .HasColumnType("tinyint(1)"); + + b.Property("ItemId") + .HasColumnType("bigint unsigned"); + + b.Property("OfferAmount") + .HasColumnType("int"); + + b.Property("StoreFrontId") + .HasColumnType("bigint unsigned"); + + b.Property("StoreId") + .HasColumnType("bigint unsigned"); + + b.HasKey("OfferId"); + + b.HasIndex("StoreFrontId"); + + b.ToTable("ItemOffer"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.Mining", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("LastMine") + .HasColumnType("bigint unsigned"); + + b.Property("Lvl") + .HasColumnType("bigint unsigned"); + + b.Property("TXp") + .HasColumnType("bigint unsigned"); + + b.Property("Xp") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("Mining"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.Reminder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Created") + .HasColumnType("bigint unsigned"); + + b.Property("Message") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Send") + .HasColumnType("bigint unsigned"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("Reminders"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreFront", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("StoreItemType") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("StoreFronts"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreInventory", b => + { + b.Property("InvId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("Item") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Price") + .HasColumnType("int"); + + b.Property("StoreFrontId") + .HasColumnType("bigint unsigned"); + + b.HasKey("InvId"); + + b.HasIndex("StoreFrontId"); + + b.ToTable("StoreInventory"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Avatar") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("CurrentBattlefish") + .HasColumnType("TINYINT"); + + b.Property("GeneralInventory") + .HasColumnType("LONGTEXT"); + + b.Property("Money") + .HasColumnType("bigint"); + + b.Property("OwnerId") + .HasColumnType("bigint unsigned"); + + b.Property("Username") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.User+BattleFishObject", b => + { + b.Property("FishId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("FishType") + .HasColumnType("TINYINT"); + + b.Property("Lvl") + .HasColumnType("int"); + + b.Property("Name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("NextXp") + .HasColumnType("bigint unsigned"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.Property("Xp") + .HasColumnType("bigint unsigned"); + + b.HasKey("FishId"); + + b.ToTable("Battlefish"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.ItemOffer", b => + { + b.HasOne("Kehyeedra3.Services.Models.StoreFront", null) + .WithMany("Offers") + .HasForeignKey("StoreFrontId"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreInventory", b => + { + b.HasOne("Kehyeedra3.Services.Models.StoreFront", null) + .WithMany("Items") + .HasForeignKey("StoreFrontId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Kehyeedra3/Migrations/20220219105127_GuildFeatures.cs b/Kehyeedra3/Migrations/20220219105127_GuildFeatures.cs new file mode 100644 index 0000000..87fb67d --- /dev/null +++ b/Kehyeedra3/Migrations/20220219105127_GuildFeatures.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Kehyeedra3.Migrations +{ + public partial class GuildFeatures : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Guilds", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Changenick = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Guilds", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Guilds"); + } + } +} diff --git a/Kehyeedra3/Migrations/ApplicationDbContextModelSnapshot.cs b/Kehyeedra3/Migrations/ApplicationDbContextModelSnapshot.cs index 2c855d3..d2dcf6a 100644 --- a/Kehyeedra3/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Kehyeedra3/Migrations/ApplicationDbContextModelSnapshot.cs @@ -90,6 +90,20 @@ namespace Kehyeedra3.Migrations b.ToTable("Fishing"); }); + modelBuilder.Entity("Kehyeedra3.Services.Models.Guild", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Changenick") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("Guilds"); + }); + modelBuilder.Entity("Kehyeedra3.Services.Models.ItemOffer", b => { b.Property("OfferId") diff --git a/Kehyeedra3/Services/Models/Guild.cs b/Kehyeedra3/Services/Models/Guild.cs new file mode 100644 index 0000000..c4a31b1 --- /dev/null +++ b/Kehyeedra3/Services/Models/Guild.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace Kehyeedra3.Services.Models +{ + class Guild + { + [Key] + public ulong Id { get; set; } = 0; + public bool Changenick { get; set; } = false; + } +}