DNSBL support

This commit is contained in:
Firepup Sixfifty 2024-05-18 17:38:49 -05:00
parent 3ff4b1a3fb
commit 74bc044fec
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA
4 changed files with 54 additions and 1 deletions

View file

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

5
bot.py
View file

@ -77,6 +77,11 @@ class bot(bare.bot):
if "autoMethod" in conf.servers[server]
else "QUOTE"
)
self.dnsblMode = (
conf.servers[server]["dnsblMode"]
if "dnsblMode" in conf.servers[server]
else "none"
)
self.lastfmLink = conf.lastfmLink
with open("mastermessages.txt") as f:
TMFeed = []

View file

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