Compare commits

..

1 Commits

Author SHA1 Message Date
f6b887eda9
Clean up Redis logic
Simplify functions and move internal database interfaces into a more
appropriate data structure.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2024-10-05 19:48:25 +02:00
2 changed files with 25 additions and 28 deletions

View File

@ -104,21 +104,9 @@ conf.registerGlobalValue(
# REDIS related settings below: # REDIS related settings below:
### ###
conf.registerGroup(SnoParser, "redis") conf.registerGroup(SnoParser, "redis")
conf.registerGroup(SnoParser.redis, "db")
conf.registerGlobalValue( conf.registerGlobalValue(
SnoParser.redis.db, SnoParser.redis,
"ips", "db1",
registry.Integer(
2,
"""
Redis: Database number for counting of IP ADDRESSES.
""",
private=True,
),
)
conf.registerGlobalValue(
SnoParser.redis.db,
"nicks",
registry.Integer( registry.Integer(
1, 1,
""" """
@ -128,21 +116,21 @@ conf.registerGlobalValue(
), ),
) )
conf.registerGlobalValue( conf.registerGlobalValue(
SnoParser.redis.db, SnoParser.redis,
"whois", "db2",
registry.Integer( registry.Integer(
0, 2,
""" """
Redis: Database number for WHOIS query caching. Redis: Database number for counting of IP ADDRESSES.
""", """,
private=True,
), ),
) )
conf.registerGlobalValue( conf.registerGlobalValue(
SnoParser.redis, SnoParser.redis,
"host", "host",
registry.String( registry.String(
"localhost", "127.0.0.1",
""" """
Redis: IP address or hostname. Redis: IP address or hostname.
""", """,
@ -230,5 +218,16 @@ conf.registerGlobalValue(
private=True, private=True,
), ),
) )
conf.registerGroup(SnoParser.whois, "redis")
conf.registerGlobalValue(
SnoParser.whois.redis,
"db",
registry.Integer(
0,
"""
Redis: Database number for WHOIS query caching.
""",
),
)
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

View File

@ -183,7 +183,7 @@ class SnoParser(callbacks.Plugin):
def ip_run(self, ipaddress: str) -> dict: def ip_run(self, ipaddress: str) -> dict:
"""Tracks IP addresses""" """Tracks IP addresses"""
data = self._get_from_cache("ips", ipaddress) data = self._get_from_cache("ips", ipaddresses)
if data is not None: if data is not None:
if self.registryValue("debug"): if self.registryValue("debug"):
print("SNOPARSER DEBUG - IP_RUN, SEEN: TRUE") print("SNOPARSER DEBUG - IP_RUN, SEEN: TRUE")
@ -212,15 +212,13 @@ class SnoParser(callbacks.Plugin):
Queries the cache for an address. Queries the cache for an address.
""" """
data = self.redis_clients['whois'].get(ipaddress) data = self.redis_clients['whois'].get(sourceip)
if data is not None: decoded_data = data.decode("utf-8")
data = data.decode("utf-8")
ttl = self.redis_clients['whois'].ttl(ipaddress) ttl = self.redis_clients['whois'].ttl(ipaddress)
count = self.redis_clients['ips'].get(ipaddress) count = self.redis_clients['ips'].get(ipaddress)
if count is not None: decoded_count = count.decode("utf-8")
count = count.decode("utf-8")
print("SnoParser manual query: ", data, " ", ttl) print("SnoParser manual query: ", data, " ", ttl)
irc.reply(f"{data} - Count: {count} - Remaining: {ttl}s") irc.reply(f"{decoded_data} - Count: {decoded_count} - Remaining: {ttl}s")
ipquery = wrap(ipquery, ["ip"]) ipquery = wrap(ipquery, ["ip"])
@ -388,7 +386,7 @@ class SnoParser(callbacks.Plugin):
self._sendSnotice(irc, msg, repl) self._sendSnotice(irc, msg, repl)
if "OPER" in text and "Client opered up" in text: if "OPER" in text and "Client opered up" in text:
operregex = "^-OPER- Client opered up \[(.*), (.*)\]$" operregex = "^-OPER- Client opered up \[(.*)\, \ (.*)\]$"
couple = re.match(operregex, text) couple = re.match(operregex, text)
hostmask = couple.group(1) hostmask = couple.group(1)
oper = couple.group(2) oper = couple.group(2)