From f3513779b7155cb180754805498600f07598424b Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Mon, 9 Oct 2017 02:52:46 +0200 Subject: [PATCH] Typereaders will be autoloaded when module loads --- .../TypeReaders/BotCommandTypeReader.cs | 14 ++- .../TypeReaders/GuildDateTimeTypeReader.cs | 74 ++++++++-------- .../Common/TypeReaders/GuildTypeReader.cs | 6 +- .../Common/TypeReaders/ModuleTypeReader.cs | 10 ++- .../Common/TypeReaders/NadekoTypeReader.cs | 18 ++++ .../TypeReaders/PermissionActionTypeReader.cs | 8 +- .../Services/Database/NadekoContext.cs | 3 +- NadekoBot.Core/Services/NadekoBot.cs | 55 ++++++++++-- .../NadekoBot.Modules.Gambling.csproj | 4 + .../WaifuClaimCommands.cs | 2 +- .../Common/Hangman/Hangman.cs | 6 +- .../Common/Hangman/TermPool.cs | 18 ++-- NadekoBot.Modules.Games/HangmanCommands.cs | 4 +- .../NadekoBot.Modules.Games.csproj | 4 + .../Services/GamesService.cs | 3 + .../NadekoBot.Modules.Music.csproj | 4 + .../Exceptions/TagBlacklistedException.cs | 7 -- NadekoBot.Modules.Nsfw/NSFW.cs | 13 +-- .../NadekoBot.Modules.Nsfw.csproj | 6 +- .../NadekoBot.Modules.Pokemon.csproj | 4 + .../AnimeSearchCommands.cs | 0 .../Common/AnimeResult.cs | 0 .../Common/DefineModel.cs | 0 .../Exceptions/StreamNotFoundException.cs | 0 .../Common/GoogleSearchResult.cs | 0 .../Common/MagicItem.cs | 0 .../Common/MangaResult.cs | 0 .../Common/OmdbProvider.cs | 0 .../Common/OverwatchApiModel.cs | 0 .../Common/SearchImageCacher.cs | 0 .../Common/SearchPokemon.cs | 0 .../Common/StreamResponses.cs | 0 .../Common/TimeModels.cs | 0 .../Common/WeatherModels.cs | 0 .../Common/WikipediaApiModel.cs | 0 .../Common/WoWJoke.cs | 0 .../Exceptions/TagBlacklistedException.cs | 12 +++ .../FeedCommands.cs | 0 .../JokeCommands.cs | 0 .../LoLCommands.cs | 0 .../MemegenCommands.cs | 0 .../NadekoBot.Modules.Searches.csproj | 0 .../OsuCommands.cs | 0 .../OverwatchCommands.cs | 0 .../PlaceCommands.cs | 0 .../PokemonSearchCommands.cs | 0 .../Searches.cs | 0 .../Services/AnimeSearchService.cs | 0 .../Services/FeedsService.cs | 0 .../Services/SearchesService.cs | 22 ++--- .../Services/StreamNotificationService.cs | 0 .../StreamNotificationCommands.cs | 0 .../TranslatorCommands.cs | 0 .../XkcdCommands.cs | 0 .../NadekoBot.Modules.Searches.csproj | 23 +++++ .../NadekoBot.Modules.Utility.csproj | 8 ++ NadekoBot.Modules.Utility/RepeatCommands.cs | 86 +++++++++---------- .../NadekoBot.Modules.Xp.csproj | 4 + NadekoBot.sln | 18 ++-- watchbuildall.ps1 | 20 +++++ 60 files changed, 316 insertions(+), 140 deletions(-) create mode 100644 NadekoBot.Core/Common/TypeReaders/NadekoTypeReader.cs rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/AnimeSearchCommands.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/AnimeResult.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/DefineModel.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/Exceptions/StreamNotFoundException.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/GoogleSearchResult.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/MagicItem.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/MangaResult.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/OmdbProvider.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/OverwatchApiModel.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/SearchImageCacher.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/SearchPokemon.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/StreamResponses.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/TimeModels.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/WeatherModels.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/WikipediaApiModel.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Common/WoWJoke.cs (100%) create mode 100644 NadekoBot.Modules.Searches/Exceptions/TagBlacklistedException.cs rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/FeedCommands.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/JokeCommands.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/LoLCommands.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/MemegenCommands.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/NadekoBot.Modules.Searches.csproj (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/OsuCommands.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/OverwatchCommands.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/PlaceCommands.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/PokemonSearchCommands.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Searches.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Services/AnimeSearchService.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Services/FeedsService.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Services/SearchesService.cs (91%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/Services/StreamNotificationService.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/StreamNotificationCommands.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/TranslatorCommands.cs (100%) rename {NadekoBot.Module.Searches => NadekoBot.Modules.Searches}/XkcdCommands.cs (100%) create mode 100644 NadekoBot.Modules.Utility/NadekoBot.Modules.Searches.csproj create mode 100644 watchbuildall.ps1 diff --git a/NadekoBot.Core/Common/TypeReaders/BotCommandTypeReader.cs b/NadekoBot.Core/Common/TypeReaders/BotCommandTypeReader.cs index a0da4a2c..dfe7dca2 100644 --- a/NadekoBot.Core/Common/TypeReaders/BotCommandTypeReader.cs +++ b/NadekoBot.Core/Common/TypeReaders/BotCommandTypeReader.cs @@ -4,11 +4,17 @@ using System.Threading.Tasks; using Discord.Commands; using NadekoBot.Services; using NadekoBot.Modules.CustomReactions.Services; +using NadekoBot.Core.Common.TypeReaders; +using Discord.WebSocket; namespace NadekoBot.Common.TypeReaders { - public class CommandTypeReader : TypeReader + public class CommandTypeReader : NadekoTypeReader { + public CommandTypeReader(DiscordSocketClient client, CommandService cmds) : base(client, cmds) + { + } + public override Task Read(ICommandContext context, string input, IServiceProvider services) { var _cmds = ((INServiceProvider)services).GetService(); @@ -28,9 +34,13 @@ namespace NadekoBot.Common.TypeReaders return Task.FromResult(TypeReaderResult.FromSuccess(cmd)); } } - //todo dependency on the module + public class CommandOrCrTypeReader : CommandTypeReader { + public CommandOrCrTypeReader(DiscordSocketClient client, CommandService cmds) : base(client, cmds) + { + } + public override async Task Read(ICommandContext context, string input, IServiceProvider services) { input = input.ToUpperInvariant(); diff --git a/NadekoBot.Core/Common/TypeReaders/GuildDateTimeTypeReader.cs b/NadekoBot.Core/Common/TypeReaders/GuildDateTimeTypeReader.cs index 95a39b85..1624af2a 100644 --- a/NadekoBot.Core/Common/TypeReaders/GuildDateTimeTypeReader.cs +++ b/NadekoBot.Core/Common/TypeReaders/GuildDateTimeTypeReader.cs @@ -1,40 +1,46 @@ -//using System; -//using System.Threading.Tasks; -//using Discord.Commands; -//using NadekoBot.Modules.Administration.Services; +using System; +using System.Threading.Tasks; +using Discord.Commands; +using NadekoBot.Modules.Administration.Services; +using NadekoBot.Core.Common.TypeReaders; +using Discord.WebSocket; -//namespace NadekoBot.Common.TypeReaders -//{ -// public class GuildDateTimeTypeReader : TypeReader -// { -// public override Task Read(ICommandContext context, string input, IServiceProvider services) -// { -// var _gts = (GuildTimezoneService)services.GetService(typeof(GuildTimezoneService)); -// if (!DateTime.TryParse(input, out var dt)) -// return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Input string is in an incorrect format.")); +namespace NadekoBot.Common.TypeReaders +{ + public class GuildDateTimeTypeReader : NadekoTypeReader + { + public GuildDateTimeTypeReader(DiscordSocketClient client, CommandService cmds) : base(client, cmds) + { + } -// var tz = _gts.GetTimeZoneOrUtc(context.Guild.Id); + public override Task Read(ICommandContext context, string input, IServiceProvider services) + { + var _gts = (GuildTimezoneService)services.GetService(typeof(GuildTimezoneService)); + if (!DateTime.TryParse(input, out var dt)) + return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Input string is in an incorrect format.")); -// return Task.FromResult(TypeReaderResult.FromSuccess(new GuildDateTime(tz, dt))); -// } -// } + var tz = _gts.GetTimeZoneOrUtc(context.Guild.Id); -// public class GuildDateTime -// { -// public TimeZoneInfo Timezone { get; } -// public DateTime CurrentGuildTime { get; } -// public DateTime InputTime { get; } -// public DateTime InputTimeUtc { get; } + return Task.FromResult(TypeReaderResult.FromSuccess(new GuildDateTime(tz, dt))); + } + } -// private GuildDateTime() { } + public class GuildDateTime + { + public TimeZoneInfo Timezone { get; } + public DateTime CurrentGuildTime { get; } + public DateTime InputTime { get; } + public DateTime InputTimeUtc { get; } -// public GuildDateTime(TimeZoneInfo guildTimezone, DateTime inputTime) -// { -// var now = DateTime.UtcNow; -// Timezone = guildTimezone; -// CurrentGuildTime = TimeZoneInfo.ConvertTime(now, TimeZoneInfo.Utc, Timezone); -// InputTime = inputTime; -// InputTimeUtc = TimeZoneInfo.ConvertTime(inputTime, Timezone, TimeZoneInfo.Utc); -// } -// } -//} + private GuildDateTime() { } + + public GuildDateTime(TimeZoneInfo guildTimezone, DateTime inputTime) + { + var now = DateTime.UtcNow; + Timezone = guildTimezone; + CurrentGuildTime = TimeZoneInfo.ConvertTime(now, TimeZoneInfo.Utc, Timezone); + InputTime = inputTime; + InputTimeUtc = TimeZoneInfo.ConvertTime(inputTime, Timezone, TimeZoneInfo.Utc); + } + } +} diff --git a/NadekoBot.Core/Common/TypeReaders/GuildTypeReader.cs b/NadekoBot.Core/Common/TypeReaders/GuildTypeReader.cs index 132e1f0f..40571e97 100644 --- a/NadekoBot.Core/Common/TypeReaders/GuildTypeReader.cs +++ b/NadekoBot.Core/Common/TypeReaders/GuildTypeReader.cs @@ -3,17 +3,19 @@ using System.Linq; using System.Threading.Tasks; using Discord.Commands; using Discord.WebSocket; +using NadekoBot.Core.Common.TypeReaders; namespace NadekoBot.Common.TypeReaders { - public class GuildTypeReader : TypeReader + public class GuildTypeReader : NadekoTypeReader { private readonly DiscordSocketClient _client; - public GuildTypeReader(DiscordSocketClient client) + public GuildTypeReader(DiscordSocketClient client, CommandService cmds) : base(client, cmds) { _client = client; } + public override Task Read(ICommandContext context, string input, IServiceProvider _) { input = input.Trim().ToLowerInvariant(); diff --git a/NadekoBot.Core/Common/TypeReaders/ModuleTypeReader.cs b/NadekoBot.Core/Common/TypeReaders/ModuleTypeReader.cs index 1978732d..4ef4d52d 100644 --- a/NadekoBot.Core/Common/TypeReaders/ModuleTypeReader.cs +++ b/NadekoBot.Core/Common/TypeReaders/ModuleTypeReader.cs @@ -3,14 +3,16 @@ using System.Linq; using System.Threading.Tasks; using Discord.Commands; using NadekoBot.Extensions; +using NadekoBot.Core.Common.TypeReaders; +using Discord.WebSocket; namespace NadekoBot.Common.TypeReaders { - public class ModuleTypeReader : TypeReader + public class ModuleTypeReader : NadekoTypeReader { private readonly CommandService _cmds; - public ModuleTypeReader(CommandService cmds) + public ModuleTypeReader(DiscordSocketClient client, CommandService cmds) : base(client, cmds) { _cmds = cmds; } @@ -26,11 +28,11 @@ namespace NadekoBot.Common.TypeReaders } } - public class ModuleOrCrTypeReader : TypeReader + public class ModuleOrCrTypeReader : NadekoTypeReader { private readonly CommandService _cmds; - public ModuleOrCrTypeReader(CommandService cmds) + public ModuleOrCrTypeReader(DiscordSocketClient client, CommandService cmds) : base(client, cmds) { _cmds = cmds; } diff --git a/NadekoBot.Core/Common/TypeReaders/NadekoTypeReader.cs b/NadekoBot.Core/Common/TypeReaders/NadekoTypeReader.cs new file mode 100644 index 00000000..b952f3b6 --- /dev/null +++ b/NadekoBot.Core/Common/TypeReaders/NadekoTypeReader.cs @@ -0,0 +1,18 @@ +using Discord.Commands; +using Discord.WebSocket; + +namespace NadekoBot.Core.Common.TypeReaders +{ + public abstract class NadekoTypeReader : TypeReader + { + private readonly DiscordSocketClient _client; + private readonly CommandService _cmds; + + private NadekoTypeReader() { } + public NadekoTypeReader(DiscordSocketClient client, CommandService cmds) + { + _client = client; + _cmds = cmds; + } + } +} diff --git a/NadekoBot.Core/Common/TypeReaders/PermissionActionTypeReader.cs b/NadekoBot.Core/Common/TypeReaders/PermissionActionTypeReader.cs index 82e16e16..b15dbf3e 100644 --- a/NadekoBot.Core/Common/TypeReaders/PermissionActionTypeReader.cs +++ b/NadekoBot.Core/Common/TypeReaders/PermissionActionTypeReader.cs @@ -1,15 +1,21 @@ using System; using System.Threading.Tasks; using Discord.Commands; +using Discord.WebSocket; using NadekoBot.Common.TypeReaders.Models; +using NadekoBot.Core.Common.TypeReaders; namespace NadekoBot.Common.TypeReaders { /// /// Used instead of bool for more flexible keywords for true/false only in the permission module /// - public class PermissionActionTypeReader : TypeReader + public class PermissionActionTypeReader : NadekoTypeReader { + public PermissionActionTypeReader(DiscordSocketClient client, CommandService cmds) : base(client, cmds) + { + } + public override Task Read(ICommandContext context, string input, IServiceProvider _) { input = input.ToUpperInvariant(); diff --git a/NadekoBot.Core/Services/Database/NadekoContext.cs b/NadekoBot.Core/Services/Database/NadekoContext.cs index 9b4c1e46..2d484582 100644 --- a/NadekoBot.Core/Services/Database/NadekoContext.cs +++ b/NadekoBot.Core/Services/Database/NadekoContext.cs @@ -307,8 +307,7 @@ namespace NadekoBot.Services.Database .HasOne(x => x.GuildConfig) .WithOne(x => x.XpSettings); #endregion - - //todo major bug + #region XpRoleReward modelBuilder.Entity() .HasIndex(x => new { x.XpSettingsId, x.Level }) diff --git a/NadekoBot.Core/Services/NadekoBot.cs b/NadekoBot.Core/Services/NadekoBot.cs index 171a654b..224db737 100644 --- a/NadekoBot.Core/Services/NadekoBot.cs +++ b/NadekoBot.Core/Services/NadekoBot.cs @@ -23,6 +23,7 @@ using NadekoBot.Services.Database; using StackExchange.Redis; using Newtonsoft.Json; using System.Runtime.Loader; +using NadekoBot.Core.Common.TypeReaders; namespace NadekoBot { @@ -138,6 +139,8 @@ namespace NadekoBot .AddManual(Client) .AddManual(CommandService) .AddManual(botConfigProvider) + //todo this needs to reload whenever a new service is supposed to be loaded + //except at startup for obvious reasons .AddManual>(AllGuildConfigs) //todo wrap this .AddManual(this) .AddManual(uow) @@ -147,19 +150,50 @@ namespace NadekoBot var commandHandler = Services.GetService(); commandHandler.AddServices(Services); + + LoadTypeReaders(typeof(NadekoBot).Assembly); //setup typereaders - CommandService.AddTypeReader(new PermissionActionTypeReader()); - CommandService.AddTypeReader(new CommandTypeReader()); + CommandService.AddTypeReader(new PermissionActionTypeReader(Client, CommandService)); + CommandService.AddTypeReader(new CommandTypeReader(Client, CommandService)); //todo module dependency - CommandService.AddTypeReader(new CommandOrCrTypeReader()); - CommandService.AddTypeReader(new ModuleTypeReader(CommandService)); - CommandService.AddTypeReader(new ModuleOrCrTypeReader(CommandService)); - CommandService.AddTypeReader(new GuildTypeReader(Client)); + CommandService.AddTypeReader(new CommandOrCrTypeReader(Client, CommandService)); + CommandService.AddTypeReader(new ModuleTypeReader(Client, CommandService)); + CommandService.AddTypeReader(new ModuleOrCrTypeReader(Client, CommandService)); + CommandService.AddTypeReader(new GuildTypeReader(Client, CommandService)); //CommandService.AddTypeReader(new GuildDateTimeTypeReader()); } Services.Unload(typeof(IUnitOfWork)); // unload it after the startup } + private IEnumerable LoadTypeReaders(Assembly assembly) + { + Type[] allTypes; + try + { + allTypes = assembly.GetTypes(); + } + catch (ReflectionTypeLoadException ex) + { + Console.WriteLine(ex.LoaderExceptions[0]); + return Enumerable.Empty(); + } + var filteredTypes = allTypes + .Where(x => x.IsSubclassOf(typeof(NadekoTypeReader)) + && !x.IsAbstract); + + var toReturn = new List(); + foreach (var ft in filteredTypes) + { + //:yayyy: + var x = (NadekoTypeReader)Activator.CreateInstance(ft, Client, CommandService); + CommandService.AddTypeReader(x.GetType(), x); + toReturn.Add(x); + _log.Info("Loaded {0} typereader.", x.GetType().Name); + } + + return toReturn; + } + private async Task LoginAsync(string token) { var clientReady = new TaskCompletionSource(); @@ -254,7 +288,6 @@ namespace NadekoBot Ready.TrySetResult(true); HandleStatusChanges(); _log.Info($"Shard {Client.ShardId} ready."); - //_log.Info(await stats.Print().ConfigureAwait(false)); } private Task Client_Log(LogMessage arg) @@ -400,6 +433,7 @@ namespace NadekoBot _log.Info("Unloaded {0} types.", i); } + return true; } finally @@ -426,6 +460,13 @@ namespace NadekoBot $"NadekoBot.Modules.{name}.dll")); var types = Services.LoadFrom(package); var added = await CommandService.AddModulesAsync(package).ConfigureAwait(false); + var trs = LoadTypeReaders(package); + /* i don't have to unload typereaders + * (and there's no api for it) + * because they get overwritten anyway, and since + * the only time I'd unload typereaders, is when unloading a module + * which means they won't have a chance to be used + * */ _log.Info("Loaded {0} modules and {1} types.", added.Count(), types.Count()); _packageModules.Add(name, added); _packageTypes.Add(name, types); diff --git a/NadekoBot.Modules.Gambling/NadekoBot.Modules.Gambling.csproj b/NadekoBot.Modules.Gambling/NadekoBot.Modules.Gambling.csproj index b97a40e1..e12e9894 100644 --- a/NadekoBot.Modules.Gambling/NadekoBot.Modules.Gambling.csproj +++ b/NadekoBot.Modules.Gambling/NadekoBot.Modules.Gambling.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/NadekoBot.Modules.Gambling/WaifuClaimCommands.cs b/NadekoBot.Modules.Gambling/WaifuClaimCommands.cs index 0709a5ee..875fd01c 100644 --- a/NadekoBot.Modules.Gambling/WaifuClaimCommands.cs +++ b/NadekoBot.Modules.Gambling/WaifuClaimCommands.cs @@ -44,7 +44,7 @@ namespace NadekoBot.Modules.Gambling Depraved, Harlot } - //todo unclaimed waifus should lose 5% of their value a day + //todo unclaimed waifus should lose 3% of their value a day [Group] public class WaifuClaimCommands : NadekoSubmodule { diff --git a/NadekoBot.Modules.Games/Common/Hangman/Hangman.cs b/NadekoBot.Modules.Games/Common/Hangman/Hangman.cs index c3c7f9e9..3e7be20f 100644 --- a/NadekoBot.Modules.Games/Common/Hangman/Hangman.cs +++ b/NadekoBot.Modules.Games/Common/Hangman/Hangman.cs @@ -11,6 +11,7 @@ namespace NadekoBot.Modules.Games.Common.Hangman public class Hangman : IDisposable { public string TermType { get; } + public TermPool TermPool { get; } public HangmanObject Term { get; } public string ScrambledWord => "`" + String.Concat(Term.Word.Select(c => @@ -56,10 +57,11 @@ namespace NadekoBot.Modules.Games.Common.Hangman public Task EndedTask => _endingCompletionSource.Task; - public Hangman(string type) + public Hangman(string type, TermPool tp = null) { this.TermType = type.Trim().ToLowerInvariant().ToTitleCase(); - this.Term = TermPool.GetTerm(type); + this.TermPool = tp ?? new TermPool(); + this.Term = this.TermPool.GetTerm(type); } private void AddError() diff --git a/NadekoBot.Modules.Games/Common/Hangman/TermPool.cs b/NadekoBot.Modules.Games/Common/Hangman/TermPool.cs index 58ba56c4..2cc98d15 100644 --- a/NadekoBot.Modules.Games/Common/Hangman/TermPool.cs +++ b/NadekoBot.Modules.Games/Common/Hangman/TermPool.cs @@ -5,27 +5,35 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using NLog; namespace NadekoBot.Modules.Games.Common.Hangman { public class TermPool { const string termsPath = "data/hangman3.json"; - public static IReadOnlyDictionary Data { get; } = new Dictionary(); - static TermPool() + private readonly Logger _log; + + public IReadOnlyDictionary Data { get; } = new Dictionary(); + public TermPool() { + _log = LogManager.GetCurrentClassLogger(); try { Data = JsonConvert.DeserializeObject>(File.ReadAllText(termsPath)); + Data = Data.ToDictionary( + x => x.Key.ToLowerInvariant(), + x => x.Value); } - catch (Exception) + catch (Exception ex) { - //ignored + _log.Warn(ex); } } - public static HangmanObject GetTerm(string type) + public HangmanObject GetTerm(string type) { + type = type?.Trim().ToLowerInvariant(); var rng = new NadekoRandom(); if (type == "random") diff --git a/NadekoBot.Modules.Games/HangmanCommands.cs b/NadekoBot.Modules.Games/HangmanCommands.cs index 32986d62..97340865 100644 --- a/NadekoBot.Modules.Games/HangmanCommands.cs +++ b/NadekoBot.Modules.Games/HangmanCommands.cs @@ -26,14 +26,14 @@ namespace NadekoBot.Modules.Games [RequireContext(ContextType.Guild)] public async Task Hangmanlist() { - await Context.Channel.SendConfirmAsync(Format.Code(GetText("hangman_types", Prefix)) + "\n" + string.Join("\n", TermPool.Data.Keys)); + await Context.Channel.SendConfirmAsync(Format.Code(GetText("hangman_types", Prefix)) + "\n" + string.Join("\n", _service.TermPool.Data.Keys)); } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Hangman([Remainder]string type = "random") { - var hm = new Hangman(type); + var hm = new Hangman(type, _service.TermPool); if (!_service.HangmanGames.TryAdd(Context.Channel.Id, hm)) { diff --git a/NadekoBot.Modules.Games/NadekoBot.Modules.Games.csproj b/NadekoBot.Modules.Games/NadekoBot.Modules.Games.csproj index 3cbf2e8b..8f99e6d7 100644 --- a/NadekoBot.Modules.Games/NadekoBot.Modules.Games.csproj +++ b/NadekoBot.Modules.Games/NadekoBot.Modules.Games.csproj @@ -19,4 +19,8 @@ + + + + diff --git a/NadekoBot.Modules.Games/Services/GamesService.cs b/NadekoBot.Modules.Games/Services/GamesService.cs index 61a4415c..dece8333 100644 --- a/NadekoBot.Modules.Games/Services/GamesService.cs +++ b/NadekoBot.Modules.Games/Services/GamesService.cs @@ -46,7 +46,10 @@ namespace NadekoBot.Modules.Games.Services //channelId, game public ConcurrentDictionary AcrophobiaGames { get; } = new ConcurrentDictionary(); public ConcurrentDictionary Connect4Games { get; } = new ConcurrentDictionary(); + public ConcurrentDictionary HangmanGames { get; } = new ConcurrentDictionary(); + public TermPool TermPool { get; } = new TermPool(); + public ConcurrentDictionary RunningTrivias { get; } = new ConcurrentDictionary(); public Dictionary TicTacToeGames { get; } = new Dictionary(); public ConcurrentDictionary RunningContests { get; } = new ConcurrentDictionary(); diff --git a/NadekoBot.Modules.Music/NadekoBot.Modules.Music.csproj b/NadekoBot.Modules.Music/NadekoBot.Modules.Music.csproj index eb9bb4e0..92e3c1d1 100644 --- a/NadekoBot.Modules.Music/NadekoBot.Modules.Music.csproj +++ b/NadekoBot.Modules.Music/NadekoBot.Modules.Music.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/NadekoBot.Modules.Nsfw/Exceptions/TagBlacklistedException.cs b/NadekoBot.Modules.Nsfw/Exceptions/TagBlacklistedException.cs index c0f881f3..5d4cfc92 100644 --- a/NadekoBot.Modules.Nsfw/Exceptions/TagBlacklistedException.cs +++ b/NadekoBot.Modules.Nsfw/Exceptions/TagBlacklistedException.cs @@ -2,11 +2,4 @@ namespace NadekoBot.Modules.NSFW.Exceptions { - public class TagBlacklistedException : Exception - { - public TagBlacklistedException() : base("Tag you used is blacklisted.") - { - - } - } } diff --git a/NadekoBot.Modules.Nsfw/NSFW.cs b/NadekoBot.Modules.Nsfw/NSFW.cs index 7cc4f4fc..4b16fb6c 100644 --- a/NadekoBot.Modules.Nsfw/NSFW.cs +++ b/NadekoBot.Modules.Nsfw/NSFW.cs @@ -12,6 +12,7 @@ using NadekoBot.Common.Collections; using NadekoBot.Modules.Searches.Common; using NadekoBot.Modules.Searches.Services; using NadekoBot.Modules.NSFW.Exceptions; +using NadekoBot.Modules.Searches.Exceptions; namespace NadekoBot.Modules.NSFW { @@ -85,7 +86,7 @@ namespace NadekoBot.Modules.NSFW if (interval == 0) { - if (!_autoHentaiTimers.TryRemove(Context.Channel.Id, out t)) return; + if (!_service.AutoHentaiTimers.TryRemove(Context.Channel.Id, out t)) return; t.Change(Timeout.Infinite, Timeout.Infinite); //proper way to disable the timer await ReplyConfirmLocalized("stopped").ConfigureAwait(false); @@ -112,7 +113,7 @@ namespace NadekoBot.Modules.NSFW } }, null, interval * 1000, interval * 1000); - _autoHentaiTimers.AddOrUpdate(Context.Channel.Id, t, (key, old) => + _service.AutoHentaiTimers.AddOrUpdate(Context.Channel.Id, t, (key, old) => { old.Change(Timeout.Infinite, Timeout.Infinite); return t; @@ -131,7 +132,7 @@ namespace NadekoBot.Modules.NSFW if (interval == 0) { - if (!_autoBoobTimers.TryRemove(Context.Channel.Id, out t)) return; + if (!_service.AutoBoobTimers.TryRemove(Context.Channel.Id, out t)) return; t.Change(Timeout.Infinite, Timeout.Infinite); //proper way to disable the timer await ReplyConfirmLocalized("stopped").ConfigureAwait(false); @@ -153,7 +154,7 @@ namespace NadekoBot.Modules.NSFW } }, null, interval * 1000, interval * 1000); - _autoBoobTimers.AddOrUpdate(Context.Channel.Id, t, (key, old) => + _service.AutoBoobTimers.AddOrUpdate(Context.Channel.Id, t, (key, old) => { old.Change(Timeout.Infinite, Timeout.Infinite); return t; @@ -170,7 +171,7 @@ namespace NadekoBot.Modules.NSFW if (interval == 0) { - if (!_autoButtTimers.TryRemove(Context.Channel.Id, out t)) return; + if (!_service.AutoButtTimers.TryRemove(Context.Channel.Id, out t)) return; t.Change(Timeout.Infinite, Timeout.Infinite); //proper way to disable the timer await ReplyConfirmLocalized("stopped").ConfigureAwait(false); @@ -192,7 +193,7 @@ namespace NadekoBot.Modules.NSFW } }, null, interval * 1000, interval * 1000); - _autoButtTimers.AddOrUpdate(Context.Channel.Id, t, (key, old) => + _service.AutoButtTimers.AddOrUpdate(Context.Channel.Id, t, (key, old) => { old.Change(Timeout.Infinite, Timeout.Infinite); return t; diff --git a/NadekoBot.Modules.Nsfw/NadekoBot.Modules.Nsfw.csproj b/NadekoBot.Modules.Nsfw/NadekoBot.Modules.Nsfw.csproj index d8b31304..2ba0001c 100644 --- a/NadekoBot.Modules.Nsfw/NadekoBot.Modules.Nsfw.csproj +++ b/NadekoBot.Modules.Nsfw/NadekoBot.Modules.Nsfw.csproj @@ -17,7 +17,11 @@ - + + + + + diff --git a/NadekoBot.Modules.Pokemon/NadekoBot.Modules.Pokemon.csproj b/NadekoBot.Modules.Pokemon/NadekoBot.Modules.Pokemon.csproj index b97a40e1..e12e9894 100644 --- a/NadekoBot.Modules.Pokemon/NadekoBot.Modules.Pokemon.csproj +++ b/NadekoBot.Modules.Pokemon/NadekoBot.Modules.Pokemon.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/NadekoBot.Module.Searches/AnimeSearchCommands.cs b/NadekoBot.Modules.Searches/AnimeSearchCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/AnimeSearchCommands.cs rename to NadekoBot.Modules.Searches/AnimeSearchCommands.cs diff --git a/NadekoBot.Module.Searches/Common/AnimeResult.cs b/NadekoBot.Modules.Searches/Common/AnimeResult.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/AnimeResult.cs rename to NadekoBot.Modules.Searches/Common/AnimeResult.cs diff --git a/NadekoBot.Module.Searches/Common/DefineModel.cs b/NadekoBot.Modules.Searches/Common/DefineModel.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/DefineModel.cs rename to NadekoBot.Modules.Searches/Common/DefineModel.cs diff --git a/NadekoBot.Module.Searches/Common/Exceptions/StreamNotFoundException.cs b/NadekoBot.Modules.Searches/Common/Exceptions/StreamNotFoundException.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/Exceptions/StreamNotFoundException.cs rename to NadekoBot.Modules.Searches/Common/Exceptions/StreamNotFoundException.cs diff --git a/NadekoBot.Module.Searches/Common/GoogleSearchResult.cs b/NadekoBot.Modules.Searches/Common/GoogleSearchResult.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/GoogleSearchResult.cs rename to NadekoBot.Modules.Searches/Common/GoogleSearchResult.cs diff --git a/NadekoBot.Module.Searches/Common/MagicItem.cs b/NadekoBot.Modules.Searches/Common/MagicItem.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/MagicItem.cs rename to NadekoBot.Modules.Searches/Common/MagicItem.cs diff --git a/NadekoBot.Module.Searches/Common/MangaResult.cs b/NadekoBot.Modules.Searches/Common/MangaResult.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/MangaResult.cs rename to NadekoBot.Modules.Searches/Common/MangaResult.cs diff --git a/NadekoBot.Module.Searches/Common/OmdbProvider.cs b/NadekoBot.Modules.Searches/Common/OmdbProvider.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/OmdbProvider.cs rename to NadekoBot.Modules.Searches/Common/OmdbProvider.cs diff --git a/NadekoBot.Module.Searches/Common/OverwatchApiModel.cs b/NadekoBot.Modules.Searches/Common/OverwatchApiModel.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/OverwatchApiModel.cs rename to NadekoBot.Modules.Searches/Common/OverwatchApiModel.cs diff --git a/NadekoBot.Module.Searches/Common/SearchImageCacher.cs b/NadekoBot.Modules.Searches/Common/SearchImageCacher.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/SearchImageCacher.cs rename to NadekoBot.Modules.Searches/Common/SearchImageCacher.cs diff --git a/NadekoBot.Module.Searches/Common/SearchPokemon.cs b/NadekoBot.Modules.Searches/Common/SearchPokemon.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/SearchPokemon.cs rename to NadekoBot.Modules.Searches/Common/SearchPokemon.cs diff --git a/NadekoBot.Module.Searches/Common/StreamResponses.cs b/NadekoBot.Modules.Searches/Common/StreamResponses.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/StreamResponses.cs rename to NadekoBot.Modules.Searches/Common/StreamResponses.cs diff --git a/NadekoBot.Module.Searches/Common/TimeModels.cs b/NadekoBot.Modules.Searches/Common/TimeModels.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/TimeModels.cs rename to NadekoBot.Modules.Searches/Common/TimeModels.cs diff --git a/NadekoBot.Module.Searches/Common/WeatherModels.cs b/NadekoBot.Modules.Searches/Common/WeatherModels.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/WeatherModels.cs rename to NadekoBot.Modules.Searches/Common/WeatherModels.cs diff --git a/NadekoBot.Module.Searches/Common/WikipediaApiModel.cs b/NadekoBot.Modules.Searches/Common/WikipediaApiModel.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/WikipediaApiModel.cs rename to NadekoBot.Modules.Searches/Common/WikipediaApiModel.cs diff --git a/NadekoBot.Module.Searches/Common/WoWJoke.cs b/NadekoBot.Modules.Searches/Common/WoWJoke.cs similarity index 100% rename from NadekoBot.Module.Searches/Common/WoWJoke.cs rename to NadekoBot.Modules.Searches/Common/WoWJoke.cs diff --git a/NadekoBot.Modules.Searches/Exceptions/TagBlacklistedException.cs b/NadekoBot.Modules.Searches/Exceptions/TagBlacklistedException.cs new file mode 100644 index 00000000..68091853 --- /dev/null +++ b/NadekoBot.Modules.Searches/Exceptions/TagBlacklistedException.cs @@ -0,0 +1,12 @@ +using System; + +namespace NadekoBot.Modules.Searches.Exceptions +{ + public class TagBlacklistedException : Exception + { + public TagBlacklistedException() : base("Tag you used is blacklisted.") + { + + } + } +} diff --git a/NadekoBot.Module.Searches/FeedCommands.cs b/NadekoBot.Modules.Searches/FeedCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/FeedCommands.cs rename to NadekoBot.Modules.Searches/FeedCommands.cs diff --git a/NadekoBot.Module.Searches/JokeCommands.cs b/NadekoBot.Modules.Searches/JokeCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/JokeCommands.cs rename to NadekoBot.Modules.Searches/JokeCommands.cs diff --git a/NadekoBot.Module.Searches/LoLCommands.cs b/NadekoBot.Modules.Searches/LoLCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/LoLCommands.cs rename to NadekoBot.Modules.Searches/LoLCommands.cs diff --git a/NadekoBot.Module.Searches/MemegenCommands.cs b/NadekoBot.Modules.Searches/MemegenCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/MemegenCommands.cs rename to NadekoBot.Modules.Searches/MemegenCommands.cs diff --git a/NadekoBot.Module.Searches/NadekoBot.Modules.Searches.csproj b/NadekoBot.Modules.Searches/NadekoBot.Modules.Searches.csproj similarity index 100% rename from NadekoBot.Module.Searches/NadekoBot.Modules.Searches.csproj rename to NadekoBot.Modules.Searches/NadekoBot.Modules.Searches.csproj diff --git a/NadekoBot.Module.Searches/OsuCommands.cs b/NadekoBot.Modules.Searches/OsuCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/OsuCommands.cs rename to NadekoBot.Modules.Searches/OsuCommands.cs diff --git a/NadekoBot.Module.Searches/OverwatchCommands.cs b/NadekoBot.Modules.Searches/OverwatchCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/OverwatchCommands.cs rename to NadekoBot.Modules.Searches/OverwatchCommands.cs diff --git a/NadekoBot.Module.Searches/PlaceCommands.cs b/NadekoBot.Modules.Searches/PlaceCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/PlaceCommands.cs rename to NadekoBot.Modules.Searches/PlaceCommands.cs diff --git a/NadekoBot.Module.Searches/PokemonSearchCommands.cs b/NadekoBot.Modules.Searches/PokemonSearchCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/PokemonSearchCommands.cs rename to NadekoBot.Modules.Searches/PokemonSearchCommands.cs diff --git a/NadekoBot.Module.Searches/Searches.cs b/NadekoBot.Modules.Searches/Searches.cs similarity index 100% rename from NadekoBot.Module.Searches/Searches.cs rename to NadekoBot.Modules.Searches/Searches.cs diff --git a/NadekoBot.Module.Searches/Services/AnimeSearchService.cs b/NadekoBot.Modules.Searches/Services/AnimeSearchService.cs similarity index 100% rename from NadekoBot.Module.Searches/Services/AnimeSearchService.cs rename to NadekoBot.Modules.Searches/Services/AnimeSearchService.cs diff --git a/NadekoBot.Module.Searches/Services/FeedsService.cs b/NadekoBot.Modules.Searches/Services/FeedsService.cs similarity index 100% rename from NadekoBot.Module.Searches/Services/FeedsService.cs rename to NadekoBot.Modules.Searches/Services/FeedsService.cs diff --git a/NadekoBot.Module.Searches/Services/SearchesService.cs b/NadekoBot.Modules.Searches/Services/SearchesService.cs similarity index 91% rename from NadekoBot.Module.Searches/Services/SearchesService.cs rename to NadekoBot.Modules.Searches/Services/SearchesService.cs index ba9e14cc..61114bd1 100644 --- a/NadekoBot.Module.Searches/Services/SearchesService.cs +++ b/NadekoBot.Modules.Searches/Services/SearchesService.cs @@ -17,6 +17,7 @@ using System.Net.Http; using Newtonsoft.Json.Linq; using AngleSharp; using System.Threading; +using NadekoBot.Modules.Searches.Exceptions; namespace NadekoBot.Modules.Searches.Services { @@ -43,9 +44,9 @@ namespace NadekoBot.Modules.Searches.Services private readonly ConcurrentDictionary _imageCacher = new ConcurrentDictionary(); //todo clear when module unloaded - public ConcurrentDictionary _autoHentaiTimers { get; } = new ConcurrentDictionary(); - public ConcurrentDictionary _autoBoobTimers { get; } = new ConcurrentDictionary(); - public ConcurrentDictionary _autoButtTimers { get; } = new ConcurrentDictionary(); + public ConcurrentDictionary AutoHentaiTimers { get; } = new ConcurrentDictionary(); + public ConcurrentDictionary AutoBoobTimers { get; } = new ConcurrentDictionary(); + public ConcurrentDictionary AutoButtTimers { get; } = new ConcurrentDictionary(); private readonly ConcurrentDictionary> _blacklistedTags = new ConcurrentDictionary>(); @@ -147,8 +148,7 @@ namespace NadekoBot.Modules.Searches.Services if (blacklistedTags .Any(x => tag.ToLowerInvariant().Contains(x))) { - //todo tag blacklisted - throw new Exception(); + throw new TagBlacklistedException(); } var cacher = _imageCacher.GetOrAdd(guild.Value, (key) => new SearchImageCacher()); @@ -231,12 +231,12 @@ namespace NadekoBot.Modules.Searches.Services public Task Unload() { - _autoBoobTimers.ForEach(x => x.Value.Change(Timeout.Infinite, Timeout.Infinite)); - _autoBoobTimers.Clear(); - _autoButtTimers.ForEach(x => x.Value.Change(Timeout.Infinite, Timeout.Infinite)); - _autoButtTimers.Clear(); - _autoHentaiTimers.ForEach(x => x.Value.Change(Timeout.Infinite, Timeout.Infinite)); - _autoHentaiTimers.Clear(); + AutoBoobTimers.ForEach(x => x.Value.Change(Timeout.Infinite, Timeout.Infinite)); + AutoBoobTimers.Clear(); + AutoButtTimers.ForEach(x => x.Value.Change(Timeout.Infinite, Timeout.Infinite)); + AutoButtTimers.Clear(); + AutoHentaiTimers.ForEach(x => x.Value.Change(Timeout.Infinite, Timeout.Infinite)); + AutoHentaiTimers.Clear(); _imageCacher.Clear(); return Task.CompletedTask; diff --git a/NadekoBot.Module.Searches/Services/StreamNotificationService.cs b/NadekoBot.Modules.Searches/Services/StreamNotificationService.cs similarity index 100% rename from NadekoBot.Module.Searches/Services/StreamNotificationService.cs rename to NadekoBot.Modules.Searches/Services/StreamNotificationService.cs diff --git a/NadekoBot.Module.Searches/StreamNotificationCommands.cs b/NadekoBot.Modules.Searches/StreamNotificationCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/StreamNotificationCommands.cs rename to NadekoBot.Modules.Searches/StreamNotificationCommands.cs diff --git a/NadekoBot.Module.Searches/TranslatorCommands.cs b/NadekoBot.Modules.Searches/TranslatorCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/TranslatorCommands.cs rename to NadekoBot.Modules.Searches/TranslatorCommands.cs diff --git a/NadekoBot.Module.Searches/XkcdCommands.cs b/NadekoBot.Modules.Searches/XkcdCommands.cs similarity index 100% rename from NadekoBot.Module.Searches/XkcdCommands.cs rename to NadekoBot.Modules.Searches/XkcdCommands.cs diff --git a/NadekoBot.Modules.Utility/NadekoBot.Modules.Searches.csproj b/NadekoBot.Modules.Utility/NadekoBot.Modules.Searches.csproj new file mode 100644 index 00000000..0ec5a3a3 --- /dev/null +++ b/NadekoBot.Modules.Utility/NadekoBot.Modules.Searches.csproj @@ -0,0 +1,23 @@ + + + + netcoreapp2.0 + latest + + + + ..\src\NadekoBot\bin\$(Configuration)\netcoreapp2.0\modules\$(AssemblyName)\ + false + false + + + + + + + + + + + + diff --git a/NadekoBot.Modules.Utility/NadekoBot.Modules.Utility.csproj b/NadekoBot.Modules.Utility/NadekoBot.Modules.Utility.csproj index af75a27c..63b44250 100644 --- a/NadekoBot.Modules.Utility/NadekoBot.Modules.Utility.csproj +++ b/NadekoBot.Modules.Utility/NadekoBot.Modules.Utility.csproj @@ -20,4 +20,12 @@ + + + + + + + + diff --git a/NadekoBot.Modules.Utility/RepeatCommands.cs b/NadekoBot.Modules.Utility/RepeatCommands.cs index 2d60b9dd..921c0746 100644 --- a/NadekoBot.Modules.Utility/RepeatCommands.cs +++ b/NadekoBot.Modules.Utility/RepeatCommands.cs @@ -147,59 +147,57 @@ namespace NadekoBot.Modules.Utility Format.Bold(rep.Repeater.Interval.Minutes.ToString()))).ConfigureAwait(false); } - //todo guild date time + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequireUserPermission(GuildPermission.ManageMessages)] + [Priority(1)] + public async Task Repeat(GuildDateTime gt, [Remainder] string message) + { + if (!_service.RepeaterReady) + return; - //[NadekoCommand, Usage, Description, Aliases] - //[RequireContext(ContextType.Guild)] - //[RequireUserPermission(GuildPermission.ManageMessages)] - //[Priority(1)] - //public async Task Repeat(GuildDateTime gt, [Remainder] string message) - //{ - // if (!_service.RepeaterReady) - // return; + if (string.IsNullOrWhiteSpace(message)) + return; - // if (string.IsNullOrWhiteSpace(message)) - // return; + var toAdd = new GuildRepeater() + { + ChannelId = Context.Channel.Id, + GuildId = Context.Guild.Id, + Interval = TimeSpan.FromHours(24), + StartTimeOfDay = gt.InputTimeUtc.TimeOfDay, + Message = message + }; - // var toAdd = new GuildRepeater() - // { - // ChannelId = Context.Channel.Id, - // GuildId = Context.Guild.Id, - // Interval = TimeSpan.FromHours(24), - // StartTimeOfDay = gt.InputTimeUtc.TimeOfDay, - // Message = message - // }; + using (var uow = _db.UnitOfWork) + { + var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.GuildRepeaters)); - // using (var uow = _db.UnitOfWork) - // { - // var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.GuildRepeaters)); + if (gc.GuildRepeaters.Count >= 5) + return; + gc.GuildRepeaters.Add(toAdd); - // if (gc.GuildRepeaters.Count >= 5) - // return; - // gc.GuildRepeaters.Add(toAdd); + await uow.CompleteAsync().ConfigureAwait(false); + } - // await uow.CompleteAsync().ConfigureAwait(false); - // } + var rep = new RepeatRunner(_client, (SocketGuild)Context.Guild, toAdd); - // var rep = new RepeatRunner(_client, (SocketGuild)Context.Guild, toAdd); + _service.Repeaters.AddOrUpdate(Context.Guild.Id, new ConcurrentQueue(new[] { rep }), (key, old) => + { + old.Enqueue(rep); + return old; + }); - // _service.Repeaters.AddOrUpdate(Context.Guild.Id, new ConcurrentQueue(new[] { rep }), (key, old) => - // { - // old.Enqueue(rep); - // return old; - // }); + var secondPart = GetText("repeater_initial", + Format.Bold(rep.InitialInterval.Hours.ToString()), + Format.Bold(rep.InitialInterval.Minutes.ToString())); - // var secondPart = GetText("repeater_initial", - // Format.Bold(rep.InitialInterval.Hours.ToString()), - // Format.Bold(rep.InitialInterval.Minutes.ToString())); - - // await Context.Channel.SendConfirmAsync( - // "🔁 " + GetText("repeater", - // Format.Bold(((IGuildUser)Context.User).GuildPermissions.MentionEveryone ? rep.Repeater.Message : rep.Repeater.Message.SanitizeMentions()), - // Format.Bold(rep.Repeater.Interval.Days.ToString()), - // Format.Bold(rep.Repeater.Interval.Hours.ToString()), - // Format.Bold(rep.Repeater.Interval.Minutes.ToString())) + " " + secondPart).ConfigureAwait(false); - //} + await Context.Channel.SendConfirmAsync( + "🔁 " + GetText("repeater", + Format.Bold(((IGuildUser)Context.User).GuildPermissions.MentionEveryone ? rep.Repeater.Message : rep.Repeater.Message.SanitizeMentions()), + Format.Bold(rep.Repeater.Interval.Days.ToString()), + Format.Bold(rep.Repeater.Interval.Hours.ToString()), + Format.Bold(rep.Repeater.Interval.Minutes.ToString())) + " " + secondPart).ConfigureAwait(false); + } [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] diff --git a/NadekoBot.Modules.Xp/NadekoBot.Modules.Xp.csproj b/NadekoBot.Modules.Xp/NadekoBot.Modules.Xp.csproj index f00a0053..a07d2b7c 100644 --- a/NadekoBot.Modules.Xp/NadekoBot.Modules.Xp.csproj +++ b/NadekoBot.Modules.Xp/NadekoBot.Modules.Xp.csproj @@ -19,4 +19,8 @@ + + + + diff --git a/NadekoBot.sln b/NadekoBot.sln index dbdacba9..ccfd0ee1 100644 --- a/NadekoBot.sln +++ b/NadekoBot.sln @@ -19,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NadekoBot.Modules.Xp", "Nad EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NadekoBot.Modules.Utility", "NadekoBot.Modules.Utility\NadekoBot.Modules.Utility.csproj", "{07606931-CB55-4D20-8369-4E086B00EC52}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NadekoBot.Modules.Searches", "NadekoBot.Module.Searches\NadekoBot.Modules.Searches.csproj", "{8BEE9984-3EB3-45BE-A5CF-0DB912626B81}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NadekoBot.Modules.Nsfw", "NadekoBot.Modules.Nsfw\NadekoBot.Modules.Nsfw.csproj", "{75ED72EC-7AB3-4B12-A2DA-3655C740B356}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NadekoBot.Modules.Games", "NadekoBot.Modules.Games\NadekoBot.Modules.Games.csproj", "{FF6BDE61-24B4-4DC2-99EE-409EA1650180}" @@ -31,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NadekoBot.Modules.Pokemon", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NadekoBot.Modules.Music", "NadekoBot.Modules.Music\NadekoBot.Modules.Music.csproj", "{674E28A6-30B1-413D-BBD3-E5F71614A00F}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NadekoBot.Modules.Searches", "NadekoBot.Modules.Searches\NadekoBot.Modules.Searches.csproj", "{ED6DCB6E-66BE-45F4-A1D6-67FE01BCACD9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -62,12 +62,6 @@ Global {07606931-CB55-4D20-8369-4E086B00EC52}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU {07606931-CB55-4D20-8369-4E086B00EC52}.Release|Any CPU.ActiveCfg = Release|Any CPU {07606931-CB55-4D20-8369-4E086B00EC52}.Release|Any CPU.Build.0 = Release|Any CPU - {8BEE9984-3EB3-45BE-A5CF-0DB912626B81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8BEE9984-3EB3-45BE-A5CF-0DB912626B81}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8BEE9984-3EB3-45BE-A5CF-0DB912626B81}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU - {8BEE9984-3EB3-45BE-A5CF-0DB912626B81}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU - {8BEE9984-3EB3-45BE-A5CF-0DB912626B81}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8BEE9984-3EB3-45BE-A5CF-0DB912626B81}.Release|Any CPU.Build.0 = Release|Any CPU {75ED72EC-7AB3-4B12-A2DA-3655C740B356}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {75ED72EC-7AB3-4B12-A2DA-3655C740B356}.Debug|Any CPU.Build.0 = Debug|Any CPU {75ED72EC-7AB3-4B12-A2DA-3655C740B356}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU @@ -98,6 +92,12 @@ Global {674E28A6-30B1-413D-BBD3-E5F71614A00F}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU {674E28A6-30B1-413D-BBD3-E5F71614A00F}.Release|Any CPU.ActiveCfg = Release|Any CPU {674E28A6-30B1-413D-BBD3-E5F71614A00F}.Release|Any CPU.Build.0 = Release|Any CPU + {ED6DCB6E-66BE-45F4-A1D6-67FE01BCACD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ED6DCB6E-66BE-45F4-A1D6-67FE01BCACD9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ED6DCB6E-66BE-45F4-A1D6-67FE01BCACD9}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU + {ED6DCB6E-66BE-45F4-A1D6-67FE01BCACD9}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU + {ED6DCB6E-66BE-45F4-A1D6-67FE01BCACD9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ED6DCB6E-66BE-45F4-A1D6-67FE01BCACD9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -107,12 +107,12 @@ Global {A6CCEFBD-DCF2-482C-9643-47664683548F} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} {41A2DEBA-E8AE-4EC8-A58F-01C4B6E599E5} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} {07606931-CB55-4D20-8369-4E086B00EC52} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} - {8BEE9984-3EB3-45BE-A5CF-0DB912626B81} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} {75ED72EC-7AB3-4B12-A2DA-3655C740B356} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} {FF6BDE61-24B4-4DC2-99EE-409EA1650180} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} {6436A700-694E-412C-92AE-B793FCD44E84} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} {30463C26-555B-4760-9459-A16DFA015DFA} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} {674E28A6-30B1-413D-BBD3-E5F71614A00F} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} + {ED6DCB6E-66BE-45F4-A1D6-67FE01BCACD9} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5F3F555C-855F-4BE8-B526-D062D3E8ACA4} diff --git a/watchbuildall.ps1 b/watchbuildall.ps1 new file mode 100644 index 00000000..80ea23e5 --- /dev/null +++ b/watchbuildall.ps1 @@ -0,0 +1,20 @@ +$cur = (Get-Item -Path ".\" -Verbose).FullName + +function WatchBuild([string] $path, [string] $args) +{ + cd $cur + cd $path + cmd.exe /c "dotnet watch" + cd $cur +} + + +WatchBuild(".\NadekoBot.Modules.CustomReactions") +WatchBuild(".\NadekoBot.Modules.Gambling") +WatchBuild(".\NadekoBot.Modules.Games") +WatchBuild(".\NadekoBot.Modules.Music") +WatchBuild(".\NadekoBot.Modules.Nsfw") +WatchBuild(".\NadekoBot.Modules.Pokemon") +WatchBuild(".\NadekoBot.Modules.Searches") +WatchBuild(".\NadekoBot.Modules.Utility") +WatchBuild(".\NadekoBot.Modules.Xp")