Compare commits

..

4 Commits

Author SHA1 Message Date
2b0207d12b
Reduce data variables
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2024-10-06 17:22:20 +02:00
58f1e22dde
Correct ipaddress argument
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2024-10-06 17:22:19 +02:00
3ba723b111
Correct OPER regex
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2024-10-06 17:22:19 +02:00
4d13d704dc
Clean up Redis logic
Simplify functions and move internal database interfaces into a more
appropriate data structure.
Configure all database numbers using a redis plugin group, instead of
using a custom setting just for the whois database to make the setup
more logical.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2024-10-06 17:22:19 +02:00
2 changed files with 34 additions and 31 deletions

View File

@ -104,20 +104,10 @@ 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, SnoParser.redis.db,
"db1", "ips",
registry.Integer(
1,
"""
Redis: Database number for counting of NICKNAMES.
""",
private=True,
),
)
conf.registerGlobalValue(
SnoParser.redis,
"db2",
registry.Integer( registry.Integer(
2, 2,
""" """
@ -126,11 +116,33 @@ conf.registerGlobalValue(
private=True, private=True,
), ),
) )
conf.registerGlobalValue(
SnoParser.redis.db,
"nicks",
registry.Integer(
1,
"""
Redis: Database number for counting of NICKNAMES.
""",
private=True,
),
)
conf.registerGlobalValue(
SnoParser.redis.db,
"whois",
registry.Integer(
0,
"""
Redis: Database number for WHOIS query caching.
""",
),
)
conf.registerGlobalValue( conf.registerGlobalValue(
SnoParser.redis, SnoParser.redis,
"host", "host",
registry.String( registry.String(
"127.0.0.1", "localhost",
""" """
Redis: IP address or hostname. Redis: IP address or hostname.
""", """,
@ -218,16 +230,5 @@ 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", ipaddresses) data = self._get_from_cache("ips", ipaddress)
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,13 +212,15 @@ class SnoParser(callbacks.Plugin):
Queries the cache for an address. Queries the cache for an address.
""" """
data = self.redis_clients['whois'].get(sourceip) data = self.redis_clients['whois'].get(ipaddress)
decoded_data = data.decode("utf-8") if data is not None:
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)
decoded_count = count.decode("utf-8") if count is not None:
count = count.decode("utf-8")
print("SnoParser manual query: ", data, " ", ttl) print("SnoParser manual query: ", data, " ", ttl)
irc.reply(f"{decoded_data} - Count: {decoded_count} - Remaining: {ttl}s") irc.reply(f"{data} - Count: {count} - Remaining: {ttl}s")
ipquery = wrap(ipquery, ["ip"]) ipquery = wrap(ipquery, ["ip"])
@ -386,7 +388,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)