Compare commits

..

No commits in common. "385d44c81aec9ef16316f4d8db2be596b76c736e" and "3ff4b1a3fba2f195ea796cdf511f082d9a05db99" have entirely different histories.

4 changed files with 5 additions and 69 deletions

View file

@ -42,7 +42,6 @@ class bot:
onStrtCmds: list[str] onStrtCmds: list[str]
markov: MarkovBot markov: MarkovBot
autoMethod: str autoMethod: str
dnsblMode: str
def __init__(self, server: str): ... def __init__(self, server: str): ...

14
bot.py
View file

@ -77,11 +77,6 @@ class bot(bare.bot):
if "autoMethod" in conf.servers[server] if "autoMethod" in conf.servers[server]
else "QUOTE" else "QUOTE"
) )
self.dnsblMode = (
conf.servers[server]["dnsblMode"]
if "dnsblMode" in conf.servers[server]
else "none"
)
self.lastfmLink = conf.lastfmLink self.lastfmLink = conf.lastfmLink
with open("mastermessages.txt") as f: with open("mastermessages.txt") as f:
TMFeed = [] TMFeed = []
@ -232,10 +227,7 @@ 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)) data = bytes(self.sock.recv(2048).strip(b"\r\n"))
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))
@ -332,8 +324,8 @@ class bot(bare.bot):
else 50 else 50
) )
conf.prefix = ( conf.prefix = (
conf.servers[self.server]["prefix"] conf.servers[server]["prefix"]
if "prefix" in conf.servers[self.server] if "prefix" in conf.servers[server]
else "." else "."
) )
reload(cmds) reload(cmds)

View file

@ -2,15 +2,11 @@
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, Union from typing import Optional, Any
import bare, pylast import bare, pylast
from pydnsbl import DNSBLIpChecker, DNSBLDomainChecker
ipbl = DNSBLIpChecker()
hsbl = DNSBLDomainChecker()
load_dotenv() load_dotenv()
__version__ = "v3.0.13" __version__ = "v3.0.12"
npbase: str = ( npbase: str = (
"\[\x0303last\.fm\x03\] [A-Za-z0-9_[\]{}\\|\-^]{1,$MAX} (is listening|last listened) to: \x02.+ - .*\x02( \([0-9]+ plays\)( \[.*\])?)?" # pyright: ignore [reportInvalidStringEscapeSequence] "\[\x0303last\.fm\x03\] [A-Za-z0-9_[\]{}\\|\-^]{1,$MAX} (is listening|last listened) to: \x02.+ - .*\x02( \([0-9]+ plays\)( \[.*\])?)?" # pyright: ignore [reportInvalidStringEscapeSequence]
) )
@ -24,13 +20,11 @@ servers: dict[str, dict[str, Any]] = {
"channels": {"#random": 0, "#dice": 0, "#offtopic": 0, "#main/replirc": 0}, "channels": {"#random": 0, "#dice": 0, "#offtopic": 0, "#main/replirc": 0},
"ignores": ["#main/replirc"], "ignores": ["#main/replirc"],
"hosts": ["9pfs.repl.co"], "hosts": ["9pfs.repl.co"],
"dnsblMode": "kickban"
}, },
"efnet": { "efnet": {
"address": "irc.underworld.no", "address": "irc.underworld.no",
"channels": {"#random": 0, "#dice": 0}, "channels": {"#random": 0, "#dice": 0},
"hosts": ["154.sub-174-251-241.myvzw.com"], "hosts": ["154.sub-174-251-241.myvzw.com"],
"dnsblMode": "kickban",
}, },
"replirc": { "replirc": {
"address": "127.0.0.1", "address": "127.0.0.1",
@ -52,7 +46,6 @@ servers: dict[str, dict[str, Any]] = {
"hosts": ["owner.firepi"], "hosts": ["owner.firepi"],
"threads": ["radio"], "threads": ["radio"],
"autoMethod": "MARKOV", "autoMethod": "MARKOV",
"dnsblMode": "akill",
}, },
"backupbox": { "backupbox": {
"address": "127.0.0.1", "address": "127.0.0.1",
@ -65,7 +58,6 @@ servers: dict[str, dict[str, Any]] = {
"2600-6c5a-637f-1a85-0000-0000-0000-6667.inf6.spectrum.com", "2600-6c5a-637f-1a85-0000-0000-0000-6667.inf6.spectrum.com",
], ],
"onIdntCmds": ["OPER e e"], "onIdntCmds": ["OPER e e"],
"dnsbl-mode": "gline",
}, },
"twitch": { "twitch": {
"nick": "fireschatbot", "nick": "fireschatbot",
@ -121,24 +113,3 @@ def sub(
if name: if name:
result = result.replace("$SENDER", name).replace("$NAME", name) result = result.replace("$SENDER", name).replace("$NAME", name)
return result return result
def dnsbl(hostname: str) -> Union[str, None]:
hosts = []
hstDT = None
try:
hstDT = ipbl.check(hostname).detected_by
except ValueError:
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
if len(hosts) >= 3:
hostStr = ', and '.join((', '.join(hosts)).rsplit(", ", 1))
else:
hostStr = ' and '.join(hosts)
return hostStr

View file

@ -185,31 +185,6 @@ def QUIT(bot: bare.bot, msg: str) -> tuple[None, None]:
return None, None return 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 #{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).")
case "kline":
bot.sendraw(f"KILL {nick} :Sorry, but you're on the {dnsblStatus} blacklist(s).")
bot.sendraw(f"KLINE 524160 *@{hostname} :Sorry, but you're on the {dnsblStatus} blacklist(s).")
bot.sendraw(f"KLINE *@{hostname} :Sorry, but you're on the {dnsblStatus} blacklist(s).")
case "gline":
bot.sendraw(f"KILL {nick} :Sorry, but you're on the {dnsblStatus} blacklist(s).")
bot.sendraw(f"GLINE *@{hostname} 524160 :Sorry, but you're on the {dnsblStatus} blacklist(s).")
bot.sendraw(f"GLINE *@{hostname} :Sorry, but you're on the {dnsblStatus} blacklist(s).")
case _:
bot.log(f'Unknown dnsbl Mode "{bot.dnsblMode}"!', "WARN")
return None, None
def NULL(bot: bare.bot, msg: str) -> tuple[None, None]: def NULL(bot: bare.bot, msg: str) -> tuple[None, None]:
return None, None return None, None
@ -224,5 +199,4 @@ handles: dict[
"MODE": NULL, "MODE": NULL,
"TOPIC": NULL, "TOPIC": NULL,
"QUIT": QUIT, "QUIT": QUIT,
"JOIN": JOIN,
} }