From c5a37126bc71f8330db54376f46d1ef0d5251c83 Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 26 Aug 2021 19:32:58 +0200 Subject: Improved `ipcounting` Signed-off-by: Georg --- __pycache__/config.cpython-38.pyc | Bin 2704 -> 2814 bytes __pycache__/plugin.cpython-38.pyc | Bin 10414 -> 10478 bytes config.py | 7 +++++++ plugin.py | 8 +++++--- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/__pycache__/config.cpython-38.pyc b/__pycache__/config.cpython-38.pyc index d7e3edd..3666f16 100644 Binary files a/__pycache__/config.cpython-38.pyc and b/__pycache__/config.cpython-38.pyc differ diff --git a/__pycache__/plugin.cpython-38.pyc b/__pycache__/plugin.cpython-38.pyc index 1a89f54..2038462 100644 Binary files a/__pycache__/plugin.cpython-38.pyc and b/__pycache__/plugin.cpython-38.pyc differ diff --git a/config.py b/config.py index 983cb6d..90dd9c9 100644 --- a/config.py +++ b/config.py @@ -140,6 +140,13 @@ conf.registerGlobalValue(SnoParser.whois, 'sample', """ , private=True )) +conf.registerGlobalValue(SnoParser.whois, 'ttl', + registry.Integer('3600', + """ + SnoParser: How long to cache WHOIS entries for. + """ + , private=True +)) conf.registerGroup(SnoParser.whois, 'redis') conf.registerGlobalValue(SnoParser.whois.redis, 'db', registry.Integer('0', diff --git a/plugin.py b/plugin.py index 4d9a797..4b16961 100644 --- a/plugin.py +++ b/plugin.py @@ -141,7 +141,8 @@ class SnoParser(callbacks.Plugin): def whois_set_cache(self, key: str, value: str) -> bool: """Data to Redis.""" - state = self.redis_client_whois.setex(key, timedelta(seconds=3600), value=value,) + duration = self.registryValue('whois.ttl') + state = self.redis_client_whois.setex(key, timedelta(seconds=duration), value=value,) return state def whois_run(self, sourceip: str) -> dict: @@ -238,12 +239,13 @@ class SnoParser(callbacks.Plugin): """ data = self.whois_get_cache(key=ipaddress) - decoded = data.decode('utf-8') + decoded_data = data.decode('utf-8') ttl = self.redis_client_whois.ttl(ipaddress) count = self.redis_client_ips.get(ipaddress) + decoded_count = count.decode('utf-8') print('SnoParser manual query: ', data, ' ', ttl) - irc.reply(f'{decoded} - Count: {count} - Remaining: {ttl}s') + irc.reply(f'{decoded_data} - Count: {decoded_count} - Remaining: {ttl}s') ipquery = wrap(ipquery, ['anything']) -- cgit v1.2.3