From 385d44c81aec9ef16316f4d8db2be596b76c736e Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Sat, 18 May 2024 22:23:36 -0500 Subject: [PATCH] Fix dnsbl errors, bug fixes in bot.py --- bot.py | 9 ++++++--- config.py | 13 +++++++++---- handlers.py | 5 ++++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index c540c8f..3c54180 100644 --- a/bot.py +++ b/bot.py @@ -232,7 +232,10 @@ class bot(bare.bot): def recv(self) -> bytes: if self.queue: return bytes(self.queue.pop(0)) - data = bytes(self.sock.recv(2048).strip(b"\r\n")) + data = bytes(self.sock.recv(2048)) + while !data.endswith(b"\r\n") + data += bytes(self.sock.recv(2048)) + data.rstrip(b"\r\n") if b"\r\n" in data: self.queue.extend(data.split(b"\r\n")) return bytes(self.queue.pop(0)) @@ -329,8 +332,8 @@ class bot(bare.bot): else 50 ) conf.prefix = ( - conf.servers[server]["prefix"] - if "prefix" in conf.servers[server] + conf.servers[self.server]["prefix"] + if "prefix" in conf.servers[self.server] else "." ) reload(cmds) diff --git a/config.py b/config.py index 00aa930..07c5205 100644 --- a/config.py +++ b/config.py @@ -2,7 +2,7 @@ from os import environ as env from dotenv import load_dotenv # type: ignore import re, codecs -from typing import Optional, Any +from typing import Optional, Any, Union import bare, pylast from pydnsbl import DNSBLIpChecker, DNSBLDomainChecker @@ -124,11 +124,16 @@ def sub( def dnsbl(hostname: str) -> Union[str, None]: - hosts = None + hosts = [] + hstDT = None try: - hosts = ipbl.check(hostname).detected_by.keys() + hstDT = ipbl.check(hostname).detected_by except ValueError: - hosts = hsbl.check(hostname).detected_by.keys() + hstDT = hsbl.check(hostname).detected_by + for host in hstDT: + if hstDT[host] != ["unknown"]: + hosts.append(host) + print(f'DEBUG: {host} - {hstDT[host]}') if not hosts: return hostStr = None diff --git a/handlers.py b/handlers.py index 028cda2..877171c 100644 --- a/handlers.py +++ b/handlers.py @@ -186,12 +186,15 @@ def QUIT(bot: bare.bot, msg: str) -> tuple[None, None]: def JOIN(bot: bare.bot, msg: str) -> tuple[None, None]: + nick = msg.split("!", 1)[0][1:] + hostname = msg.split("@", 1)[1].split(" ", 1)[0].strip() + chan = msg.split("#")[-1].strip() if bot.dnsblMode != "none": dnsblStatus = conf.dnsbl(hostname) if dnsblStatus: match bot.dnsblMode: case "kickban": - bot.sendraw(f"KICK {nick} :Sorry, but you're on the {dnsblStatus} blacklist(s).") + bot.sendraw(f"KICK #{chan} {nick} :Sorry, but you're on the {dnsblStatus} blacklist(s).") bot.sendraw(f"MODE #{chan} +b *!*@{hostname}") case "akill": bot.sendraw(f"OS AKILL ADD *@{hostname} !P Sorry, but you're on the {dnsblStatus} blacklists(s).")