From a0ec4db004806fe5796b3f8dd64cd89134ce8af0 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Fri, 19 Feb 2016 08:05:22 +0100 Subject: [PATCH] up to 1 command every 0-1.3 seconds per user --- .../Classes/Permissions/PermissionChecker.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/NadekoBot/Classes/Permissions/PermissionChecker.cs b/NadekoBot/Classes/Permissions/PermissionChecker.cs index bba332e3..628b0c7b 100644 --- a/NadekoBot/Classes/Permissions/PermissionChecker.cs +++ b/NadekoBot/Classes/Permissions/PermissionChecker.cs @@ -6,18 +6,34 @@ using System.Text; using System.Threading.Tasks; using Discord; using Discord.Commands; +using System.Collections.Concurrent; namespace NadekoBot.Classes.Permissions { class PermissionChecker : IPermissionChecker { public static readonly PermissionChecker _instance = new PermissionChecker(); public static PermissionChecker Instance => _instance; + private ConcurrentDictionary timeBlackList { get; } = new ConcurrentDictionary(); + static PermissionChecker() { } - public PermissionChecker() { } + public PermissionChecker() { + Task.Run(async () => { + while (true) { + //blacklist is cleared every 1.3 seconds. That is the most time anyone will be blocked for ever + await Task.Delay(1300); + timeBlackList.Clear(); + } + }); + } public bool CanRun(Command command, User user, Channel channel, out string error) { error = null; + if (timeBlackList.ContainsKey(user)) + return false; + + timeBlackList.TryAdd(user, DateTime.Now); + if (channel.IsPrivate) return true;