General ease-of-use commit

This commit is contained in:
Firepup Sixfifty 2023-12-04 22:48:56 -06:00
parent e5b8930c6c
commit 42631780ff
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA
3 changed files with 10 additions and 9 deletions

View file

@ -8,9 +8,9 @@ import bare, re
def admin( def admin(
bot: bare.bot, bot: bare.bot,
name: str, name: str,
host: Optional[str] = "nul", host: Optional[str] = "",
chan: Optional[str] = "nul", chan: Optional[str] = "",
cmd: Optional[str] = "nul", cmd: Optional[str] = "",
) -> bool: ) -> bool:
if ( if (
name.lower() in conf.servers[bot.server]["admins"] name.lower() in conf.servers[bot.server]["admins"]
@ -20,13 +20,13 @@ def admin(
if bot.current != "bridge": if bot.current != "bridge":
return True return True
else: else:
if type(chan) != str or chan == "nul": if not chan:
return False return False
else: else:
bot.msg(f"Sorry {name}, bridged users can't use admin commands.", chan) bot.msg(f"Sorry {name}, bridged users can't use admin commands.", chan)
return False return False
else: else:
if type(chan) != str or chan == "nul": if not chan:
return False return False
else: else:
bot.msg(f"Sorry {name}, {cmd} is an admin only command.", chan) bot.msg(f"Sorry {name}, {cmd} is an admin only command.", chan)

View file

@ -67,8 +67,9 @@ def mfind(message: str, find: list, usePrefix: bool = True) -> bool:
else: else:
return any(message[: len(match)] == match for match in find) 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 = message.replace("$BOTNICK", bot.nick).replace("$NICK", bot.nick)
result = result.replace("$NICKLEN", str(bot.nicklen)).replace("$MAX", str(bot.nicklen))
if chan: if chan:
result = result.replace("$CHANNEL", chan).replace("$CHAN", chan) result = result.replace("$CHANNEL", chan).replace("$CHAN", chan)
if name: if name:

View file

@ -99,9 +99,9 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[tuple[None, None], tuple[str, str]
for cmd in cmds.data: for cmd in cmds.data:
triggers = [cmd] triggers = [cmd]
triggers.extend(cmds.data[cmd]["aliases"]) 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( if conf.mfind(
message.lower(), conf.sub(message, bot, chan, name).lower(),
triggers, triggers,
cmds.data[cmd]["prefix"], 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: if not handled:
for check in cmds.regexes: for check in cmds.regexes:
if re.search( if re.search(
check.replace("$MAX", str(bot.nicklen)).replace("$BOTNICK", bot.nick), conf.sub(check, bot, chan, name),
message, message,
): ):
cmds.call[check](bot, chan, name, message) cmds.call[check](bot, chan, name, message)