From 44a1090ece5a5b6b8eb8b36d61fbc6189b564101 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 3 Sep 2016 17:50:10 +0200 Subject: [PATCH] Fixed slowmode --- .../Administration/Commands/RatelimitCommand.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs index ddd2db75..ec634158 100644 --- a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs @@ -33,10 +33,9 @@ namespace NadekoBot.Modules.Administration public int MaxMessages { get; set; } public int PerSeconds { get; set; } - public CancellationTokenSource cancelSource { get; set; } - public CancellationToken cancelToken { get; set; } + public CancellationTokenSource cancelSource { get; set; } = new CancellationTokenSource(); - public ConcurrentDictionary Users { get; set; } + public ConcurrentDictionary Users { get; set; } = new ConcurrentDictionary(); public bool CheckUserRatelimit(ulong id) { @@ -51,7 +50,7 @@ namespace NadekoBot.Modules.Administration var t = Task.Run(async () => { try { - await Task.Delay(PerSeconds * 1000, cancelToken); + await Task.Delay(PerSeconds * 1000, cancelSource.Token); } catch (OperationCanceledException) { } usr.MessageCount--; @@ -95,6 +94,7 @@ namespace NadekoBot.Modules.Administration Ratelimiter throwaway; if (RatelimitingChannels.TryRemove(channel.Id, out throwaway)) { + throwaway.cancelSource.Cancel(); await channel.SendMessageAsync("`Slow mode disabled.`").ConfigureAwait(false); return; } @@ -106,7 +106,9 @@ namespace NadekoBot.Modules.Administration } if (RatelimitingChannels.TryAdd(channel.Id,throwaway = new Ratelimiter() { - ChannelId = channel.Id + ChannelId = channel.Id, + MaxMessages = msg, + PerSeconds = perSec, })) { await channel.SendMessageAsync("`Slow mode initiated.` " +