Skip to content

Commit

Permalink
feat: new command to generate an invite link
Browse files Browse the repository at this point in the history
  • Loading branch information
missytake committed Apr 30, 2024
1 parent defc179 commit 8562557
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/team_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
crew_help,
set_display_name,
set_avatar,
generate_invite,
start_chat,
outside_help,
set_outside_help,
Expand Down Expand Up @@ -108,6 +109,9 @@ def ac_incoming_message(self, message: deltachat.Message):
if arguments[0] == "/set_avatar":
result = set_avatar(self.account, message, self.crew)
self.reply(message.chat, result, quote=message)
if arguments[0] == "/generate-invite":
text = generate_invite(self.account)
self.reply(message.chat, text, quote=message)
if arguments[0] == "/start_chat":
outside_chat, result = start_chat(
self.account,
Expand Down
11 changes: 11 additions & 0 deletions src/team_bot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def crew_help() -> str:
Start a chat:\t/start_chat [email protected],[email protected] Chat_Title Hello friends!
Change the bot's name:\t/set_name Name
Change the bot's avatar:\t/set_avatar <attach image>
Generate invite link:\t\t/generate-invite
Show this help text:\t\t/help
Change the help message for outsiders:\t/set_outside_help Hello outsider
"""
Expand Down Expand Up @@ -63,6 +64,16 @@ def set_avatar(
return "Avatar changed to this image."


def generate_invite(account: deltachat.Account) -> str:
"""Return a https://i.delta.chat invite link for chatting with the bot.
:return: the invite link, e.g.: https://i.delta.chat
"""
openpgp4fpr = account.get_setup_contact_qr()
invite = "https://i.delta.chat/#" + openpgp4fpr[12::]
return invite


def start_chat(
ac: deltachat.Account,
command: deltachat.Message,
Expand Down
12 changes: 7 additions & 5 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,19 @@ def test_forward_sending_errors_to_relay_group(relaycrew):
)


@pytest.mark.timeout(TIMEOUT * 2)
@pytest.mark.timeout(TIMEOUT)
def test_public_invite(relaycrew, outsider):
crew = get_user_crew(relaycrew.user)
crew.send_text("/generate-invite")
result = relaycrew.user._evtracker.wait_next_incoming_message()
assert result.filename
# assert result.filename
assert result.text.startswith("https://i.delta.chat")

qr = result.filename
chat = outsider.qr_setup_contact(qr)
# qr = result.filename
invite = "OPENPGP4FPR:" + result.text[22::]
chat = outsider.qr_setup_contact(invite)
outsider._evtracker.wait_securejoin_joiner_progress(1000)

while not chat.is_protected():
print(chat.get_messages()[:-1].text)
print(chat.get_messages()[-1].text)
time.sleep(1)

0 comments on commit 8562557

Please sign in to comment.