cache dnsbl lookups (v3.0.19)
This commit is contained in:
parent
19ff5ee010
commit
433f57beb8
4 changed files with 11 additions and 5 deletions
1
bare.py
1
bare.py
|
@ -45,6 +45,7 @@ class bot:
|
|||
dnsblMode: str
|
||||
statuses: dict[str, dict[str, str]]
|
||||
ops: dict[str, bool]
|
||||
dns: dict[str, dict[str, Union[str, list[str]]]]
|
||||
|
||||
def __init__(self, server: str): ...
|
||||
|
||||
|
|
1
bot.py
1
bot.py
|
@ -85,6 +85,7 @@ class bot(bare.bot):
|
|||
if "dnsblMode" in conf.servers[server]
|
||||
else "none"
|
||||
)
|
||||
self.dns = {}
|
||||
self.lastfmLink = conf.lastfmLink
|
||||
with open("mastermessages.txt") as f:
|
||||
TMFeed = []
|
||||
|
|
|
@ -290,12 +290,15 @@ def check(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
|||
msg = message.split(" ", 1)[1]
|
||||
nick = msg.split("!")[0]
|
||||
host = msg.split("@", 1)[1]
|
||||
cache = host in bot.dns
|
||||
dnsbl, raws = conf.dnsblHandler(bot, nick, host, chan)
|
||||
bot.msg(f"Blacklist check: {dnsbl if dnsbl else 'Safe.'} ({raws})", chan)
|
||||
bot.msg(f"Blacklist check: {'(Cached) ' if cache else ''}{dnsbl if dnsbl else 'Safe.'} ({raws})", chan)
|
||||
except IndexError:
|
||||
try:
|
||||
dnsbl, raws = conf.dnsblHandler(bot, "thisusernameshouldbetoolongtoeveractuallybeinuse", message.split(" ", 1)[1], chan)
|
||||
bot.msg(f"Blacklist check: {dnsbl if dnsbl else 'Safe.'} ({raws})", chan)
|
||||
host = message.split(" ", 1)[1]
|
||||
cache = host in bot.dns
|
||||
dnsbl, raws = conf.dnsblHandler(bot, "thisusernameshouldbetoolongtoeveractuallybeinuse", host, chan)
|
||||
bot.msg(f"Blacklist check: {'(Cached) ' if cache else ''}{dnsbl if dnsbl else 'Safe.'} ({raws})", chan)
|
||||
except Exception as E:
|
||||
bot.msg("Blacklist Lookup Failed. Error recorded to bot logs.", chan)
|
||||
bot.log(str(E), "FATAL")
|
||||
|
|
|
@ -32,7 +32,7 @@ ipbl = DNSBLIpChecker(providers=providers)
|
|||
hsbl = DNSBLDomainChecker(providers=providers)
|
||||
|
||||
load_dotenv()
|
||||
__version__ = "v3.0.18"
|
||||
__version__ = "v3.0.19"
|
||||
npbase: str = (
|
||||
"\[\x0303last\.fm\x03\] [A-Za-z0-9_[\]{}\\|\-^]{1,$MAX} (is listening|last listened) to: \x02.+ - .*\x02( \([0-9]+ plays\)( \[.*\])?)?" # pyright: ignore [reportInvalidStringEscapeSequence]
|
||||
)
|
||||
|
@ -198,7 +198,8 @@ def dnsblHandler(
|
|||
dnsblStatus = "Not enabled"
|
||||
dnsblResps = {}
|
||||
if bot.dnsblMode != "none":
|
||||
dnsblStatus, dnsblResps = dnsbl(hostname)
|
||||
dnsblStatus, dnsblResps = dnsbl(hostname) if not hostname in bot.dns else (bot.dns[hostname]["status"], bot.dns[hostname]["resps"])
|
||||
bot.dns[hostname] = {"status": dnsblStatus, "resps": dnsblResps}
|
||||
if dnsblStatus:
|
||||
match bot.dnsblMode:
|
||||
case "kickban":
|
||||
|
|
Loading…
Reference in a new issue