From 50b0194c7d2c80741e48836cfe948e638e072781 Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Thu, 25 Mar 2021 10:50:55 +0100 Subject: [PATCH] Support allowed_mentions and reference when sending. --- bot.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index 995e01f..9a63a51 100644 --- a/bot.py +++ b/bot.py @@ -592,7 +592,7 @@ def typing_context_manager(channel, typing = None): return DummyContextManager() if typing else channel.typing() # join may be passed by cat.maybe_purr() etc. -async def maybe_say(channel, text, *, typing = None, attachment = None, embed = None, probability = 0.2, wake = True, join = None): +async def maybe_say(channel, text, *, typing = None, attachment = None, embed = None, allowed_mentions = None, reference = None, probability = 0.2, wake = True, join = None): if random.random() <= probability: message = None try: @@ -601,6 +601,10 @@ async def maybe_say(channel, text, *, typing = None, attachment = None, embed = async with typing_context_manager(channel, typing): if embed: send['embed'] = embed + if allowed_mentions: + send['allowed_mentions'] = allowed_mentions + if reference: + send['reference'] = reference if attachment is not None: parsed = parse_attachment(attachment) if parsed is not None: @@ -625,7 +629,7 @@ async def maybe_say(channel, text, *, typing = None, attachment = None, embed = log.debug("Didn't bother to say {}".format(text)) return None -async def say(channel, text, *, typing = None, attachment = None, embed = None, wake = None, join = None): +async def say(channel, text, *, typing = None, attachment = None, embed = None, allowed_mentions = None, reference = None, wake = None, join = None): args = { 'probability': 1.0 } if typing is not None: args['typing'] = typing @@ -633,12 +637,16 @@ async def say(channel, text, *, typing = None, attachment = None, embed = None, args['attachment'] = attachment if embed is not None: args['embed'] = embed + if allowed_mentions: + args['allowed_mentions'] = allowed_mentions + if reference: + args['reference'] = reference if wake is not None: args['wake'] = wake message = await maybe_say(channel, text, **args) return message -async def say_many(channel, lines, *, typing = None, attachment = None, embed = None, maxlen = 2000): +async def say_many(channel, lines, *, typing = None, attachment = None, embed = None, allowed_mentions = None, reference = None, maxlen = 2000): async with typing_context_manager(channel, typing) as context_manager: while len(lines): message_len = 0 @@ -654,7 +662,7 @@ async def say_many(channel, lines, *, typing = None, attachment = None, embed = # We can't print too big a message. subset = lines[:n] message = '\n'.join(subset) - result = await say(channel, message, typing = context_manager, attachment = attachment, embed = embed) + result = await say(channel, message, typing = context_manager, attachment = attachment, embed = embed, allowed_mentions = allowed_mentions, reference = reference) if not result: break lines = lines[len(subset):] -- 2.7.4