slowmode can now be localized

This commit is contained in:
Kwoth
2017-02-14 20:35:10 +01:00
parent bfc10ab3e2
commit 6ab8f26cd7
3 changed files with 54 additions and 9 deletions

View File

@@ -16,7 +16,7 @@ namespace NadekoBot.Modules.Administration
public class RatelimitCommand : NadekoSubmodule
{
public static ConcurrentDictionary<ulong, Ratelimiter> RatelimitingChannels = new ConcurrentDictionary<ulong, Ratelimiter>();
private static Logger _log { get; }
private new static readonly Logger _log;
public class Ratelimiter
{
@@ -65,9 +65,7 @@ namespace NadekoBot.Modules.Administration
try
{
var usrMsg = umsg as IUserMessage;
if (usrMsg == null)
return;
var channel = usrMsg.Channel as ITextChannel;
var channel = usrMsg?.Channel as ITextChannel;
if (channel == null || usrMsg.IsAuthor())
return;
@@ -91,8 +89,7 @@ namespace NadekoBot.Modules.Administration
if (RatelimitingChannels.TryRemove(Context.Channel.Id, out throwaway))
{
throwaway.cancelSource.Cancel();
await Context.Channel.SendConfirmAsync(" Slow mode disabled.").ConfigureAwait(false);
return;
await ReplyConfirmLocalized("slowmode_disabled").ConfigureAwait(false);
}
}
@@ -105,7 +102,7 @@ namespace NadekoBot.Modules.Administration
if (msg < 1 || perSec < 1 || msg > 100 || perSec > 3600)
{
await Context.Channel.SendErrorAsync("⚠️ Invalid parameters.");
await ReplyErrorLocalized("invalid_params").ConfigureAwait(false);
return;
}
var toAdd = new Ratelimiter()
@@ -116,8 +113,8 @@ namespace NadekoBot.Modules.Administration
};
if(RatelimitingChannels.TryAdd(Context.Channel.Id, toAdd))
{
await Context.Channel.SendConfirmAsync("Slow mode initiated",
$"Users can't send more than `{toAdd.MaxMessages} message(s)` every `{toAdd.PerSeconds} second(s)`.")
await Context.Channel.SendConfirmAsync(GetText("slowmode_init"),
GetText("slowmode_desc", Format.Bold(toAdd.MaxMessages.ToString()), Format.Bold(toAdd.PerSeconds.ToString())))
.ConfigureAwait(false);
}
}