Ryan Barrett 2024-11-14 10:59:47 -08:00
rodzic 6e31d21aba
commit 0e2ba03586
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 23 dodań i 12 usunięć

23
dms.py
Wyświetl plik

@ -108,28 +108,22 @@ def receive(*, from_user, obj):
else obj.as1)
logger.info(f'got DM from {from_user.key.id()} to {to_proto.LABEL}: {inner_obj.get("content")}')
soup = util.parse_html(inner_obj.get('content', ''))
content = soup.get_text().strip().lower()
if not content:
return r'¯\_(ツ)_/¯', 204
def reply(text, type=None):
maybe_send(from_proto=to_proto, to_user=from_user, text=text, type=type,
in_reply_to=inner_obj.get('id'))
return 'OK', 200
# parse and handle message
soup = util.parse_html(inner_obj.get('content', ''))
content = soup.get_text().strip().lower()
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:
if tokens and tokens[0].lstrip('@') in bot_handles:
logger.info(f' first token is bot mention, removing')
tokens = tokens[1:]
if not tokens:
return r'¯\_(ツ)_/¯', 204
if tokens[0].lstrip('/') in COMMANDS:
cmd = tokens[0].lstrip('/')
arg = tokens[1] if len(tokens) > 1 else None
@ -138,6 +132,11 @@ def receive(*, from_user, obj):
arg = tokens[0]
# handle commands
def reply(text, type=None):
maybe_send(from_proto=to_proto, to_user=from_user, text=text, type=type,
in_reply_to=inner_obj.get('id'))
return 'OK', 200
if cmd in ('?', 'help', 'commands', 'info', 'hi', 'hello'):
extra = ''
if to_proto.LABEL == 'atproto':

Wyświetl plik

@ -129,6 +129,18 @@ class DmsTest(TestCase):
self.assertEqual([], OtherFake.sent)
self.assertEqual([], Fake.sent)
def test_receive_empty_strip_mention_of_bot(self):
alice, bob = self.make_alice_bob()
obj = Object(our_as1={
**DM_BASE,
'content': '<a href="https://other.brid.gy/other.brid.gy">@other.brid.gy</a> ',
})
self.assertEqual(('¯\\_(ツ)_/¯', 204), receive(from_user=alice, obj=obj))
self.assert_replied(OtherFake, alice, '?', ALICE_CONFIRMATION_CONTENT)
self.assert_sent(ExplicitFake, bob, 'request_bridging',
ALICE_REQUEST_CONTENT)
def test_receive_unknown_text(self):
self.make_user(id='other.brid.gy', cls=Web)
alice = self.make_user('efake:alice', cls=ExplicitFake,