Skip to content

Commit

Permalink
DMs bug fix for when a command that needs an arg doesn't get one
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Feb 5, 2025
1 parent 709e06b commit 28f410f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def reply(text, type=None):
elif user_bridged is False and from_user_enabled:
return reply(f"Looks like you're already bridged to {to_proto.PHRASE}!")
elif arg and not cmd_arg:
return reply(f'{cmd} command needs an argument<br><br>{help(from_user, to_proto)}')
return reply(f'{cmd} command needs an argument<br><br>{help(from_user, to_proto, cmd, cmd_arg, dm_as1)}')

# dispatch!
kwargs = {}
Expand Down
11 changes: 11 additions & 0 deletions tests/test_dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,17 @@ def test_receive_username(self):
self.assert_replied(OtherFake, alice, '?', ALICE_USERNAME_CONFIRMATION_CONTENT)
self.assertEqual({'efake:alice': 'new-handle'}, OtherFake.usernames)

def test_receive_username_no_arg(self):
self.make_user(id='other.brid.gy', cls=Web)
alice = self.make_user(id='efake:alice', cls=ExplicitFake,
enabled_protocols=['other'], obj_as1={'x': 'y'})

self.assertEqual(('OK', 200), receive(from_user=alice, obj=Object(our_as1={
**DM_BASE,
'content': 'username',
})))
self.assert_replied(OtherFake, alice, '?', "<p>Hi! I'm a friendly bot")

def test_receive_username_not_implemented(self):
self.make_user(id='fa.brid.gy', cls=Web)
alice = self.make_user(id='efake:alice', cls=ExplicitFake,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from .test_activitypub import ACTOR, NOTE
from .test_atproto import DID_DOC
from .test_dms import DmsTest
from . import test_dms
from .test_web import (
ACTOR_HTML_RESP,
ACTOR_AS1_UNWRAPPED_URLS,
Expand Down Expand Up @@ -1197,7 +1197,7 @@ def test_reply_from_non_bridged_post_isnt_bridged_but_gets_dm_prompt(self):
self.assertEqual(204, code)

self.assertEqual([], Fake.sent)
DmsTest().assert_sent(Fake, eve, 'replied_to_bridged_user', """Hi! You <a href="efake:reply">recently replied</a> to <a class="h-card u-author" href="fake:user">fake:user</a>, who's bridged here from fake-phrase. If you want them to see your replies, you can bridge your account into fake-phrase by following this account. <a href="https://fed.brid.gy/docs">See the docs</a> for more information.""")
test_dms.DmsTest().assert_sent(Fake, eve, 'replied_to_bridged_user', """Hi! You <a href="efake:reply">recently replied</a> to <a class="h-card u-author" href="fake:user">fake:user</a>, who's bridged here from fake-phrase. If you want them to see your replies, you can bridge your account into fake-phrase by following this account. <a href="https://fed.brid.gy/docs">See the docs</a> for more information.""")

eve = eve.key.get()
self.assertEqual([DM(protocol='fake', type='replied_to_bridged_user')],
Expand Down Expand Up @@ -2889,7 +2889,7 @@ def test_follow_and_block_protocol_user_sets_enabled_protocols(self):
], ExplicitFake.sent[1:])

ExplicitFake.sent = ExplicitFake.sent[:1]
DmsTest().assert_sent(Fake, user, 'welcome', 'Welcome to Bridgy Fed! Your account will soon be bridged to fake-phrase at <a class="h-card u-author" rel="me" href="web:fake:efake:user" title="fake:handle:efake:handle:user">fake:handle:efake:handle:user</a>. <a href="https://fed.brid.gy/docs">See the docs</a> and <a href="https://fed.brid.gy/efake/efake:handle:user">your user page</a> for more information. To disable this and delete your bridged profile, block this account.')
test_dms.DmsTest().assert_sent(Fake, user, 'welcome', 'Welcome to Bridgy Fed! Your account will soon be bridged to fake-phrase at <a class="h-card u-author" rel="me" href="web:fake:efake:user" title="fake:handle:efake:handle:user">fake:handle:efake:handle:user</a>. <a href="https://fed.brid.gy/docs">See the docs</a> and <a href="https://fed.brid.gy/efake/efake:handle:user">your user page</a> for more information. To disable this and delete your bridged profile, block this account.')

# another follow should be a noop
follow['id'] += '2'
Expand Down

0 comments on commit 28f410f

Please sign in to comment.