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:
###
conf.registerGroup(SnoParser, "redis")
conf.registerGroup(SnoParser.redis, "db")
conf.registerGlobalValue(
SnoParser.redis.db,
"ips",
registry.Integer(
2,
"""
Redis: Database number for counting of IP ADDRESSES.
""",
private=True,
),
)
conf.registerGlobalValue(
SnoParser.redis.db,
"nicks",
SnoParser.redis,
"db1",
registry.Integer(
1,
"""
@ -128,21 +116,21 @@ conf.registerGlobalValue(
),
)
conf.registerGlobalValue(
SnoParser.redis.db,
"whois",
SnoParser.redis,
"db2",
registry.Integer(
0,
2,
"""
Redis: Database number for WHOIS query caching.
Redis: Database number for counting of IP ADDRESSES.
""",
private=True,
),
)
conf.registerGlobalValue(
SnoParser.redis,
"host",
registry.String(
"localhost",
"127.0.0.1",
"""
Redis: IP address or hostname.
""",
@ -230,5 +218,16 @@ conf.registerGlobalValue(
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:

View File

@ -183,7 +183,7 @@ class SnoParser(callbacks.Plugin):
def ip_run(self, ipaddress: str) -> dict:
"""Tracks IP addresses"""
data = self._get_from_cache("ips", ipaddress)
data = self._get_from_cache("ips", ipaddresses)
if data is not None:
if self.registryValue("debug"):
print("SNOPARSER DEBUG - IP_RUN, SEEN: TRUE")
@ -212,15 +212,13 @@ class SnoParser(callbacks.Plugin):
Queries the cache for an address.
"""
data = self.redis_clients['whois'].get(ipaddress)
if data is not None:
data = data.decode("utf-8")
data = self.redis_clients['whois'].get(sourceip)
decoded_data = data.decode("utf-8")
ttl = self.redis_clients['whois'].ttl(ipaddress)
count = self.redis_clients['ips'].get(ipaddress)
if count is not None:
count = count.decode("utf-8")
decoded_count = count.decode("utf-8")
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"])
@ -388,7 +386,7 @@ class SnoParser(callbacks.Plugin):
self._sendSnotice(irc, msg, repl)
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)
hostmask = couple.group(1)
oper = couple.group(2)