forked from Firepup650/FireBot
DNSBL support
This commit is contained in:
parent
3ff4b1a3fb
commit
74bc044fec
4 changed files with 54 additions and 1 deletions
1
bare.py
1
bare.py
|
@ -42,6 +42,7 @@ 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): ...
|
||||||
|
|
||||||
|
|
5
bot.py
5
bot.py
|
@ -77,6 +77,11 @@ 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 = []
|
||||||
|
|
26
config.py
26
config.py
|
@ -4,9 +4,13 @@ from dotenv import load_dotenv # type: ignore
|
||||||
import re, codecs
|
import re, codecs
|
||||||
from typing import Optional, Any
|
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.12"
|
__version__ = "v3.0.13"
|
||||||
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]
|
||||||
)
|
)
|
||||||
|
@ -20,11 +24,13 @@ 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",
|
||||||
|
@ -46,6 +52,7 @@ 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",
|
||||||
|
@ -58,6 +65,7 @@ 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",
|
||||||
|
@ -113,3 +121,19 @@ 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 = 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
|
||||||
|
|
23
handlers.py
23
handlers.py
|
@ -185,6 +185,28 @@ 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]:
|
||||||
|
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]:
|
def NULL(bot: bare.bot, msg: str) -> tuple[None, None]:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
@ -199,4 +221,5 @@ handles: dict[
|
||||||
"MODE": NULL,
|
"MODE": NULL,
|
||||||
"TOPIC": NULL,
|
"TOPIC": NULL,
|
||||||
"QUIT": QUIT,
|
"QUIT": QUIT,
|
||||||
|
"JOIN": JOIN,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue