Fix dnsbl errors, bug fixes in bot.py

This commit is contained in:
Firepup Sixfifty 2024-05-18 22:23:36 -05:00
parent 74bc044fec
commit 385d44c81a
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA
3 changed files with 19 additions and 8 deletions

9
bot.py
View file

@ -232,7 +232,10 @@ class bot(bare.bot):
def recv(self) -> bytes: def recv(self) -> bytes:
if self.queue: if self.queue:
return bytes(self.queue.pop(0)) 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: if b"\r\n" in data:
self.queue.extend(data.split(b"\r\n")) self.queue.extend(data.split(b"\r\n"))
return bytes(self.queue.pop(0)) return bytes(self.queue.pop(0))
@ -329,8 +332,8 @@ class bot(bare.bot):
else 50 else 50
) )
conf.prefix = ( conf.prefix = (
conf.servers[server]["prefix"] conf.servers[self.server]["prefix"]
if "prefix" in conf.servers[server] if "prefix" in conf.servers[self.server]
else "." else "."
) )
reload(cmds) reload(cmds)

View file

@ -2,7 +2,7 @@
from os import environ as env from os import environ as env
from dotenv import load_dotenv # type: ignore from dotenv import load_dotenv # type: ignore
import re, codecs import re, codecs
from typing import Optional, Any from typing import Optional, Any, Union
import bare, pylast import bare, pylast
from pydnsbl import DNSBLIpChecker, DNSBLDomainChecker from pydnsbl import DNSBLIpChecker, DNSBLDomainChecker
@ -124,11 +124,16 @@ def sub(
def dnsbl(hostname: str) -> Union[str, None]: def dnsbl(hostname: str) -> Union[str, None]:
hosts = None hosts = []
hstDT = None
try: try:
hosts = ipbl.check(hostname).detected_by.keys() hstDT = ipbl.check(hostname).detected_by
except ValueError: 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: if not hosts:
return return
hostStr = None hostStr = None

View file

@ -186,12 +186,15 @@ def QUIT(bot: bare.bot, msg: str) -> tuple[None, None]:
def JOIN(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": if bot.dnsblMode != "none":
dnsblStatus = conf.dnsbl(hostname) dnsblStatus = conf.dnsbl(hostname)
if dnsblStatus: if dnsblStatus:
match bot.dnsblMode: match bot.dnsblMode:
case "kickban": 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}") bot.sendraw(f"MODE #{chan} +b *!*@{hostname}")
case "akill": case "akill":
bot.sendraw(f"OS AKILL ADD *@{hostname} !P Sorry, but you're on the {dnsblStatus} blacklists(s).") bot.sendraw(f"OS AKILL ADD *@{hostname} !P Sorry, but you're on the {dnsblStatus} blacklists(s).")