2017-02-13 09:29:57 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using NadekoBot.Extensions;
|
2016-08-18 21:00:54 +00:00
|
|
|
|
using NLog;
|
2017-02-13 09:29:57 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-08-15 14:57:40 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules
|
|
|
|
|
{
|
2017-02-13 09:29:57 +00:00
|
|
|
|
public abstract class NadekoModule : ModuleBase
|
2016-08-15 14:57:40 +00:00
|
|
|
|
{
|
2017-02-13 09:29:57 +00:00
|
|
|
|
protected readonly Logger _log;
|
|
|
|
|
public readonly string _prefix;
|
|
|
|
|
public readonly CultureInfo cultureInfo;
|
2017-02-13 12:44:21 +00:00
|
|
|
|
public readonly string ModuleTypeName;
|
|
|
|
|
public readonly string LowerModuleTypeName;
|
2016-08-15 14:57:40 +00:00
|
|
|
|
|
2017-02-13 09:29:57 +00:00
|
|
|
|
public NadekoModule(bool isTopLevelModule = true)
|
2016-08-15 14:57:40 +00:00
|
|
|
|
{
|
2017-02-13 09:29:57 +00:00
|
|
|
|
//if it's top level module
|
2017-02-13 12:44:21 +00:00
|
|
|
|
ModuleTypeName = isTopLevelModule ? this.GetType().Name : this.GetType().DeclaringType.Name;
|
|
|
|
|
LowerModuleTypeName = ModuleTypeName.ToLowerInvariant();
|
|
|
|
|
|
|
|
|
|
if (!NadekoBot.ModulePrefixes.TryGetValue(ModuleTypeName, out _prefix))
|
2017-02-13 09:29:57 +00:00
|
|
|
|
_prefix = "?err?";
|
2016-08-18 21:00:54 +00:00
|
|
|
|
_log = LogManager.GetCurrentClassLogger();
|
2017-02-13 09:29:57 +00:00
|
|
|
|
|
|
|
|
|
cultureInfo = (Context.Guild == null
|
|
|
|
|
? CultureInfo.CurrentCulture
|
|
|
|
|
: NadekoBot.Localization.GetCultureInfo(Context.Guild));
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 12:24:11 +00:00
|
|
|
|
//public Task<IUserMessage> ReplyConfirmLocalized(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> ReplyConfirmLocalized(string textKey)
|
|
|
|
|
//{
|
|
|
|
|
// var text = NadekoBot.ResponsesResourceManager.GetString(textKey, cultureInfo);
|
|
|
|
|
// return Context.Channel.SendConfirmAsync(Context.User.Mention + " " + textKey);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//public Task<IUserMessage> ReplyErrorLocalized(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);
|
|
|
|
|
//}
|
|
|
|
|
|
2017-02-13 12:44:21 +00:00
|
|
|
|
protected string GetText(string key)
|
|
|
|
|
{
|
|
|
|
|
return NadekoBot.ResponsesResourceManager.GetString(LowerModuleTypeName + "_" + key, cultureInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected string GetText(string key, params object[] replacements)
|
|
|
|
|
{
|
|
|
|
|
return string.Format(GetText(key), replacements);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 12:24:11 +00:00
|
|
|
|
public Task<IUserMessage> ErrorLocalized(string textKey, params object[] replacements)
|
2017-02-13 09:29:57 +00:00
|
|
|
|
{
|
2017-02-13 12:44:21 +00:00
|
|
|
|
var text = GetText(textKey);
|
2017-02-13 12:24:11 +00:00
|
|
|
|
return Context.Channel.SendErrorAsync(string.Format(text, replacements));
|
2017-02-13 09:29:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 12:24:11 +00:00
|
|
|
|
public Task<IUserMessage> ReplyErrorLocalized(string textKey, params object[] replacements)
|
2017-02-13 09:29:57 +00:00
|
|
|
|
{
|
2017-02-13 12:44:21 +00:00
|
|
|
|
var text = GetText(textKey);
|
2017-02-13 12:24:11 +00:00
|
|
|
|
return Context.Channel.SendErrorAsync(Context.User.Mention + " " +string.Format(text, replacements));
|
2017-02-13 09:29:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 12:24:11 +00:00
|
|
|
|
public Task<IUserMessage> ConfirmLocalized(string textKey, params object[] replacements)
|
2017-02-13 09:29:57 +00:00
|
|
|
|
{
|
2017-02-13 12:44:21 +00:00
|
|
|
|
var text = GetText(textKey);
|
2017-02-13 12:24:11 +00:00
|
|
|
|
return Context.Channel.SendConfirmAsync(string.Format(text, replacements));
|
2017-02-13 09:29:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 12:24:11 +00:00
|
|
|
|
public Task<IUserMessage> ReplyConfirmLocalized(string textKey, params object[] replacements)
|
2017-02-13 09:29:57 +00:00
|
|
|
|
{
|
2017-02-13 12:44:21 +00:00
|
|
|
|
var text = GetText(textKey);
|
2017-02-13 12:24:11 +00:00
|
|
|
|
return Context.Channel.SendConfirmAsync(Context.User.Mention + " " + string.Format(text, replacements));
|
2017-02-13 09:29:57 +00:00
|
|
|
|
}
|
2017-02-13 10:12:13 +00:00
|
|
|
|
}
|
2017-02-13 09:29:57 +00:00
|
|
|
|
|
2017-02-13 10:12:13 +00:00
|
|
|
|
public abstract class NadekoSubmodule : NadekoModule
|
|
|
|
|
{
|
|
|
|
|
public NadekoSubmodule() : base(false)
|
2017-02-13 09:29:57 +00:00
|
|
|
|
{
|
2016-08-15 14:57:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|