diff --git a/checks.py b/checks.py index e325a74..72ea969 100644 --- a/checks.py +++ b/checks.py @@ -8,9 +8,9 @@ import bare, re def admin( bot: bare.bot, name: str, - host: Optional[str] = "nul", - chan: Optional[str] = "nul", - cmd: Optional[str] = "nul", + host: Optional[str] = "", + chan: Optional[str] = "", + cmd: Optional[str] = "", ) -> bool: if ( name.lower() in conf.servers[bot.server]["admins"] @@ -20,13 +20,13 @@ def admin( if bot.current != "bridge": return True else: - if type(chan) != str or chan == "nul": + if not chan: 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": + if not chan: return False else: bot.msg(f"Sorry {name}, {cmd} is an admin only command.", chan) diff --git a/config.py b/config.py index 0236fbb..9a853f8 100644 --- a/config.py +++ b/config.py @@ -67,8 +67,9 @@ def mfind(message: str, find: list, usePrefix: bool = True) -> bool: else: return any(message[: len(match)] == match for match in find) -def sub(message: str, bot: bare.bot, chan: Optional[str], name: Optional[str]): +def sub(message: str, bot: bare.bot, chan: Optional[str] = "", name: Optional[str] = "") -> str: result = message.replace("$BOTNICK", bot.nick).replace("$NICK", bot.nick) + result = result.replace("$NICKLEN", str(bot.nicklen)).replace("$MAX", str(bot.nicklen)) if chan: result = result.replace("$CHANNEL", chan).replace("$CHAN", chan) if name: diff --git a/handlers.py b/handlers.py index 3d360e5..a0bab1e 100644 --- a/handlers.py +++ b/handlers.py @@ -99,9 +99,9 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[tuple[None, None], tuple[str, str] for cmd in cmds.data: triggers = [cmd] triggers.extend(cmds.data[cmd]["aliases"]) - triggers = list(call.replace("$BOTNICK", bot.nick.lower()) for call in triggers) + triggers = list(conf.sub(call, bot, chan, name).lower() for call in triggers) if conf.mfind( - message.lower(), + conf.sub(message, bot, chan, name).lower(), triggers, cmds.data[cmd]["prefix"], ): @@ -115,7 +115,7 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[tuple[None, None], tuple[str, str] if not handled: for check in cmds.regexes: if re.search( - check.replace("$MAX", str(bot.nicklen)).replace("$BOTNICK", bot.nick), + conf.sub(check, bot, chan, name), message, ): cmds.call[check](bot, chan, name, message)