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

View File

@ -341,6 +341,9 @@
<data name="administration_fwdm_stop" xml:space="preserve"> <data name="administration_fwdm_stop" xml:space="preserve">
<value>I will stop forwarding DMs from now on.</value> <value>I will stop forwarding DMs from now on.</value>
</data> </data>
<data name="administration_invalid_params" xml:space="preserve">
<value>Invalid parameters.</value>
</data>
<data name="administration_joined" xml:space="preserve"> <data name="administration_joined" xml:space="preserve">
<value>{0} has joined {1}</value> <value>{0} has joined {1}</value>
</data> </data>
@ -474,6 +477,15 @@
<data name="administration_ropl_not_set" xml:space="preserve"> <data name="administration_ropl_not_set" xml:space="preserve">
<value>No rotating playing statuses set.</value> <value>No rotating playing statuses set.</value>
</data> </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"> <data name="administration_soft_banned_pl" xml:space="preserve">
<value>soft-banned (kicked)</value> <value>soft-banned (kicked)</value>
<comment>PLURAL</comment> <comment>PLURAL</comment>