Lots of stuff

This commit is contained in:
Firepup Sixfifty 2023-11-20 17:52:18 -06:00
parent 2031315832
commit 149946b65a
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA
5 changed files with 55 additions and 45 deletions

1
bot.py
View file

@ -41,6 +41,7 @@ class bot(bare.bot):
self.queue: list[bbytes] = [] self.queue: list[bbytes] = []
self.sock = socket(AF_INET, SOCK_STREAM) self.sock = socket(AF_INET, SOCK_STREAM)
self.npallowed = ["FireBitBot"] self.npallowed = ["FireBitBot"]
self.current = "user"
self.log(f"Start init for {self.server}") self.log(f"Start init for {self.server}")
def connect(self) -> None: def connect(self) -> None:

26
checks.py Normal file
View file

@ -0,0 +1,26 @@
#!/usr/bin/python3
import config as conf
import random as r
from typing import Any, Callable, Optional
import bare, re
def admin(bot: bare.bot, name: str, host: Optional[str] = "nul", chan: Optional[str] = "nul", cmd: Optional[str] = "nul") -> bool:
if (
name.lower() in conf.servers[bot.server]["admins"]
or host in conf.admin_hosts
or host in conf.servers[bot.server]["hosts"]
):
if bot.current != "bridge":
return True
else:
if type(chan) != str or chan == "nul":
return False
else:
bot.msg(f"Sorry {name}, bridged users can't use admin commands.", chan)
return False
else:
if type(chan) != str or chan == "nul":
return False
else:
bot.msg(f"Sorry {name}, {cmd} is an admin only command.", chan)
return False

View file

@ -1,8 +1,9 @@
#!/usr/bin/python3
from subprocess import run, PIPE from subprocess import run, PIPE
import config as conf import config as conf
import random as r import random as r
from typing import Any, Callable from typing import Any, Callable
import bare, re import bare, re, checks
def goat(bot: bare.bot, chan: str, name: str, message: str) -> None: def goat(bot: bare.bot, chan: str, name: str, message: str) -> None:
@ -50,19 +51,14 @@ def uptime(bot: bare.bot, chan: str, name: str, message: str) -> None:
def isAdmin(bot: bare.bot, chan: str, name: str, message: str) -> None: def isAdmin(bot: bare.bot, chan: str, name: str, message: str) -> None:
bot.msg( bot.msg(
f"{conf.adminCheck(bot, name)} (hostname is not checked)", f"{checks.admin(bot, name)} (hostname is not checked)",
chan, chan,
) )
def help(bot: bare.bot, chan: str, name: str, message: str) -> None: def help(bot: bare.bot, chan: str, name: str, message: str) -> None:
helpErr = False helpErr = False
if (name.startswith("saxjax") and bot.server == "efnet") or ( if bot.current == "bridge":
name == "ReplIRC" and bot.server == "replirc"
):
if "<" in message and "<" in message:
helpErr = True
elif name.endswith("dsc"):
helpErr = True helpErr = True
if not helpErr: if not helpErr:
bot.msg("Command list needs rework", name) bot.msg("Command list needs rework", name)
@ -102,10 +98,11 @@ def quote(bot: bare.bot, chan: str, name: str, message: str) -> None:
query = "null" query = "null"
if " " in message: if " " in message:
query = message.split(" ", 1)[1] query = message.split(" ", 1)[1]
qfilter = f".*{query}.*" qfilter = f".*{query}.*".replace(" ", "\s")
r.seed() r.seed()
mm = open("mastermessages.txt", "r") mm = open("mastermessages.txt", "r")
q = list(filter(lambda x: re.match(qfilter, x), mm.readlines())) quotes = mm.readlines()
q = list(filter(lambda x: re.match(qfilter, x), quotes))
if q == []: if q == []:
q = [f'No results for "{query}" '] q = [f'No results for "{query}" ']
sel = conf.decode_escapes( sel = conf.decode_escapes(
@ -153,7 +150,7 @@ def reboot(bot: bare.bot, chan: str, name: str, message: str) -> None:
def sudo(bot: bare.bot, chan: str, name: str, message: str) -> None: def sudo(bot: bare.bot, chan: str, name: str, message: str) -> None:
if conf.adminCheck(bot, name): if checks.admin(bot, name):
bot.msg("Error - system failure, contact system operator", chan) bot.msg("Error - system failure, contact system operator", chan)
elif "bot" in name.lower(): elif "bot" in name.lower():
bot.log("lol, no.") bot.log("lol, no.")
@ -179,22 +176,22 @@ data: dict[str, dict[str, Any]] = {
"bugs bugs bugs": {"prefix": False, "aliases": []}, "bugs bugs bugs": {"prefix": False, "aliases": []},
"hi $BOTNICK": {"prefix": False, "aliases": ["hello $BOTNICK"]}, "hi $BOTNICK": {"prefix": False, "aliases": ["hello $BOTNICK"]},
# [npbase, su] # [npbase, su]
"restart": {"prefix": True, "aliases": ["reboot"], "admin": True}, "restart": {"prefix": True, "aliases": ["reboot"], "check": checks.admin},
"uptime": {"prefix": True, "aliases": []}, "uptime": {"prefix": True, "aliases": []},
"raw ": {"prefix": True, "aliases": ["cmd "], "admin": True}, "raw ": {"prefix": True, "aliases": ["cmd "], "check": checks.admin},
"debug": {"prefix": True, "aliases": ["dbg"], "admin": True}, "debug": {"prefix": True, "aliases": ["dbg"], "check": checks.admin},
"8ball": {"prefix": True, "aliases": ["eightball", "8b"]}, "8ball": {"prefix": True, "aliases": ["eightball", "8b"]},
"join ": {"prefix": True, "aliases": [], "admin": True}, "join ": {"prefix": True, "aliases": [], "check": checks.admin},
"quote": {"prefix": True, "aliases": ["q"]}, "quote": {"prefix": True, "aliases": ["q"]},
"goat.mode.activate": {"prefix": True, "aliases": [], "admin": True}, "goat.mode.activate": {"prefix": True, "aliases": [], "check": checks.admin},
"goat.mode.deactivate": {"prefix": True, "aliases": [], "admin": True}, "goat.mode.deactivate": {"prefix": True, "aliases": [], "check": checks.admin},
"help": {"prefix": True, "aliases": []}, "help": {"prefix": True, "aliases": []},
"amiadmin": {"prefix": True, "aliases": []}, "amiadmin": {"prefix": True, "aliases": []},
"ping": {"prefix": True, "aliases": []}, "ping": {"prefix": True, "aliases": []},
"op me": {"prefix": False, "aliases": [], "admin": True}, "op me": {"prefix": False, "aliases": [], "check": checks.admin},
"whoami": {"prefix": True, "aliases": []}, "whoami": {"prefix": True, "aliases": []},
} }
checks: 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]] = {
"!botlist": botlist, "!botlist": botlist,
"bugs bugs bugs": bugs, "bugs bugs bugs": bugs,

View file

@ -66,11 +66,3 @@ def mfind(message: str, find: list, usePrefix: bool = True) -> bool:
return any(message[: len(match) + 1] == prefix + match for match in find) return any(message[: len(match) + 1] == prefix + match for match in find)
else: else:
return any(message[: len(match)] == match for match in find) return any(message[: len(match)] == match for match in find)
def adminCheck(bot: bare.bot, name: str, host: Optional[str] = "nul") -> bool:
return (
name.lower() in servers[bot.server]["admins"]
or host in admin_hosts
or host in servers[bot.server]["hosts"]
)

View file

@ -1,11 +1,11 @@
#!/usr/bin/python3
import random as r import random as r
import config as conf import config as conf
import re
import commands as cmds import commands as cmds
from typing import Union, Callable from typing import Union, Callable
from overrides import bytes, bbytes from overrides import bytes, bbytes
from importlib import reload from importlib import reload
import bare import bare, re, checks
def CTCP(bot: bare.bot, msg: str) -> bool: def CTCP(bot: bare.bot, msg: str) -> bool:
@ -46,14 +46,15 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[tuple[None, None], tuple[str, str]
name = msg.split("!", 1)[0][1:] name = msg.split("!", 1)[0][1:]
host = msg.split("@", 1)[1].split(" ", 1)[0] host = msg.split("@", 1)[1].split(" ", 1)[0]
bridge = False bridge = False
bot.current = "user"
if ( if (
(name.startswith("saxjax") and bot.server == "efnet") (name.startswith("saxjax") and bot.server == "efnet")
or (name == "ReplIRC" and bot.server == "replirc") or (name == "ReplIRC" and bot.server == "replirc")
or (name == "FirePyLink_" and bot.server == "ircnow") or (name in ["FirePyLink_", "FirePyLink"] and bot.server in ["ircnow", "backupbox"])
or (name == "FirePyLink" and bot.server == "backupbox")
): ):
if "<" in msg and ">" in msg: if "<" in msg and ">" in msg:
bridge = True bridge = True
bot.current = "bridge"
Nname = msg.split("<", 1)[1].split(">", 1)[0].strip() Nname = msg.split("<", 1)[1].split(">", 1)[0].strip()
if name == "ReplIRC": if name == "ReplIRC":
name = Nname[4:] name = Nname[4:]
@ -70,7 +71,7 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[tuple[None, None], tuple[str, str]
message = msg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip() message = msg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
chan = msg.split("PRIVMSG", 1)[1].split(":", 1)[0].strip() chan = msg.split("PRIVMSG", 1)[1].split(":", 1)[0].strip()
bot.log( bot.log(
f'Got "{bytes(message).lazy_decode()}" from "{name}" in "{chan}"', f'Got "{bytes(message).lazy_decode()}" from "{name}" in "{chan}" ({bot.current})',
) )
if len(name) > bot.nicklen: if len(name) > bot.nicklen:
bot.log(f"Name too long ({len(name)} > {bot.nicklen})") bot.log(f"Name too long ({len(name)} > {bot.nicklen})")
@ -101,18 +102,16 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[tuple[None, None], tuple[str, str]
cmds.data[cmd]["prefix"], cmds.data[cmd]["prefix"],
): ):
if ( if (
"admin" in cmds.data[cmd] and cmds.data[cmd]["admin"] "check" in cmds.data[cmd] and cmds.data[cmd]["check"]
) and not conf.adminCheck(bot, name, host): ):
bot.msg( if cmds.data[cmd]["check"](bot, name, host, chan, cmd):
f"Sorry {name}, you don't have permission to use {cmd.strip()}.", cmds.call[cmd](bot, chan, name, message)
chan,
)
else: else:
cmds.call[cmd](bot, chan, name, message) cmds.call[cmd](bot, chan, name, message)
handled = True handled = True
break break
if not handled: if not handled:
for check in cmds.checks: for check in cmds.regexes:
if re.search( if re.search(
check.replace("$MAX", str(bot.nicklen)).replace("$BOTNICK", bot.nick), check.replace("$MAX", str(bot.nicklen)).replace("$BOTNICK", bot.nick),
message, message,
@ -121,13 +120,8 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[tuple[None, None], tuple[str, str]
handled = True handled = True
break break
if not handled and conf.mfind(message, ["reload"]): if not handled and conf.mfind(message, ["reload"]):
if conf.adminCheck(bot, name, host): if checks.admin(bot, name, host, chan, "reload"):
return "reload", chan return "reload", chan
else:
bot.msg(
f"Sorry {name}, you don't have permission to use reload.",
chan,
)
handled = True handled = True
if not handled and len(message.split("\x01")) == 3: if not handled and len(message.split("\x01")) == 3:
if not CTCP(bot, message): if not CTCP(bot, message):