Slowmode fixed, fixed description/usage, adding new one overrides old one

This commit is contained in:
Kwoth 2016-10-19 13:17:18 +02:00
parent 7d4db46fe7
commit 31bbe5ba98
3 changed files with 20 additions and 10 deletions

View File

@ -90,7 +90,7 @@ namespace NadekoBot.Modules.Administration
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequirePermission(GuildPermission.ManageMessages)] [RequirePermission(GuildPermission.ManageMessages)]
public async Task Slowmode(IUserMessage umsg, int msg = 1, int perSec = 5) public async Task Slowmode(IUserMessage umsg)
{ {
var channel = (ITextChannel)umsg.Channel; var channel = (ITextChannel)umsg.Channel;
@ -101,21 +101,31 @@ namespace NadekoBot.Modules.Administration
await channel.SendMessageAsync("`Slow mode disabled.`").ConfigureAwait(false); await channel.SendMessageAsync("`Slow mode disabled.`").ConfigureAwait(false);
return; return;
} }
}
if (msg < 1 || perSec < 1) [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequirePermission(GuildPermission.ManageMessages)]
public async Task Slowmode(IUserMessage umsg, int msg, int perSec)
{
await Slowmode(umsg).ConfigureAwait(false); // disable if exists
var channel = (ITextChannel)umsg.Channel;
if (msg < 1 || perSec < 1 || msg > 100 || perSec > 3600)
{ {
await channel.SendMessageAsync("`Invalid parameters.`"); await channel.SendMessageAsync("`Invalid parameters.`");
return; return;
} }
var toAdd = new Ratelimiter()
if (RatelimitingChannels.TryAdd(channel.Id,throwaway = new Ratelimiter() { {
ChannelId = channel.Id, ChannelId = channel.Id,
MaxMessages = msg, MaxMessages = msg,
PerSeconds = perSec, PerSeconds = perSec,
})) };
if(RatelimitingChannels.TryAdd(channel.Id, toAdd))
{ {
await channel.SendMessageAsync("`Slow mode initiated.` " + await channel.SendMessageAsync("`Slow mode initiated.` " +
$"Users can't send more than {throwaway.MaxMessages} message(s) every {throwaway.PerSeconds} second(s).") $"Users can't send more than {toAdd.MaxMessages} message(s) every {toAdd.PerSeconds} second(s).")
.ConfigureAwait(false); .ConfigureAwait(false);
} }
} }

View File

@ -6414,7 +6414,7 @@ namespace NadekoBot.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Toggles slow mode. When ON, users will be able to send only 1 message every 5 seconds. . /// Looks up a localized string similar to Toggles slowmode. Disable by specifying no parameters. To enable, specify a number of messages each user can send, and an interval in seconds. For example 1 message every 5 seconds..
/// </summary> /// </summary>
public static string slowmode_desc { public static string slowmode_desc {
get { get {
@ -6423,7 +6423,7 @@ namespace NadekoBot.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to `.slowmode`. /// Looks up a localized string similar to `.slowmode 1 5`.
/// </summary> /// </summary>
public static string slowmode_usage { public static string slowmode_usage {
get { get {

View File

@ -328,10 +328,10 @@
<value>slowmode</value> <value>slowmode</value>
</data> </data>
<data name="slowmode_desc" xml:space="preserve"> <data name="slowmode_desc" xml:space="preserve">
<value>Toggles slow mode. When ON, users will be able to send only 1 message every 5 seconds. </value> <value>Toggles slowmode. Disable by specifying no parameters. To enable, specify a number of messages each user can send, and an interval in seconds. For example 1 message every 5 seconds.</value>
</data> </data>
<data name="slowmode_usage" xml:space="preserve"> <data name="slowmode_usage" xml:space="preserve">
<value>`.slowmode`</value> <value>`.slowmode 1 5`</value>
</data> </data>
<data name="cleanvplust_cmd" xml:space="preserve"> <data name="cleanvplust_cmd" xml:space="preserve">
<value>cleanvplust cv+t</value> <value>cleanvplust cv+t</value>