Sub certain phrases out when passed in

This commit is contained in:
Firepup Sixfifty 2023-11-24 01:15:33 -06:00
parent db4e3fff2b
commit f248c68ea6
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA
2 changed files with 9 additions and 0 deletions

View file

@ -66,3 +66,11 @@ def mfind(message: str, find: list, usePrefix: bool = True) -> bool:
return any(message[: len(match) + 1] == prefix + match for match in find)
else:
return any(message[: len(match)] == match for match in find)
def sub(message: str, bot: bare.bot, chan: Optional[str], name: Optional[str]):
result = message.replace("$BOTNICK", bot.nick).replace("$NICK", bot.nick)
if chan:
result = result.replace("$CHANNEL", chan).replace("$CHAN", chan)
if name:
result = result.replace("$SENDER", name).replace("$NAME", name)
return result

View file

@ -73,6 +73,7 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[tuple[None, None], tuple[str, str]
else:
message = msg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
chan = msg.split("PRIVMSG", 1)[1].split(":", 1)[0].strip()
message = conf.sub(message, bot, chan, name)
bot.log(
f'Got "{bytes(message).lazy_decode()}" from "{name}" in "{chan}" ({bot.current})',
)