From a1e25f5149161497b5a2f0f5d2286a759fc5a1eb Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 13 Feb 2017 11:12:13 +0100 Subject: [PATCH] Cleanup, now compiles! :O --- .../{DiscordModule.cs => NadekoModule.cs} | 57 +++++++++---------- .../Modules/NadekoModuleExtensions.cs | 15 +++++ src/NadekoBot/Modules/Pokemon/Pokemon.cs | 6 +- .../Resources/ResponseStrings.Designer.cs | 18 ++++++ src/NadekoBot/Resources/ResponseStrings.resx | 6 ++ src/NadekoBot/Services/CommandHandler.cs | 2 +- src/NadekoBot/Services/Impl/Localization.cs | 6 ++ 7 files changed, 76 insertions(+), 34 deletions(-) rename src/NadekoBot/Modules/{DiscordModule.cs => NadekoModule.cs} (59%) create mode 100644 src/NadekoBot/Modules/NadekoModuleExtensions.cs diff --git a/src/NadekoBot/Modules/DiscordModule.cs b/src/NadekoBot/Modules/NadekoModule.cs similarity index 59% rename from src/NadekoBot/Modules/DiscordModule.cs rename to src/NadekoBot/Modules/NadekoModule.cs index cc609a58..b5541b78 100644 --- a/src/NadekoBot/Modules/DiscordModule.cs +++ b/src/NadekoBot/Modules/NadekoModule.cs @@ -27,43 +27,38 @@ namespace NadekoBot.Modules ? CultureInfo.CurrentCulture : NadekoBot.Localization.GetCultureInfo(Context.Guild)); } + + public Task ConfirmLocalized(string titleKey, string textKey, string url = null, string footer = null) + { + var title = NadekoBot.ResponsesResourceManager.GetString(titleKey, cultureInfo); + var text = NadekoBot.ResponsesResourceManager.GetString(textKey, cultureInfo); + return Context.Channel.SendConfirmAsync(title, text, url, footer); + } + + public Task ConfirmLocalized(string textKey) + { + var text = NadekoBot.ResponsesResourceManager.GetString(textKey, cultureInfo); + return Context.Channel.SendConfirmAsync(textKey); + } + + public Task ErrorLocalized(string titleKey, string textKey, string url = null, string footer = null) + { + var title = NadekoBot.ResponsesResourceManager.GetString(titleKey, cultureInfo); + var text = NadekoBot.ResponsesResourceManager.GetString(textKey, cultureInfo); + return Context.Channel.SendErrorAsync(title, text, url, footer); + } + + public Task ErrorLocalized(string textKey) + { + var text = NadekoBot.ResponsesResourceManager.GetString(textKey, cultureInfo); + return Context.Channel.SendErrorAsync(textKey); + } } public abstract class NadekoSubmodule : NadekoModule { public NadekoSubmodule() : base(false) { - - } - } - - - public static class ModuleBaseExtensions - { - public static Task ConfirmLocalized(this NadekoModule module, string titleKey, string textKey, string url = null, string footer = null) - { - var title = NadekoBot.ResponsesResourceManager.GetString(titleKey, module.cultureInfo); - var text = NadekoBot.ResponsesResourceManager.GetString(textKey, module.cultureInfo); - return module.Context.Channel.SendConfirmAsync(title, text, url, footer); - } - - public static Task ConfirmLocalized(this NadekoModule module, string textKey) - { - var text = NadekoBot.ResponsesResourceManager.GetString(textKey, module.cultureInfo); - return module.Context.Channel.SendConfirmAsync(textKey); - } - - public static Task ErrorLocalized(this NadekoModule module, string titleKey, string textKey, string url = null, string footer = null) - { - var title = NadekoBot.ResponsesResourceManager.GetString(titleKey, module.cultureInfo); - var text = NadekoBot.ResponsesResourceManager.GetString(textKey, module.cultureInfo); - return module.Context.Channel.SendErrorAsync(title, text, url, footer); - } - - public static Task ErrorLocalized(this NadekoModule module, string textKey) - { - var text = NadekoBot.ResponsesResourceManager.GetString(textKey, module.cultureInfo); - return module.Context.Channel.SendErrorAsync(textKey); } } } diff --git a/src/NadekoBot/Modules/NadekoModuleExtensions.cs b/src/NadekoBot/Modules/NadekoModuleExtensions.cs new file mode 100644 index 00000000..09625409 --- /dev/null +++ b/src/NadekoBot/Modules/NadekoModuleExtensions.cs @@ -0,0 +1,15 @@ +using Discord; +using NadekoBot.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.Modules +{ + public static class NadekoModuleExtensions + { + + } +} diff --git a/src/NadekoBot/Modules/Pokemon/Pokemon.cs b/src/NadekoBot/Modules/Pokemon/Pokemon.cs index 3ece509f..19515ad1 100644 --- a/src/NadekoBot/Modules/Pokemon/Pokemon.cs +++ b/src/NadekoBot/Modules/Pokemon/Pokemon.cs @@ -12,6 +12,8 @@ using System; using Newtonsoft.Json; using System.IO; using System.Collections.Concurrent; +using NadekoBot.Modules; +using NadekoBot.Resources; namespace NadekoBot.Modules.Pokemon { @@ -105,12 +107,12 @@ namespace NadekoBot.Modules.Pokemon if (targetUser == null) { - await ReplyLocalized("no user found").ConfigureAwait(false); + await ErrorLocalized(nameof(ResponseStrings.Culture)).ConfigureAwait(false); return; } else if (targetUser == user) { - await Context.Channel.SendMessageAsync("You can't attack yourself.").ConfigureAwait(false); + await ErrorLocalized("You can't attack yourself.").ConfigureAwait(false); return; } diff --git a/src/NadekoBot/Resources/ResponseStrings.Designer.cs b/src/NadekoBot/Resources/ResponseStrings.Designer.cs index 72395491..5b93ef8c 100644 --- a/src/NadekoBot/Resources/ResponseStrings.Designer.cs +++ b/src/NadekoBot/Resources/ResponseStrings.Designer.cs @@ -58,5 +58,23 @@ namespace NadekoBot.Resources { resourceCulture = value; } } + + /// + /// Looks up a localized string similar to You can't attack yourself.. + /// + public static string cant_attack_yourself { + get { + return ResourceManager.GetString("cant_attack_yourself", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to User not found.. + /// + public static string no_user_found { + get { + return ResourceManager.GetString("no_user_found", resourceCulture); + } + } } } diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index 1af7de15..e740045d 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -117,4 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + You can't attack yourself. + + + User not found. + \ No newline at end of file diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index ac0a5b80..ce17de09 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -73,7 +73,7 @@ namespace NadekoBot.Services if (!ownerChannels.Any()) _log.Warn("No owner channels created! Make sure you've specified correct OwnerId in the credentials.json file."); else - _log.Info($"Created {ownerChannels.Count} out of {NadekoBot.Credentials.OwnerIds.Length} owner message channels."); + _log.Info($"Created {ownerChannels.Count} out of {NadekoBot.Credentials.OwnerIds.Count} owner message channels."); _client.MessageReceived += MessageReceivedHandler; } diff --git a/src/NadekoBot/Services/Impl/Localization.cs b/src/NadekoBot/Services/Impl/Localization.cs index 7a29c233..dc64dd3e 100644 --- a/src/NadekoBot/Services/Impl/Localization.cs +++ b/src/NadekoBot/Services/Impl/Localization.cs @@ -88,5 +88,11 @@ namespace NadekoBot.Services GuildCultureInfos.TryGetValue(guildId, out info); return info ?? DefaultCultureInfo; } + + public static string LoadCommandString(string key) + { + string toReturn = Resources.CommandStrings.ResourceManager.GetString(key); + return string.IsNullOrWhiteSpace(toReturn) ? key : toReturn; + } } }