diff --git a/RegexBot/Module/AutoRespond/ConfigItem.cs b/RegexBot/Module/AutoRespond/ConfigItem.cs index 60fc7f8..84ba528 100644 --- a/RegexBot/Module/AutoRespond/ConfigItem.cs +++ b/RegexBot/Module/AutoRespond/ConfigItem.cs @@ -15,28 +15,24 @@ namespace Noikoio.RegexBot.Module.AutoRespond public enum ResponseType { None, Exec, Reply } private static Random ChangeRng = new Random(); - string _label; - IEnumerable _regex; ResponseType _rtype; string _rbody; - private FilterList _filter; - private RateLimitCache _limit; private double _random; - public string Label => _label; - public IEnumerable Regex => _regex; + public string Label { get; } + public IEnumerable Regex { get; } public (ResponseType, string) Response => (_rtype, _rbody); - public FilterList Filter => _filter; - public RateLimitCache RateLimit => _limit; + public FilterList Filter { get; } + public RateLimitCache RateLimit { get; } public double RandomChance => _random; public ConfigItem(JProperty definition) { - _label = definition.Name; + Label = definition.Name; var data = (JObject)definition.Value; // error postfix string - string errorpfx = $" in response definition for '{_label}'."; + string errorpfx = $" in response definition for '{Label}'."; // regex trigger const string NoRegexError = "No regular expression patterns are defined"; @@ -74,7 +70,7 @@ namespace Noikoio.RegexBot.Module.AutoRespond $"Failed to parse regular expression pattern '{rxstr}'{errorpfx}"); } } - _regex = regexes.ToArray(); + Regex = regexes.ToArray(); // response - defined in either "exec" or "reply", but not both _rbody = null; @@ -103,19 +99,19 @@ namespace Noikoio.RegexBot.Module.AutoRespond // --- // whitelist/blacklist filtering - _filter = new FilterList(data); + Filter = new FilterList(data); // rate limiting string rlstr = data["ratelimit"]?.Value(); if (string.IsNullOrWhiteSpace(rlstr)) { - _limit = new RateLimitCache(RateLimitCache.DefaultTimeout); + RateLimit = new RateLimitCache(RateLimitCache.DefaultTimeout); } else { - if (ushort.TryParse(rlstr, out var rlval)) + if (uint.TryParse(rlstr, out var rlval)) { - _limit = new RateLimitCache(rlval); + RateLimit = new RateLimitCache(rlval); } else { diff --git a/RegexBot/Module/AutoRespond/RateLimitCache.cs b/RegexBot/Module/AutoRespond/RateLimitCache.cs index f84bfa2..f958f8c 100644 --- a/RegexBot/Module/AutoRespond/RateLimitCache.cs +++ b/RegexBot/Module/AutoRespond/RateLimitCache.cs @@ -9,18 +9,16 @@ namespace Noikoio.RegexBot.Module.AutoRespond class RateLimitCache { public const ushort DefaultTimeout = 20; // this is Skeeter's fault - - private readonly ushort _timeout; private Dictionary _cache; - public ushort Timeout => _timeout; + public uint Timeout { get; } /// /// Sets up a new instance of . /// - public RateLimitCache(ushort timeout) + public RateLimitCache(uint timeout) { - _timeout = timeout; + Timeout = timeout; _cache = new Dictionary(); } @@ -32,7 +30,7 @@ namespace Noikoio.RegexBot.Module.AutoRespond /// True on success. False if the given ID already exists. public bool AllowUsage(ulong id) { - if (_timeout == 0) return true; + if (Timeout == 0) return true; lock (this) {