diff --git a/config.py b/config.py index 37b6039..798aa31 100644 --- a/config.py +++ b/config.py @@ -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 diff --git a/handlers.py b/handlers.py index 5b6730d..3d360e5 100644 --- a/handlers.py +++ b/handlers.py @@ -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})', )