From 85625578a8b3e1f5cb7efae1da3975979ec795d0 Mon Sep 17 00:00:00 2001 From: missytake Date: Tue, 30 Apr 2024 10:10:58 +0200 Subject: [PATCH] feat: new command to generate an invite link --- src/team_bot/bot.py | 4 ++++ src/team_bot/commands.py | 11 +++++++++++ tests/test_bot.py | 12 +++++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/team_bot/bot.py b/src/team_bot/bot.py index 29536c8..351fd87 100644 --- a/src/team_bot/bot.py +++ b/src/team_bot/bot.py @@ -11,6 +11,7 @@ from .commands import ( crew_help, set_display_name, set_avatar, + generate_invite, start_chat, outside_help, set_outside_help, @@ -108,6 +109,9 @@ class RelayPlugin: 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, diff --git a/src/team_bot/commands.py b/src/team_bot/commands.py index ec221f5..907c3b0 100644 --- a/src/team_bot/commands.py +++ b/src/team_bot/commands.py @@ -15,6 +15,7 @@ def crew_help() -> str: Start a chat:\t/start_chat alice@example.org,bob@example.org Chat_Title Hello friends! Change the bot's name:\t/set_name Name Change the bot's avatar:\t/set_avatar +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 """ @@ -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, diff --git a/tests/test_bot.py b/tests/test_bot.py index 3662160..8034513 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -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)