forked from Firepup650/FireBot
Allow admins to premptively check DNSBLs. Also remove some Debug lines and fix minor issues.
This commit is contained in:
parent
8dc9755c46
commit
fdd490518c
3 changed files with 47 additions and 25 deletions
17
commands.py
17
commands.py
|
@ -224,7 +224,7 @@ def setStatus(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
||||||
stat = int(message.split(' ')[1])
|
stat = int(message.split(' ')[1])
|
||||||
reas = message.split(' ', 2)[2]
|
reas = message.split(' ', 2)[2]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
bot.msg(f"Insufficent information to set a status. Expected 3 args. Only got {len(message.split(' ', 1)) - 1} args.", chan)
|
bot.msg(f"Insufficent information to set a status. Only got {len(message.split(' ')) - (1 if '.sS' in message else 0)}/3 expected args.", chan)
|
||||||
return
|
return
|
||||||
except ValueError:
|
except ValueError:
|
||||||
bot.msg("Status parameter must be an int.", chan)
|
bot.msg("Status parameter must be an int.", chan)
|
||||||
|
@ -250,13 +250,24 @@ def getStatus(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
||||||
user = message.split(' ')[1]
|
user = message.split(' ')[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
user = 'firepup'
|
user = 'firepup'
|
||||||
bot.msg(f"[DEBUG] {user} - {bot.statuses.get(user)} (msg in was {message.split(' ')})", chan)
|
|
||||||
if bot.statuses.get(user) is None:
|
if bot.statuses.get(user) is None:
|
||||||
bot.msg("You've gotta provide a nick I actually recognize.", chan)
|
bot.msg("You've gotta provide a nick I actually recognize.", chan)
|
||||||
return
|
return
|
||||||
bot.msg(f"{user}'s status: {'Unknown' if not bot.statuses[user].get('status') else bot.statuses[user]['status']} - {'Reason unset' if not bot.statuses[user].get('reason') else bot.statuses[user]['reason']}", chan)
|
bot.msg(f"{user}'s status: {'Unknown' if not bot.statuses[user].get('status') else bot.statuses[user]['status']} - {'Reason unset' if not bot.statuses[user].get('reason') else bot.statuses[user]['reason']}", chan)
|
||||||
|
|
||||||
|
|
||||||
|
def check(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
||||||
|
try:
|
||||||
|
msg = message.split(' ', 1)[1]
|
||||||
|
nick = msg.split('!')[0]
|
||||||
|
host = msg.split('@', 1)[1]
|
||||||
|
dnsbl = conf.dnsblHandler(bot, nick, host, chan)
|
||||||
|
bot.msg("Blacklist check: " + (dnsbl if dnsbl else "Safe."), chan)
|
||||||
|
except Exception as E:
|
||||||
|
bot.msg("Blacklist lookup failed. Error recorded to bot logs.", chan)
|
||||||
|
bot.log(str(E), "FATAL")
|
||||||
|
|
||||||
|
|
||||||
data: dict[str, dict[str, Any]] = {
|
data: dict[str, dict[str, Any]] = {
|
||||||
"!botlist": {"prefix": False, "aliases": []},
|
"!botlist": {"prefix": False, "aliases": []},
|
||||||
"bugs bugs bugs": {"prefix": False, "aliases": []},
|
"bugs bugs bugs": {"prefix": False, "aliases": []},
|
||||||
|
@ -290,6 +301,7 @@ data: dict[str, dict[str, Any]] = {
|
||||||
"markov": {"prefix": True, "aliases": ["m"]},
|
"markov": {"prefix": True, "aliases": ["m"]},
|
||||||
"setStatus": {"prefix": True, "aliases": ["sS"], "check": checks.admin},
|
"setStatus": {"prefix": True, "aliases": ["sS"], "check": checks.admin},
|
||||||
"getStatus": {"prefix": True, "aliases": ["gS"]},
|
"getStatus": {"prefix": True, "aliases": ["gS"]},
|
||||||
|
"check": {"prefix": True, "aliases": [], "check": checks.admin},
|
||||||
}
|
}
|
||||||
regexes: list[str] = [conf.npbase, conf.su]
|
regexes: list[str] = [conf.npbase, conf.su]
|
||||||
call: dict[str, Callable[[bare.bot, str, str, str], None]] = {
|
call: dict[str, Callable[[bare.bot, str, str, str], None]] = {
|
||||||
|
@ -318,4 +330,5 @@ call: dict[str, Callable[[bare.bot, str, str, str], None]] = {
|
||||||
"markov": markov,
|
"markov": markov,
|
||||||
"setStatus": setStatus,
|
"setStatus": setStatus,
|
||||||
"getStatus": getStatus,
|
"getStatus": getStatus,
|
||||||
|
"check": check,
|
||||||
}
|
}
|
||||||
|
|
30
config.py
30
config.py
|
@ -10,7 +10,7 @@ ipbl = DNSBLIpChecker()
|
||||||
hsbl = DNSBLDomainChecker()
|
hsbl = DNSBLDomainChecker()
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
__version__ = "v3.0.14"
|
__version__ = "v3.0.15"
|
||||||
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]
|
||||||
)
|
)
|
||||||
|
@ -123,7 +123,7 @@ def sub(
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def dnsbl(hostname: str) -> Union[str, None]:
|
def dnsbl(hostname: str) -> str:
|
||||||
hosts = []
|
hosts = []
|
||||||
hstDT = None
|
hstDT = None
|
||||||
try:
|
try:
|
||||||
|
@ -136,12 +136,34 @@ def dnsbl(hostname: str) -> Union[str, None]:
|
||||||
for host in hstDT:
|
for host in hstDT:
|
||||||
if hstDT[host] != ["unknown"]:
|
if hstDT[host] != ["unknown"]:
|
||||||
hosts.append(host)
|
hosts.append(host)
|
||||||
print(f'DEBUG: {host} - {hstDT[host]}')
|
|
||||||
if not hosts:
|
if not hosts:
|
||||||
return
|
return ""
|
||||||
hostStr = None
|
hostStr = None
|
||||||
if len(hosts) >= 3:
|
if len(hosts) >= 3:
|
||||||
hostStr = ', and '.join((', '.join(hosts)).rsplit(", ", 1))
|
hostStr = ', and '.join((', '.join(hosts)).rsplit(", ", 1))
|
||||||
else:
|
else:
|
||||||
hostStr = ' and '.join(hosts)
|
hostStr = ' and '.join(hosts)
|
||||||
return hostStr
|
return hostStr
|
||||||
|
|
||||||
|
def dnsblHandler(bot: bare.bot, nick: str, hostname: str, chan: str) -> str:
|
||||||
|
dnsblStatus = 'Not enabled'
|
||||||
|
if bot.dnsblMode != "none":
|
||||||
|
dnsblStatus = 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 dnsblStatus
|
||||||
|
|
25
handlers.py
25
handlers.py
|
@ -189,27 +189,14 @@ def JOIN(bot: bare.bot, msg: str) -> tuple[None, None]:
|
||||||
nick = msg.split("!", 1)[0][1:]
|
nick = msg.split("!", 1)[0][1:]
|
||||||
hostname = msg.split("@", 1)[1].split(" ", 1)[0].strip()
|
hostname = msg.split("@", 1)[1].split(" ", 1)[0].strip()
|
||||||
chan = msg.split("#")[-1].strip()
|
chan = msg.split("#")[-1].strip()
|
||||||
if bot.dnsblMode != "none":
|
conf.dnsblHandler(bot, nick, hostname, chan)
|
||||||
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
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
|
def MODE(bot: bare.bot, msg: str) -> tuple[None, None]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue