Cleanup, now compiles! :O

This commit is contained in:
Kwoth 2017-02-13 11:12:13 +01:00
parent db79177f0c
commit a1e25f5149
7 changed files with 76 additions and 34 deletions

View File

@ -27,43 +27,38 @@ namespace NadekoBot.Modules
? CultureInfo.CurrentCulture
: NadekoBot.Localization.GetCultureInfo(Context.Guild));
}
public Task<IUserMessage> 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<IUserMessage> ConfirmLocalized(string textKey)
{
var text = NadekoBot.ResponsesResourceManager.GetString(textKey, cultureInfo);
return Context.Channel.SendConfirmAsync(textKey);
}
public Task<IUserMessage> 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<IUserMessage> 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<IUserMessage> 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<IUserMessage> ConfirmLocalized(this NadekoModule module, string textKey)
{
var text = NadekoBot.ResponsesResourceManager.GetString(textKey, module.cultureInfo);
return module.Context.Channel.SendConfirmAsync(textKey);
}
public static Task<IUserMessage> 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<IUserMessage> ErrorLocalized(this NadekoModule module, string textKey)
{
var text = NadekoBot.ResponsesResourceManager.GetString(textKey, module.cultureInfo);
return module.Context.Channel.SendErrorAsync(textKey);
}
}
}

View File

@ -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
{
}
}

View File

@ -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;
}

View File

@ -58,5 +58,23 @@ namespace NadekoBot.Resources {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to You can&apos;t attack yourself..
/// </summary>
public static string cant_attack_yourself {
get {
return ResourceManager.GetString("cant_attack_yourself", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User not found..
/// </summary>
public static string no_user_found {
get {
return ResourceManager.GetString("no_user_found", resourceCulture);
}
}
}
}

View File

@ -117,4 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="cant_attack_yourself" xml:space="preserve">
<value>You can't attack yourself.</value>
</data>
<data name="no_user_found" xml:space="preserve">
<value>User not found.</value>
</data>
</root>

View File

@ -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;
}

View File

@ -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;
}
}
}