Sub certain phrases out when passed in
This commit is contained in:
parent
db4e3fff2b
commit
f248c68ea6
2 changed files with 9 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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})',
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue