From 6e31d21aba3c9d7da7406ca62562a454be165e18 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Thu, 14 Nov 2024 09:36:11 -0800 Subject: [PATCH] DMs bug fix for prompting user with leading bot @-mention --- dms.py | 132 ++++++++++++++++++++++++++-------------------- tests/test_dms.py | 16 +++++- 2 files changed, 89 insertions(+), 59 deletions(-) diff --git a/dms.py b/dms.py index 3c6f62b0..79df83f5 100644 --- a/dms.py +++ b/dms.py @@ -17,6 +17,17 @@ REQUESTS_LIMIT_EXPIRE = timedelta(days=1) REQUESTS_LIMIT_USER = 10 +COMMANDS = ( + 'did', + 'help', + 'no', + 'ok', + 'start', + 'stop', + 'username', + 'yes', +) + def maybe_send(*, from_proto, to_user, text, type=None, in_reply_to=None): """Sends a DM. @@ -110,21 +121,27 @@ def reply(text, type=None): # parse and handle message tokens = content.split() + logger.info(f' tokens: {tokens}') # remove @-mention of bot, if any bot_handles = (DOMAINS + ids.BOT_ACTOR_AP_IDS + tuple(h.lstrip('@') for h in ids.BOT_ACTOR_AP_HANDLES)) if tokens[0].lstrip('@') in bot_handles: + logger.info(f' first token is bot mention, removing') tokens = tokens[1:] - cmd = tokens[0].lstrip('/') - arg = tokens[1] if len(tokens) > 1 else None - - extra = '' - if to_proto.LABEL == 'atproto': - extra = """
  • did: get your bridged Bluesky account's DID""" + if tokens[0].lstrip('/') in COMMANDS: + cmd = tokens[0].lstrip('/') + arg = tokens[1] if len(tokens) > 1 else None + else: + cmd = None + arg = tokens[0] + # handle commands if cmd in ('?', 'help', 'commands', 'info', 'hi', 'hello'): + extra = '' + if to_proto.LABEL == 'atproto': + extra = """
  • did: get your bridged Bluesky account's DID""" return reply(f"""\

    Hi! I'm a friendly bot that can help you bridge your account into {to_proto.PHRASE}. Here are some commands I respond to: