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

View File

@ -185,6 +185,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Invalid parameters..
/// </summary>
public static string administration_invalid_params {
get {
return ResourceManager.GetString("administration_invalid_params", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} has joined {1}.
/// </summary>
@ -574,6 +583,33 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Users can&apos;t send more than {0} messages every {1} seconds..
/// </summary>
public static string administration_slowmode_desc {
get {
return ResourceManager.GetString("administration_slowmode_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Slow mode disabled..
/// </summary>
public static string administration_slowmode_disabled {
get {
return ResourceManager.GetString("administration_slowmode_disabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Slow mode initiated.
/// </summary>
public static string administration_slowmode_init {
get {
return ResourceManager.GetString("administration_slowmode_init", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to soft-banned (kicked).
/// </summary>

View File

@ -341,6 +341,9 @@
<data name="administration_fwdm_stop" xml:space="preserve">
<value>I will stop forwarding DMs from now on.</value>
</data>
<data name="administration_invalid_params" xml:space="preserve">
<value>Invalid parameters.</value>
</data>
<data name="administration_joined" xml:space="preserve">
<value>{0} has joined {1}</value>
</data>
@ -474,6 +477,15 @@
<data name="administration_ropl_not_set" xml:space="preserve">
<value>No rotating playing statuses set.</value>
</data>
<data name="administration_slowmode_desc" xml:space="preserve">
<value>Users can't send more than {0} messages every {1} seconds.</value>
</data>
<data name="administration_slowmode_disabled" xml:space="preserve">
<value>Slow mode disabled.</value>
</data>
<data name="administration_slowmode_init" xml:space="preserve">
<value>Slow mode initiated</value>
</data>
<data name="administration_soft_banned_pl" xml:space="preserve">
<value>soft-banned (kicked)</value>
<comment>PLURAL</comment>