diff --git a/Feature/AutoRespond/AutoRespond_Process.cs b/Feature/AutoRespond/AutoRespond_Process.cs index 8ae411a..0620349 100644 --- a/Feature/AutoRespond/AutoRespond_Process.cs +++ b/Feature/AutoRespond/AutoRespond_Process.cs @@ -10,12 +10,12 @@ namespace Noikoio.RegexBot.Feature.AutoRespond { // Check filters if (def.Filter.IsFiltered(msg)) return; + + // Check if the trigger is a match + if (!def.Trigger.IsMatch(msg.Content)) return; // Check rate limit - if (!def.RateLimit.AddUsage(msg.Channel.Id)) return; - - // Check if the trigger is a match, of course - if (!def.Trigger.IsMatch(msg.Content)) return; + if (!def.RateLimit.AllowUsage(msg.Channel.Id)) return; await Log($"'{def.Label}' triggered in #{msg.Channel.Name} by {msg.Author}"); var (type, text) = def.Response; diff --git a/Feature/AutoRespond/RateLimitCache.cs b/Feature/AutoRespond/RateLimitCache.cs index cc3e4f2..20e92a7 100644 --- a/Feature/AutoRespond/RateLimitCache.cs +++ b/Feature/AutoRespond/RateLimitCache.cs @@ -25,18 +25,21 @@ namespace Noikoio.RegexBot.Feature.AutoRespond } /// - /// Adds a cache item corersponding to the given ID. + /// Checks if a "usage" is allowed for the given value. /// Items added to cache will be removed after the number of seconds specified in . /// /// The ID to add to the cache. /// True on success. False if the given ID already exists. - public bool AddUsage(ulong id) + public bool AllowUsage(ulong id) { if (_timeout == 0) return true; - Clean(); - if (_cache.ContainsKey(id)) return false; - _cache.Add(id, DateTime.Now); + lock (this) + { + Clean(); + if (_cache.ContainsKey(id)) return false; + _cache.Add(id, DateTime.Now); + } return true; }