Fixed slowmode
This commit is contained in:
parent
1c34b97e97
commit
44a1090ece
@ -33,10 +33,9 @@ namespace NadekoBot.Modules.Administration
|
|||||||
public int MaxMessages { get; set; }
|
public int MaxMessages { get; set; }
|
||||||
public int PerSeconds { get; set; }
|
public int PerSeconds { get; set; }
|
||||||
|
|
||||||
public CancellationTokenSource cancelSource { get; set; }
|
public CancellationTokenSource cancelSource { get; set; } = new CancellationTokenSource();
|
||||||
public CancellationToken cancelToken { get; set; }
|
|
||||||
|
|
||||||
public ConcurrentDictionary<ulong, RatelimitedUser> Users { get; set; }
|
public ConcurrentDictionary<ulong, RatelimitedUser> Users { get; set; } = new ConcurrentDictionary<ulong, RatelimitedUser>();
|
||||||
|
|
||||||
public bool CheckUserRatelimit(ulong id)
|
public bool CheckUserRatelimit(ulong id)
|
||||||
{
|
{
|
||||||
@ -51,7 +50,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
var t = Task.Run(async () => {
|
var t = Task.Run(async () => {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Task.Delay(PerSeconds * 1000, cancelToken);
|
await Task.Delay(PerSeconds * 1000, cancelSource.Token);
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException) { }
|
catch (OperationCanceledException) { }
|
||||||
usr.MessageCount--;
|
usr.MessageCount--;
|
||||||
@ -95,6 +94,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
Ratelimiter throwaway;
|
Ratelimiter throwaway;
|
||||||
if (RatelimitingChannels.TryRemove(channel.Id, out throwaway))
|
if (RatelimitingChannels.TryRemove(channel.Id, out throwaway))
|
||||||
{
|
{
|
||||||
|
throwaway.cancelSource.Cancel();
|
||||||
await channel.SendMessageAsync("`Slow mode disabled.`").ConfigureAwait(false);
|
await channel.SendMessageAsync("`Slow mode disabled.`").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -106,7 +106,9 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (RatelimitingChannels.TryAdd(channel.Id,throwaway = new Ratelimiter() {
|
if (RatelimitingChannels.TryAdd(channel.Id,throwaway = new Ratelimiter() {
|
||||||
ChannelId = channel.Id
|
ChannelId = channel.Id,
|
||||||
|
MaxMessages = msg,
|
||||||
|
PerSeconds = perSec,
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("`Slow mode initiated.` " +
|
await channel.SendMessageAsync("`Slow mode initiated.` " +
|
||||||
|
Loading…
Reference in New Issue
Block a user