Compare commits
2 commits
3ff4b1a3fb
...
385d44c81a
Author | SHA1 | Date | |
---|---|---|---|
385d44c81a | |||
74bc044fec |
4 changed files with 69 additions and 5 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): ...
|
||||||
|
|
||||||
|
|
14
bot.py
14
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 = []
|
||||||
|
@ -227,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))
|
||||||
|
@ -324,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)
|
||||||
|
|
33
config.py
33
config.py
|
@ -2,11 +2,15 @@
|
||||||
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
|
||||||
|
|
||||||
|
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,24 @@ 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
|
||||||
|
|
26
handlers.py
26
handlers.py
|
@ -185,6 +185,31 @@ 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
|
||||||
|
|
||||||
|
@ -199,4 +224,5 @@ handles: dict[
|
||||||
"MODE": NULL,
|
"MODE": NULL,
|
||||||
"TOPIC": NULL,
|
"TOPIC": NULL,
|
||||||
"QUIT": QUIT,
|
"QUIT": QUIT,
|
||||||
|
"JOIN": JOIN,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue