Fix dnsbl errors, bug fixes in bot.py
This commit is contained in:
parent
74bc044fec
commit
385d44c81a
3 changed files with 19 additions and 8 deletions
9
bot.py
9
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)
|
||||
|
|
13
config.py
13
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
|
||||
|
|
|
@ -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).")
|
||||
|
|
Loading…
Reference in a new issue