diff --git a/src/NadekoBot/Migrations/20160826234229_first.Designer.cs b/src/NadekoBot/Migrations/20160828000228_first.Designer.cs similarity index 61% rename from src/NadekoBot/Migrations/20160826234229_first.Designer.cs rename to src/NadekoBot/Migrations/20160828000228_first.Designer.cs index a7fdcfa1..43f73276 100644 --- a/src/NadekoBot/Migrations/20160826234229_first.Designer.cs +++ b/src/NadekoBot/Migrations/20160828000228_first.Designer.cs @@ -8,7 +8,7 @@ using NadekoBot.Services.Database.Impl; namespace NadekoBot.Migrations { [DbContext(typeof(NadekoSqliteContext))] - [Migration("20160826234229_first")] + [Migration("20160828000228_first")] partial class first { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -16,6 +16,50 @@ namespace NadekoBot.Migrations modelBuilder .HasAnnotation("ProductVersion", "1.0.0-rtm-21431"); + modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("ItemId"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("BlacklistItem"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.BotConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BufferSize"); + + b.Property("CurrencyName"); + + b.Property("CurrencyPluralName"); + + b.Property("CurrencySign"); + + b.Property("DontJoinServers"); + + b.Property("ForwardMessages"); + + b.Property("ForwardToAllOwners"); + + b.Property("RemindMessageFormat"); + + b.Property("RotatingStatuses"); + + b.HasKey("Id"); + + b.ToTable("BotConfig"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashCaller", b => { b.Property("Id") @@ -79,6 +123,22 @@ namespace NadekoBot.Migrations b.ToTable("Donators"); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.EightBallResponse", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("Text"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("EightBallResponse"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b => { b.Property("Id") @@ -110,8 +170,6 @@ namespace NadekoBot.Migrations b.Property("GuildId"); - b.Property("RotatingStatuses"); - b.Property("SendChannelByeMessage"); b.Property("SendChannelGreetMessage"); @@ -126,18 +184,36 @@ namespace NadekoBot.Migrations b.ToTable("GuildConfigs"); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("ModuleName"); + + b.Property("Prefix"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("ModulePrefix"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b => { b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("GuildConfigId"); + b.Property("BotConfigId"); b.Property("Status"); b.HasKey("Id"); - b.HasIndex("GuildConfigId"); + b.HasIndex("BotConfigId"); b.ToTable("PlayingStatus"); }); @@ -165,6 +241,24 @@ namespace NadekoBot.Migrations b.ToTable("Quotes"); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("Icon"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("RaceAnimal"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.Reminder", b => { b.Property("Id") @@ -204,6 +298,13 @@ namespace NadekoBot.Migrations b.ToTable("SelfAssignableRoles"); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("Blacklist") + .HasForeignKey("BotConfigId"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashCaller", b => { b.HasOne("NadekoBot.Services.Database.Models.ClashWar", "ClashWar") @@ -212,11 +313,32 @@ namespace NadekoBot.Migrations .OnDelete(DeleteBehavior.Cascade); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.EightBallResponse", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("EightBallResponses") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("ModulePrefixes") + .HasForeignKey("BotConfigId"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b => { - b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") .WithMany("RotatingStatusMessages") - .HasForeignKey("GuildConfigId"); + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("RaceAnimals") + .HasForeignKey("BotConfigId"); }); } } diff --git a/src/NadekoBot/Migrations/20160826234229_first.cs b/src/NadekoBot/Migrations/20160828000228_first.cs similarity index 59% rename from src/NadekoBot/Migrations/20160826234229_first.cs rename to src/NadekoBot/Migrations/20160828000228_first.cs index 6dd4deac..081d2cb9 100644 --- a/src/NadekoBot/Migrations/20160826234229_first.cs +++ b/src/NadekoBot/Migrations/20160828000228_first.cs @@ -8,6 +8,27 @@ namespace NadekoBot.Migrations { protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateTable( + name: "BotConfig", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Autoincrement", true), + BufferSize = table.Column(nullable: false), + CurrencyName = table.Column(nullable: true), + CurrencyPluralName = table.Column(nullable: true), + CurrencySign = table.Column(nullable: true), + DontJoinServers = table.Column(nullable: false), + ForwardMessages = table.Column(nullable: false), + ForwardToAllOwners = table.Column(nullable: false), + RemindMessageFormat = table.Column(nullable: true), + RotatingStatuses = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_BotConfig", x => x.Id); + }); + migrationBuilder.CreateTable( name: "ClashOfClans", columns: table => new @@ -60,7 +81,6 @@ namespace NadekoBot.Migrations ExclusiveSelfAssignedRoles = table.Column(nullable: false), GreetMessageChannelId = table.Column(nullable: false), GuildId = table.Column(nullable: false), - RotatingStatuses = table.Column(nullable: false), SendChannelByeMessage = table.Column(nullable: false), SendChannelGreetMessage = table.Column(nullable: false), SendDmGreetMessage = table.Column(nullable: false) @@ -119,6 +139,108 @@ namespace NadekoBot.Migrations table.PrimaryKey("PK_SelfAssignableRoles", x => x.Id); }); + migrationBuilder.CreateTable( + name: "BlacklistItem", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Autoincrement", true), + BotConfigId = table.Column(nullable: true), + ItemId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_BlacklistItem", x => x.Id); + table.ForeignKey( + name: "FK_BlacklistItem_BotConfig_BotConfigId", + column: x => x.BotConfigId, + principalTable: "BotConfig", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "EightBallResponse", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Autoincrement", true), + BotConfigId = table.Column(nullable: true), + Text = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_EightBallResponse", x => x.Id); + table.ForeignKey( + name: "FK_EightBallResponse_BotConfig_BotConfigId", + column: x => x.BotConfigId, + principalTable: "BotConfig", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "ModulePrefix", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Autoincrement", true), + BotConfigId = table.Column(nullable: true), + ModuleName = table.Column(nullable: true), + Prefix = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ModulePrefix", x => x.Id); + table.ForeignKey( + name: "FK_ModulePrefix_BotConfig_BotConfigId", + column: x => x.BotConfigId, + principalTable: "BotConfig", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "PlayingStatus", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Autoincrement", true), + BotConfigId = table.Column(nullable: true), + Status = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PlayingStatus", x => x.Id); + table.ForeignKey( + name: "FK_PlayingStatus_BotConfig_BotConfigId", + column: x => x.BotConfigId, + principalTable: "BotConfig", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "RaceAnimal", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Autoincrement", true), + BotConfigId = table.Column(nullable: true), + Icon = table.Column(nullable: true), + Name = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_RaceAnimal", x => x.Id); + table.ForeignKey( + name: "FK_RaceAnimal_BotConfig_BotConfigId", + column: x => x.BotConfigId, + principalTable: "BotConfig", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + migrationBuilder.CreateTable( name: "ClashCallers", columns: table => new @@ -142,25 +264,10 @@ namespace NadekoBot.Migrations onDelete: ReferentialAction.Cascade); }); - migrationBuilder.CreateTable( - name: "PlayingStatus", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("Autoincrement", true), - GuildConfigId = table.Column(nullable: true), - Status = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_PlayingStatus", x => x.Id); - table.ForeignKey( - name: "FK_PlayingStatus_GuildConfigs_GuildConfigId", - column: x => x.GuildConfigId, - principalTable: "GuildConfigs", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); + migrationBuilder.CreateIndex( + name: "IX_BlacklistItem_BotConfigId", + table: "BlacklistItem", + column: "BotConfigId"); migrationBuilder.CreateIndex( name: "IX_ClashCallers_ClashWarId", @@ -173,6 +280,11 @@ namespace NadekoBot.Migrations column: "UserId", unique: true); + migrationBuilder.CreateIndex( + name: "IX_EightBallResponse_BotConfigId", + table: "EightBallResponse", + column: "BotConfigId"); + migrationBuilder.CreateIndex( name: "IX_GuildConfigs_GuildId", table: "GuildConfigs", @@ -180,9 +292,19 @@ namespace NadekoBot.Migrations unique: true); migrationBuilder.CreateIndex( - name: "IX_PlayingStatus_GuildConfigId", + name: "IX_ModulePrefix_BotConfigId", + table: "ModulePrefix", + column: "BotConfigId"); + + migrationBuilder.CreateIndex( + name: "IX_PlayingStatus_BotConfigId", table: "PlayingStatus", - column: "GuildConfigId"); + column: "BotConfigId"); + + migrationBuilder.CreateIndex( + name: "IX_RaceAnimal_BotConfigId", + table: "RaceAnimal", + column: "BotConfigId"); migrationBuilder.CreateIndex( name: "IX_SelfAssignableRoles_GuildId_RoleId", @@ -193,18 +315,33 @@ namespace NadekoBot.Migrations protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "BlacklistItem"); + migrationBuilder.DropTable( name: "ClashCallers"); migrationBuilder.DropTable( name: "Donators"); + migrationBuilder.DropTable( + name: "EightBallResponse"); + + migrationBuilder.DropTable( + name: "GuildConfigs"); + + migrationBuilder.DropTable( + name: "ModulePrefix"); + migrationBuilder.DropTable( name: "PlayingStatus"); migrationBuilder.DropTable( name: "Quotes"); + migrationBuilder.DropTable( + name: "RaceAnimal"); + migrationBuilder.DropTable( name: "Reminders"); @@ -215,7 +352,7 @@ namespace NadekoBot.Migrations name: "ClashOfClans"); migrationBuilder.DropTable( - name: "GuildConfigs"); + name: "BotConfig"); } } } diff --git a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs index 509a3bd9..b9042c98 100644 --- a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs +++ b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs @@ -15,6 +15,50 @@ namespace NadekoBot.Migrations modelBuilder .HasAnnotation("ProductVersion", "1.0.0-rtm-21431"); + modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("ItemId"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("BlacklistItem"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.BotConfig", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BufferSize"); + + b.Property("CurrencyName"); + + b.Property("CurrencyPluralName"); + + b.Property("CurrencySign"); + + b.Property("DontJoinServers"); + + b.Property("ForwardMessages"); + + b.Property("ForwardToAllOwners"); + + b.Property("RemindMessageFormat"); + + b.Property("RotatingStatuses"); + + b.HasKey("Id"); + + b.ToTable("BotConfig"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashCaller", b => { b.Property("Id") @@ -78,6 +122,22 @@ namespace NadekoBot.Migrations b.ToTable("Donators"); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.EightBallResponse", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("Text"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("EightBallResponse"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.GuildConfig", b => { b.Property("Id") @@ -109,8 +169,6 @@ namespace NadekoBot.Migrations b.Property("GuildId"); - b.Property("RotatingStatuses"); - b.Property("SendChannelByeMessage"); b.Property("SendChannelGreetMessage"); @@ -125,18 +183,36 @@ namespace NadekoBot.Migrations b.ToTable("GuildConfigs"); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("ModuleName"); + + b.Property("Prefix"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("ModulePrefix"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b => { b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("GuildConfigId"); + b.Property("BotConfigId"); b.Property("Status"); b.HasKey("Id"); - b.HasIndex("GuildConfigId"); + b.HasIndex("BotConfigId"); b.ToTable("PlayingStatus"); }); @@ -164,6 +240,24 @@ namespace NadekoBot.Migrations b.ToTable("Quotes"); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("Icon"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.ToTable("RaceAnimal"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.Reminder", b => { b.Property("Id") @@ -203,6 +297,13 @@ namespace NadekoBot.Migrations b.ToTable("SelfAssignableRoles"); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.BlacklistItem", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("Blacklist") + .HasForeignKey("BotConfigId"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashCaller", b => { b.HasOne("NadekoBot.Services.Database.Models.ClashWar", "ClashWar") @@ -211,11 +312,32 @@ namespace NadekoBot.Migrations .OnDelete(DeleteBehavior.Cascade); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.EightBallResponse", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("EightBallResponses") + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.ModulePrefix", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("ModulePrefixes") + .HasForeignKey("BotConfigId"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.PlayingStatus", b => { - b.HasOne("NadekoBot.Services.Database.Models.GuildConfig") + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") .WithMany("RotatingStatusMessages") - .HasForeignKey("GuildConfigId"); + .HasForeignKey("BotConfigId"); + }); + + modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("RaceAnimals") + .HasForeignKey("BotConfigId"); }); } } diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 345b8949..7578b58e 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Administration [Module(".", AppendSpace = false)] public partial class Administration : DiscordModule { - public Administration(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client) + public Administration(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client) { } diff --git a/src/NadekoBot/Modules/Administration/Commands/PlayingRotate.cs b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs similarity index 56% rename from src/NadekoBot/Modules/Administration/Commands/PlayingRotate.cs rename to src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs index ed3e7e3f..d7757ee2 100644 --- a/src/NadekoBot/Modules/Administration/Commands/PlayingRotate.cs +++ b/src/NadekoBot/Modules/Administration/Commands/PlayingRotateCommands.cs @@ -5,6 +5,7 @@ using NadekoBot.Attributes; using NadekoBot.Services; using NadekoBot.Services.Database; using NadekoBot.Services.Database.Models; +using NLog; using System; using System.Collections.Generic; using System.Linq; @@ -20,6 +21,52 @@ namespace NadekoBot.Modules.Administration [Group] public class PlayingRotateCommands { + private Logger _log { get; } + + public PlayingRotateCommands() + { + _log = LogManager.GetCurrentClassLogger(); + Task.Run(async () => + { + var index = 0; + do + { + try + { + BotConfig conf; + using (var uow = DbHandler.UnitOfWork()) + { + conf = uow.BotConfig.GetOrCreate(); + } + + if (!conf.RotatingStatuses) + continue; + else + { + if (index >= conf.RotatingStatusMessages.Count) + index = 0; + + if (!conf.RotatingStatusMessages.Any()) + continue; + + await NadekoBot.Client + .GetCurrentUser() + .ModifyStatusAsync(mpp => mpp.Game = new Game(conf.RotatingStatusMessages[index++].Status)) + .ConfigureAwait(false); + } + } + catch (Exception ex) + { + _log.Warn("Rotating playing status errored.\n" + ex); + } + finally + { + await Task.Delay(15000); + } + } while (true); + }); + } + public static Dictionary> PlayingPlaceholders { get; } = new Dictionary> { {"%servers%", () => NadekoBot.Client.GetGuilds().Count().ToString()}, @@ -45,28 +92,34 @@ namespace NadekoBot.Modules.Administration { var channel = (ITextChannel)imsg.Channel; + bool status; using (var uow = DbHandler.UnitOfWork()) { - var config = uow.GuildConfigs.For(channel.Guild.Id); + var config = uow.BotConfig.GetOrCreate(); - config.RotatingStatuses = !config.RotatingStatuses; + status = config.RotatingStatuses = !config.RotatingStatuses; await uow.CompleteAsync(); } + if (status) + await channel.SendMessageAsync("`Rotating playing status enabled.`"); + else + await channel.SendMessageAsync("`Rotating playing status disabled.`"); } [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task AddPlaying(IMessage imsg, string status) + public async Task AddPlaying(IMessage imsg, [Remainder] string status) { var channel = (ITextChannel)imsg.Channel; using (var uow = DbHandler.UnitOfWork()) { - var config = uow.GuildConfigs.For(channel.Guild.Id); + var config = uow.BotConfig.GetOrCreate(); config.RotatingStatusMessages.Add(new PlayingStatus { Status = status }); await uow.CompleteAsync(); } + await channel.SendMessageAsync("`Added.`").ConfigureAwait(false); } [LocalizedCommand, LocalizedDescription, LocalizedSummary] @@ -78,7 +131,7 @@ namespace NadekoBot.Modules.Administration List statuses; using (var uow = DbHandler.UnitOfWork()) { - statuses = uow.GuildConfigs.For(channel.Guild.Id).RotatingStatusMessages; + statuses = uow.BotConfig.GetOrCreate().RotatingStatusMessages; } if (!statuses.Any()) @@ -86,7 +139,7 @@ namespace NadekoBot.Modules.Administration else { var i = 1; - await channel.SendMessageAsync($"{imsg.Author.Mention} Here is a list of rotating statuses:\n" + string.Join("\n", statuses.Select(rs => $"`{i++}.` {rs.Status}\n"))); + await channel.SendMessageAsync($"{imsg.Author.Mention} `Here is a list of rotating statuses:`\n\n\t" + string.Join("\n\t", statuses.Select(rs => $"`{i++}.` {rs.Status}"))); } } @@ -96,17 +149,20 @@ namespace NadekoBot.Modules.Administration public async Task RemovePlaying(IMessage imsg, int index) { var channel = (ITextChannel)imsg.Channel; + index -= 1; + string msg = ""; using (var uow = DbHandler.UnitOfWork()) { - var config = uow.GuildConfigs.For(channel.Guild.Id); + var config = uow.BotConfig.GetOrCreate(); if (index >= config.RotatingStatusMessages.Count) return; - + msg = config.RotatingStatusMessages[index].Status; config.RotatingStatusMessages.RemoveAt(index); await uow.CompleteAsync(); } + await channel.SendMessageAsync($"`Removed the the playing message:` {msg}").ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs b/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs index 62367330..01ec4f21 100644 --- a/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs @@ -62,7 +62,7 @@ namespace NadekoBot.Modules.Administration success = uow.SelfAssignedRoles.DeleteByGuildAndRoleId(role.GuildId, role.Id); await uow.CompleteAsync(); } - if (success) + if (!success) { await channel.SendMessageAsync(":anger:That role is not self-assignable.").ConfigureAwait(false); return; @@ -183,7 +183,7 @@ namespace NadekoBot.Modules.Administration [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] - public async Task Iamnot(IMessage imsg, IRole role) + public async Task Iamnot(IMessage imsg, [Remainder] IRole role) { var channel = (ITextChannel)imsg.Channel; var guildUser = (IGuildUser)imsg.Author; diff --git a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs index e45536f8..3873bcc6 100644 --- a/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs +++ b/src/NadekoBot/Modules/ClashOfClans/ClashOfClans.cs @@ -20,7 +20,7 @@ namespace NadekoBot.Modules.ClashOfClans { public static ConcurrentDictionary> ClashWars { get; set; } = new ConcurrentDictionary>(); - public ClashOfClans(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client) + public ClashOfClans(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client) { using (var uow = DbHandler.UnitOfWork()) { diff --git a/src/NadekoBot/Modules/DiscordModule.cs b/src/NadekoBot/Modules/DiscordModule.cs index bf8719f1..47fdfdf9 100644 --- a/src/NadekoBot/Modules/DiscordModule.cs +++ b/src/NadekoBot/Modules/DiscordModule.cs @@ -10,15 +10,13 @@ namespace NadekoBot.Modules { protected ILocalization _l; protected CommandService _commands; - protected IBotConfiguration _config; protected DiscordSocketClient _client; protected Logger _log; - public DiscordModule(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) + public DiscordModule(ILocalization loc, CommandService cmds, DiscordSocketClient client) { _l = loc; _commands = cmds; - _config = config; _client = client; _log = LogManager.GetCurrentClassLogger(); } diff --git a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs index 765f49b9..0fea97cd 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs @@ -2,6 +2,8 @@ using Discord.Commands; using NadekoBot.Attributes; using NadekoBot.Extensions; +using NadekoBot.Services; +using NadekoBot.Services.Database; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -63,7 +65,7 @@ namespace NadekoBot.Modules.Gambling public class AnimalRace { - private ConcurrentQueue animals = new ConcurrentQueue(NadekoBot.Config.RaceAnimals.Shuffle()); + private ConcurrentQueue animals { get; } public bool Fail { get; internal set; } @@ -83,6 +85,13 @@ namespace NadekoBot.Modules.Gambling Fail = true; return; } + + using (var uow = DbHandler.UnitOfWork()) + { + animals = new ConcurrentQueue(uow.BotConfig.GetOrCreate().RaceAnimals.Select(ra=>ra.Icon).Shuffle()); + } + + var cancelSource = new CancellationTokenSource(); var token = cancelSource.Token; var fullgame = CheckForFullGameAsync(token); @@ -184,7 +193,7 @@ namespace NadekoBot.Modules.Gambling var wonAmount = winner.AmountBet * (participants.Count - 1); //todo DB //await FlowersHandler.AddFlowersAsync(winner.User, "Won a Race", wonAmount).ConfigureAwait(false); - await raceChannel.SendMessageAsync($"🏁 {winner.User.Mention} as {winner.Animal} **Won the race and {wonAmount}{NadekoBot.Config.Currency.Sign}!**").ConfigureAwait(false); + await raceChannel.SendMessageAsync($"🏁 {winner.User.Mention} as {winner.Animal} **Won the race and {wonAmount}{CurrencySign}!**").ConfigureAwait(false); } else { @@ -228,7 +237,7 @@ namespace NadekoBot.Modules.Gambling return false; } participants.Add(p); - await raceChannel.SendMessageAsync($"{u.Mention} **joined the race as a {p.Animal}" + (amount > 0 ? $" and bet {amount} {(amount == 1? NadekoBot.Config.Currency.Name: NadekoBot.Config.Currency.PluralName)}!**" : "**")); + await raceChannel.SendMessageAsync($"{u.Mention} **joined the race as a {p.Animal}" + (amount > 0 ? $" and bet {amount} {(amount == 1? CurrencyName : CurrencyPluralName)}!**" : "**")); return true; } } diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 72d72fb4..26411beb 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using NadekoBot.Services; using Discord.WebSocket; +using NadekoBot.Services.Database; //todo DB namespace NadekoBot.Modules.Gambling @@ -15,8 +16,21 @@ namespace NadekoBot.Modules.Gambling [Module("$", AppendSpace = false)] public partial class Gambling : DiscordModule { - public Gambling(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client) + public static string CurrencyName { get; set; } + public static string CurrencyPluralName { get; set; } + public static string CurrencySign { get; set; } + + public Gambling(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client) { + using (var uow = DbHandler.UnitOfWork()) + { + var conf = uow.BotConfig.GetOrCreate(); + + CurrencyName = conf.CurrencyName; + CurrencySign = conf.CurrencySign; + CurrencyPluralName = conf.CurrencyPluralName; + } + } [LocalizedCommand, LocalizedDescription, LocalizedSummary] diff --git a/src/NadekoBot/Modules/Games/Games.cs b/src/NadekoBot/Modules/Games/Games.cs index 861d4697..8f47d1f9 100644 --- a/src/NadekoBot/Modules/Games/Games.cs +++ b/src/NadekoBot/Modules/Games/Games.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Collections.Generic; using NadekoBot.Extensions; using Discord.WebSocket; +using NadekoBot.Services.Database; namespace NadekoBot.Modules.Games { @@ -15,10 +16,16 @@ namespace NadekoBot.Modules.Games public partial class Games : DiscordModule { //todo DB - private IEnumerable _8BallResponses; - public Games(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client) + private IEnumerable _8BallResponses { + get { + using (var uow = DbHandler.UnitOfWork()) + { + return uow.BotConfig.GetOrCreate().EightBallResponses.Select(ebr => ebr.Text); + } + } + } + public Games(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client) { - _8BallResponses = config.EightBallResponses; } [LocalizedCommand, LocalizedDescription, LocalizedSummary] diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 68e9cca4..f9135a8b 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -21,7 +21,7 @@ namespace NadekoBot.Modules.Help return str + String.Format(str, NadekoBot.Credentials.ClientId); } } - public Help(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client) + public Help(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client) { } diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 09e780f9..87feee7b 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -24,7 +24,7 @@ namespace NadekoBot.Modules.Music public const string MusicDataPath = "data/musicdata"; private IGoogleApiService _google; - public Music(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client, IGoogleApiService google) : base(loc, cmds, config, client) + public Music(ILocalization loc, CommandService cmds, DiscordSocketClient client, IGoogleApiService google) : base(loc, cmds, client) { //it can fail if its currenctly opened or doesn't exist. Either way i don't care try { Directory.Delete(MusicDataPath, true); } catch { } diff --git a/src/NadekoBot/Modules/NSFW/NSFW.cs b/src/NadekoBot/Modules/NSFW/NSFW.cs index 3fb08633..a3e5c1b2 100644 --- a/src/NadekoBot/Modules/NSFW/NSFW.cs +++ b/src/NadekoBot/Modules/NSFW/NSFW.cs @@ -18,7 +18,7 @@ namespace NadekoBot.Modules.NSFW [Module("~", AppendSpace = false)] public class NSFW : DiscordModule { - public NSFW(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client) + public NSFW(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client) { } diff --git a/src/NadekoBot/Modules/Pokemon/Pokemon.cs b/src/NadekoBot/Modules/Pokemon/Pokemon.cs index fef39c40..05d33675 100644 --- a/src/NadekoBot/Modules/Pokemon/Pokemon.cs +++ b/src/NadekoBot/Modules/Pokemon/Pokemon.cs @@ -10,7 +10,7 @@ namespace NadekoBot.Modules.Games [Module(">", AppendSpace = false)] public partial class Pokemon : DiscordModule { - public Pokemon(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client) + public Pokemon(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client) { } diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index b729efa7..4181ff55 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -21,7 +21,7 @@ namespace NadekoBot.Modules.Searches { private IGoogleApiService _google { get; } - public Searches(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client, IGoogleApiService youtube) : base(loc, cmds, config, client) + public Searches(ILocalization loc, CommandService cmds, DiscordSocketClient client, IGoogleApiService youtube) : base(loc, cmds, client) { _google = youtube; } diff --git a/src/NadekoBot/Modules/Translator/Translator.cs b/src/NadekoBot/Modules/Translator/Translator.cs index 2003f5d4..85cb85e7 100644 --- a/src/NadekoBot/Modules/Translator/Translator.cs +++ b/src/NadekoBot/Modules/Translator/Translator.cs @@ -12,7 +12,7 @@ namespace NadekoBot.Modules.Translator [Module("~", AppendSpace = false)] public class Translator : DiscordModule { - public Translator(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client) + public Translator(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client) { } diff --git a/src/NadekoBot/Modules/Utility/Commands/Remind.cs b/src/NadekoBot/Modules/Utility/Commands/Remind.cs index 4036d8c0..3920b311 100644 --- a/src/NadekoBot/Modules/Utility/Commands/Remind.cs +++ b/src/NadekoBot/Modules/Utility/Commands/Remind.cs @@ -23,6 +23,8 @@ namespace NadekoBot.Modules.Utility Regex regex = new Regex(@"^(?:(?\d)mo)?(?:(?\d)w)?(?:(?\d{1,2})d)?(?:(?\d{1,2})h)?(?:(?\d{1,2})m)?$", RegexOptions.Compiled | RegexOptions.Multiline); + private string RemindMessageFormat { get; } + IDictionary> replacements = new Dictionary> { { "%message%" , (r) => r.Message }, @@ -36,6 +38,8 @@ namespace NadekoBot.Modules.Utility using (var uow = DbHandler.UnitOfWork()) { reminders = uow.Reminders.GetAll().ToList(); + + RemindMessageFormat = uow.BotConfig.GetOrCreate().RemindMessageFormat; } foreach (var r in reminders) @@ -74,7 +78,7 @@ namespace NadekoBot.Modules.Utility return; await ch.SendMessageAsync( - replacements.Aggregate(NadekoBot.Config.RemindMessageFormat, + replacements.Aggregate(RemindMessageFormat, (cur, replace) => cur.Replace(replace.Key, replace.Value(r))) ).ConfigureAwait(false); //it works trust me diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 12ff226e..d3adc055 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Utility [Module(".", AppendSpace = false)] public partial class Utility : DiscordModule { - public Utility(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client) + public Utility(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client) { } @@ -129,6 +129,19 @@ namespace NadekoBot.Modules.Utility } } + [LocalizedCommand, LocalizedDescription, LocalizedSummary] + [RequireContext(ContextType.Guild)] + public async Task ChannelTopic(IMessage imsg) + { + var channel = (ITextChannel)imsg.Channel; + + var topic = channel.Topic; + if (string.IsNullOrWhiteSpace(topic)) + await channel.SendMessageAsync("`No topic set.`"); + else + await channel.SendMessageAsync("`Topic:` " + topic); + } + [LocalizedCommand, LocalizedDescription, LocalizedSummary] [RequireContext(ContextType.Guild)] public async Task Stats(IMessage imsg) diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index dd417b20..4923039c 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -20,7 +20,6 @@ namespace NadekoBot public static CommandService Commands { get; private set; } public static DiscordSocketClient Client { get; private set; } - public static BotConfiguration Config { get; private set; } public static Localization Localizer { get; private set; } public static BotCredentials Credentials { get; private set; } @@ -42,7 +41,6 @@ namespace NadekoBot //initialize Services Credentials = new BotCredentials(); Commands = new CommandService(); - Config = new BotConfiguration(); Localizer = new Localization(); Google = new GoogleApiService(); Stats = new StatsService(Client); @@ -51,7 +49,6 @@ namespace NadekoBot //setup DI var depMap = new DependencyMap(); depMap.Add(Localizer); - depMap.Add(Config); depMap.Add(Client); depMap.Add(Commands); depMap.Add(Google); diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 3ed74b6a..380f6767 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -6647,6 +6647,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to toggle whether the self-assigned roles should be exclusive. + /// + public static string tesar_desc { + get { + return ResourceManager.GetString("tesar_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `.tesar`. + /// + public static string tesar_summary { + get { + return ResourceManager.GetString("tesar_summary", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to tesar. + /// + public static string tesar_text { + get { + return ResourceManager.GetString("tesar_text", resourceCulture); + } + } + /// /// Looks up a localized string similar to Shows a current trivia leaderboard.. /// @@ -6674,33 +6701,6 @@ namespace NadekoBot.Resources { } } - /// - /// Looks up a localized string similar to toggle whether the self-assigned roles should be exclusive. - /// - public static string togglexclsar_desc { - get { - return ResourceManager.GetString("togglexclsar_desc", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to `.tesar`. - /// - public static string togglexclsar_summary { - get { - return ResourceManager.GetString("togglexclsar_summary", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to togglexclsar. - /// - public static string togglexclsar_text { - get { - return ResourceManager.GetString("togglexclsar_text", resourceCulture); - } - } - /// /// Looks up a localized string similar to Quits current trivia after current question.. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 38be8b2c..d18d35b8 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -405,13 +405,13 @@ `.lsar` - - togglexclsar + + tesar - + toggle whether the self-assigned roles should be exclusive - + `.tesar` diff --git a/src/NadekoBot/Resources/ResponseStrings.Designer.cs b/src/NadekoBot/Resources/ResponseStrings.Designer.cs index 15ceb39d..72395491 100644 --- a/src/NadekoBot/Resources/ResponseStrings.Designer.cs +++ b/src/NadekoBot/Resources/ResponseStrings.Designer.cs @@ -58,14 +58,5 @@ namespace NadekoBot.Resources { resourceCulture = value; } } - - /// - /// Looks up a localized string similar to TESTING. - /// - public static string test { - get { - return ResourceManager.GetString("test", resourceCulture); - } - } } } diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index 188ec335..1af7de15 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -117,7 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - TESTING - \ No newline at end of file diff --git a/src/NadekoBot/Services/Database/IUnitOfWork.cs b/src/NadekoBot/Services/Database/IUnitOfWork.cs index 6db44ae8..3a3fb2c2 100644 --- a/src/NadekoBot/Services/Database/IUnitOfWork.cs +++ b/src/NadekoBot/Services/Database/IUnitOfWork.cs @@ -15,6 +15,7 @@ namespace NadekoBot.Services.Database IClashOfClansRepository ClashOfClans { get; } IReminderRepository Reminders { get; } ISelfAssignedRolesRepository SelfAssignedRoles { get; } + IBotConfigRepository BotConfig { get; } int Complete(); Task CompleteAsync(); diff --git a/src/NadekoBot/Services/Database/Models/BotConfig.cs b/src/NadekoBot/Services/Database/Models/BotConfig.cs new file mode 100644 index 00000000..6bb02fb3 --- /dev/null +++ b/src/NadekoBot/Services/Database/Models/BotConfig.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.Services.Database.Models +{ + public class BotConfig : DbEntity + { + public HashSet Blacklist { get; set; } + public ulong BufferSize { get; set; } = 4000000; + public bool DontJoinServers { get; set; } = false; + public bool ForwardMessages { get; set; } = true; + public bool ForwardToAllOwners { get; set; } = true; + + public List ModulePrefixes { get; set; } = new List() + { + new ModulePrefix() { ModuleName="Administration", Prefix="." }, + new ModulePrefix() { ModuleName="Searches", Prefix="~" }, + new ModulePrefix() { ModuleName="NSFW", Prefix="~" }, + new ModulePrefix() { ModuleName="ClashOfClans", Prefix="," }, + new ModulePrefix() { ModuleName="Help", Prefix="-" }, + new ModulePrefix() { ModuleName="Music", Prefix="!!" }, + new ModulePrefix() { ModuleName="Trello", Prefix="trello" }, + new ModulePrefix() { ModuleName="Games", Prefix=">" }, + new ModulePrefix() { ModuleName="Gambling", Prefix="$" }, + new ModulePrefix() { ModuleName="Permissions", Prefix=";" }, + new ModulePrefix() { ModuleName="Pokemon", Prefix=">" }, + new ModulePrefix() { ModuleName="Utility", Prefix="." } + }; + + public List RotatingStatusMessages { get; set; } = new List(); + + public bool RotatingStatuses { get; set; } = false; + public string RemindMessageFormat { get; set; } = "❗⏰**I've been told to remind you to '%message%' now by %user%.**⏰❗"; + + + public string CurrencySign { get; set; } = "🌸"; + public string CurrencyName { get; set; } = "Nadeko Flower"; + public string CurrencyPluralName { get; set; } = "Nadeko Flowers"; + + public List EightBallResponses { get; set; } = new List + { + new EightBallResponse() { Text = "Most definitely yes" }, + new EightBallResponse() { Text = "For sure" }, + new EightBallResponse() { Text = "Totally!" }, + new EightBallResponse() { Text = "As I see it, yes" }, + new EightBallResponse() { Text = "My sources say yes" }, + new EightBallResponse() { Text = "Yes" }, + new EightBallResponse() { Text = "Most likely" }, + new EightBallResponse() { Text = "Perhaps" }, + new EightBallResponse() { Text = "Maybe" }, + new EightBallResponse() { Text = "Not sure" }, + new EightBallResponse() { Text = "It is uncertain" }, + new EightBallResponse() { Text = "Ask me again later" }, + new EightBallResponse() { Text = "Don't count on it" }, + new EightBallResponse() { Text = "Probably not" }, + new EightBallResponse() { Text = "Very doubtful" }, + new EightBallResponse() { Text = "Most likely no" }, + new EightBallResponse() { Text = "Nope" }, + new EightBallResponse() { Text = "No" }, + new EightBallResponse() { Text = "My sources say no" }, + new EightBallResponse() { Text = "Dont even think about it" }, + new EightBallResponse() { Text = "Definitely no" }, + new EightBallResponse() { Text = "NO - It may cause disease contraction" } + }; + + public List RaceAnimals { get; set; } = new List + { + new RaceAnimal { Icon = "🐼", Name = "Panda" }, + new RaceAnimal { Icon = "🐻", Name = "Bear" }, + new RaceAnimal { Icon = "🐧", Name = "Pengu" }, + new RaceAnimal { Icon = "🐨", Name = "Koala" }, + new RaceAnimal { Icon = "🐬", Name = "Dolphin" }, + new RaceAnimal { Icon = "🐞", Name = "Ladybird" }, + new RaceAnimal { Icon = "🦀", Name = "Crab" }, + new RaceAnimal { Icon = "🦄", Name = "Unicorn" } + }; + } + + public class PlayingStatus :DbEntity + { + public string Status { get; set; } + } + + public class BlacklistItem : DbEntity + { + public ulong ItemId { get; set; } + public enum BlacklistType + { + Server, + Channel, + User + } + } + + public class EightBallResponse : DbEntity + { + public string Text { get; set; } + } + + public class RaceAnimal : DbEntity + { + public string Icon { get; set; } + public string Name { get; set; } + } + + public class ModulePrefix : DbEntity + { + public string ModuleName { get; set; } + public string Prefix { get; set; } + } +} diff --git a/src/NadekoBot/Services/Database/Models/GuildConfig.cs b/src/NadekoBot/Services/Database/Models/GuildConfig.cs index 7ffe046f..77c1d966 100644 --- a/src/NadekoBot/Services/Database/Models/GuildConfig.cs +++ b/src/NadekoBot/Services/Database/Models/GuildConfig.cs @@ -31,12 +31,5 @@ namespace NadekoBot.Services.Database.Models //self assignable roles public bool ExclusiveSelfAssignedRoles { get; set; } public bool AutoDeleteSelfAssignedRoleMessages { get; set; } - public bool RotatingStatuses { get; set; } - public List RotatingStatusMessages { get; set; } - } - - public class PlayingStatus : DbEntity - { - public string Status { get; set; } } } diff --git a/src/NadekoBot/Services/Database/NadekoContext.cs b/src/NadekoBot/Services/Database/NadekoContext.cs index e576ec62..378c1637 100644 --- a/src/NadekoBot/Services/Database/NadekoContext.cs +++ b/src/NadekoBot/Services/Database/NadekoContext.cs @@ -17,6 +17,7 @@ namespace NadekoBot.Services.Database public DbSet ClashCallers { get; set; } public DbSet Reminders { get; set; } public DbSet SelfAssignableRoles { get; set; } + public DbSet BotConfig { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -25,8 +26,7 @@ namespace NadekoBot.Services.Database var quoteEntity = modelBuilder.Entity(); #endregion - - + #region Donators var donatorEntity = modelBuilder.Entity(); diff --git a/src/NadekoBot/Services/Database/Repositories/IBotConfigRepository.cs b/src/NadekoBot/Services/Database/Repositories/IBotConfigRepository.cs new file mode 100644 index 00000000..c82ed462 --- /dev/null +++ b/src/NadekoBot/Services/Database/Repositories/IBotConfigRepository.cs @@ -0,0 +1,14 @@ +using NadekoBot.Services.Database.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.Services.Database.Repositories +{ + public interface IBotConfigRepository : IRepository + { + BotConfig GetOrCreate(); + } +} diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/BotConfigRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/BotConfigRepository.cs new file mode 100644 index 00000000..78c4e086 --- /dev/null +++ b/src/NadekoBot/Services/Database/Repositories/Impl/BotConfigRepository.cs @@ -0,0 +1,34 @@ +using NadekoBot.Services.Database.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; + +namespace NadekoBot.Services.Database.Repositories.Impl +{ + public class BotConfigRepository : Repository, IBotConfigRepository + { + public BotConfigRepository(DbContext context) : base(context) + { + } + + public BotConfig GetOrCreate() + { + var config = _set.Include(bc => bc.RotatingStatusMessages) + .Include(bc => bc.RaceAnimals) + .Include(bc => bc.Blacklist) + .Include(bc => bc.EightBallResponses) + .Include(bc => bc.ModulePrefixes) + .FirstOrDefault(); + + if (config == null) + { + _set.Add(config = new BotConfig()); + _context.SaveChanges(); + } + return config; + } + } +} diff --git a/src/NadekoBot/Services/Database/Repositories/Impl/SelfAssignedRolesRepository.cs b/src/NadekoBot/Services/Database/Repositories/Impl/SelfAssignedRolesRepository.cs index 3e980e10..17c4caf0 100644 --- a/src/NadekoBot/Services/Database/Repositories/Impl/SelfAssignedRolesRepository.cs +++ b/src/NadekoBot/Services/Database/Repositories/Impl/SelfAssignedRolesRepository.cs @@ -26,6 +26,6 @@ namespace NadekoBot.Services.Database.Repositories.Impl } public IEnumerable GetFromGuild(ulong guildId) => - _set.Where(s => s.GuildId == guildId); + _set.Where(s => s.GuildId == guildId).ToList(); } } diff --git a/src/NadekoBot/Services/Database/UnitOfWork.cs b/src/NadekoBot/Services/Database/UnitOfWork.cs index b1680a63..5550bc6c 100644 --- a/src/NadekoBot/Services/Database/UnitOfWork.cs +++ b/src/NadekoBot/Services/Database/UnitOfWork.cs @@ -30,6 +30,9 @@ namespace NadekoBot.Services.Database private ISelfAssignedRolesRepository _selfAssignedRoles; public ISelfAssignedRolesRepository SelfAssignedRoles => _selfAssignedRoles ?? (_selfAssignedRoles = new SelfAssignedRolesRepository(_context)); + private IBotConfigRepository _botConfig; + public IBotConfigRepository BotConfig => _botConfig ?? (_botConfig = new BotConfigRepository(_context)); + public UnitOfWork(NadekoContext context) { _context = context; diff --git a/src/NadekoBot/Services/IBotConfiguration.cs b/src/NadekoBot/Services/IBotConfiguration.cs deleted file mode 100644 index 4b6a9898..00000000 --- a/src/NadekoBot/Services/IBotConfiguration.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.Generic; - -namespace NadekoBot.Services -{ - public interface IBotConfiguration - { - bool DontJoinServers { get; set; } - bool ForwardMessages { get; set; } - bool ForwardToAllOwners { get; set; } - - bool RotatePlayingStatus { get; set; } - List PlayingStatuses { get; set; } - - ulong BufferSize { get; set; } - List RaceAnimals { get; set; } - string RemindMessageFormat { get; set; } - - - HashSet BlacklistedServers { get; set; } - HashSet BlacklistedChannels { get; set; } - HashSet BlacklistedUsers { get; set; } - - List EightBallResponses { get; set; } - Currency Currency { get; set; } - - ModulePrefixes ModulePrefixes { get; set; } - } - - public class Currency { - public string Sign { get; set; } - public string Name { get; set; } - public string PluralName { get; set; } - } - - public class ModulePrefixes - { - public string Administration { get; set; } = "."; - public string Searches { get; set; } = "~"; - public string NSFW { get; set; } = "~"; - public string Conversations { get; set; } = "<@{0}>"; - public string ClashOfClans { get; set; } = ","; - public string Help { get; set; } = "-"; - public string Music { get; set; } = "!!"; - public string Trello { get; set; } = "trello "; - public string Games { get; set; } = ">"; - public string Gambling { get; set; } = "$"; - public string Permissions { get; set; } = ";"; - public string Programming { get; set; } = "%"; - public string Pokemon { get; set; } = ">"; - public string Utility { get; set; } = "."; - } -} diff --git a/src/NadekoBot/Services/Impl/BotConfiguration.cs b/src/NadekoBot/Services/Impl/BotConfiguration.cs deleted file mode 100644 index 8d6c17b0..00000000 --- a/src/NadekoBot/Services/Impl/BotConfiguration.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace NadekoBot.Services.Impl -{ - public class BotConfiguration : IBotConfiguration - { - internal Task _8BallResponses; - - public HashSet BlacklistedChannels { get; set; } = new HashSet(); - - public HashSet BlacklistedServers { get; set; } = new HashSet(); - - public HashSet BlacklistedUsers { get; set; } = new HashSet(); - - public ulong BufferSize { get; set; } = 4000000; - - public bool DontJoinServers { get; set; } = false; - - public bool ForwardMessages { get; set; } = true; - - public bool ForwardToAllOwners { get; set; } = true; - - public ModulePrefixes ModulePrefixes { get; set; } = new ModulePrefixes - { - Administration = ".", - ClashOfClans = ",", - Conversations = "<@{0}>", - Gambling = "$", - Games = ">", - Pokemon = ">", - Help = "-", - Music = "!!", - NSFW = "~", - Permissions = ";", - Programming = "%", - Searches = "~", - Trello = "trello", - Utility = "." - }; - - public List PlayingStatuses { get; set; } = new List(); - - public string RemindMessageFormat { get; set; } = "❗⏰**I've been told to remind you to '%message%' now by %user%.**⏰❗"; - - public bool RotatePlayingStatus { get; set; } = false; - - public Currency Currency { get; set; } = new Currency - { - Name = "Nadeko Flower", - PluralName = "Nadeko Flowers", - Sign = "🌸", - }; - - public List EightBallResponses { get; set; } = new List - { - "Most definitely yes", - "For sure", - "As I see it, yes", - "My sources say yes", - "Yes", - "Most likely", - "Perhaps", - "Maybe", - "Not sure", - "It is uncertain", - "Ask me again later", - "Don't count on it", - "Probably not", - "Very doubtful", - "Most likely no", - "Nope", - "No", - "My sources say no", - "Dont even think about it", - "Definitely no", - "NO - It may cause disease contraction" - }; - - public List RaceAnimals { get; set; } = new List - { - "🐼", - "🐻", - "🐧", - "🐨", - "🐬", - "🐞", - "🦀", - "🦄" - }; - } -} diff --git a/src/NadekoBot/project.lock.json b/src/NadekoBot/project.lock.json index ebd101b1..57023365 100644 --- a/src/NadekoBot/project.lock.json +++ b/src/NadekoBot/project.lock.json @@ -3161,7 +3161,7 @@ "lib/portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10/libvideo.dll": {} } }, - "Discord.Net/1.0.0-dev": { + "Discord.Net/1.0.0-beta": { "type": "project", "framework": ".NETStandard,Version=v1.3", "dependencies": { @@ -3188,7 +3188,7 @@ "netstandard1.3/Discord.Net.dll": {} } }, - "Discord.Net.Commands/1.0.0-dev": { + "Discord.Net.Commands/1.0.0-beta": { "type": "project", "framework": ".NETStandard,Version=v1.3", "dependencies": { @@ -9019,12 +9019,12 @@ "lib/portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10/libvideo.dll" ] }, - "Discord.Net/1.0.0-dev": { + "Discord.Net/1.0.0-beta": { "type": "project", "path": "../../discord.net/src/Discord.Net/project.json", "msbuildProject": "../../discord.net/src/Discord.Net/Discord.Net.xproj" }, - "Discord.Net.Commands/1.0.0-dev": { + "Discord.Net.Commands/1.0.0-beta": { "type": "project", "path": "../../discord.net/src/Discord.Net.Commands/project.json", "msbuildProject": "../../discord.net/src/Discord.Net.Commands/Discord.Net.Commands.xproj"