feat: new command to generate an invite link
This commit is contained in:
parent
defc179dcf
commit
85625578a8
|
@ -11,6 +11,7 @@ from .commands import (
|
||||||
crew_help,
|
crew_help,
|
||||||
set_display_name,
|
set_display_name,
|
||||||
set_avatar,
|
set_avatar,
|
||||||
|
generate_invite,
|
||||||
start_chat,
|
start_chat,
|
||||||
outside_help,
|
outside_help,
|
||||||
set_outside_help,
|
set_outside_help,
|
||||||
|
@ -108,6 +109,9 @@ class RelayPlugin:
|
||||||
if arguments[0] == "/set_avatar":
|
if arguments[0] == "/set_avatar":
|
||||||
result = set_avatar(self.account, message, self.crew)
|
result = set_avatar(self.account, message, self.crew)
|
||||||
self.reply(message.chat, result, quote=message)
|
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":
|
if arguments[0] == "/start_chat":
|
||||||
outside_chat, result = start_chat(
|
outside_chat, result = start_chat(
|
||||||
self.account,
|
self.account,
|
||||||
|
|
|
@ -15,6 +15,7 @@ def crew_help() -> str:
|
||||||
Start a chat:\t/start_chat alice@example.org,bob@example.org Chat_Title Hello friends!
|
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 name:\t/set_name Name
|
||||||
Change the bot's avatar:\t/set_avatar <attach image>
|
Change the bot's avatar:\t/set_avatar <attach image>
|
||||||
|
Generate invite link:\t\t/generate-invite
|
||||||
Show this help text:\t\t/help
|
Show this help text:\t\t/help
|
||||||
Change the help message for outsiders:\t/set_outside_help Hello outsider
|
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."
|
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(
|
def start_chat(
|
||||||
ac: deltachat.Account,
|
ac: deltachat.Account,
|
||||||
command: deltachat.Message,
|
command: deltachat.Message,
|
||||||
|
|
|
@ -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):
|
def test_public_invite(relaycrew, outsider):
|
||||||
crew = get_user_crew(relaycrew.user)
|
crew = get_user_crew(relaycrew.user)
|
||||||
crew.send_text("/generate-invite")
|
crew.send_text("/generate-invite")
|
||||||
result = relaycrew.user._evtracker.wait_next_incoming_message()
|
result = relaycrew.user._evtracker.wait_next_incoming_message()
|
||||||
assert result.filename
|
# assert result.filename
|
||||||
assert result.text.startswith("https://i.delta.chat")
|
assert result.text.startswith("https://i.delta.chat")
|
||||||
|
|
||||||
qr = result.filename
|
# qr = result.filename
|
||||||
chat = outsider.qr_setup_contact(qr)
|
invite = "OPENPGP4FPR:" + result.text[22::]
|
||||||
|
chat = outsider.qr_setup_contact(invite)
|
||||||
|
outsider._evtracker.wait_securejoin_joiner_progress(1000)
|
||||||
|
|
||||||
while not chat.is_protected():
|
while not chat.is_protected():
|
||||||
print(chat.get_messages()[:-1].text)
|
print(chat.get_messages()[-1].text)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
Loading…
Reference in a new issue