Compare commits
1 commit
main
...
dev-depend
Author | SHA1 | Date | |
---|---|---|---|
missytake | 5d9705d244 |
23
.github/workflows/ci.yml
vendored
23
.github/workflows/ci.yml
vendored
|
@ -1,23 +0,0 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ['3.8', '3.11']
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install '.[dev]'
|
||||
- run: tox
|
||||
|
|
@ -24,7 +24,7 @@ install_requires =
|
|||
pyinfra
|
||||
pickleDB
|
||||
qrcode
|
||||
deltachat>=1.142.7
|
||||
deltachat>=1.136.2
|
||||
|
||||
[options.extras_require]
|
||||
dev =
|
||||
|
|
|
@ -66,11 +66,6 @@ class RelayPlugin:
|
|||
relay_group = self.get_relay_group(message.chat.id)
|
||||
relay_group.send_text(f"Sending Message failed:\n\n{error}")
|
||||
|
||||
@account_hookimpl
|
||||
def ac_member_removed(self, chat, contact, actor, message):
|
||||
if chat == self.crew:
|
||||
self.offboard(contact)
|
||||
|
||||
@account_hookimpl
|
||||
def ac_incoming_message(self, message: deltachat.Message):
|
||||
"""This method is called on every incoming message and decides what to do with it."""
|
||||
|
@ -156,7 +151,6 @@ class RelayPlugin:
|
|||
else:
|
||||
logging.debug("Ignoring message, just the crew chatting")
|
||||
else:
|
||||
self.mark_last_messages_read(message.chat)
|
||||
logging.debug("Ignoring message, just the crew chatting")
|
||||
|
||||
else:
|
||||
|
@ -240,10 +234,21 @@ class RelayPlugin:
|
|||
|
||||
def is_relay_group(self, chat: deltachat.Chat) -> bool:
|
||||
"""Check whether a chat is a relay group."""
|
||||
for mapping in self.kvstore.get("relays"):
|
||||
if mapping[1] == chat.id:
|
||||
return True
|
||||
return False
|
||||
if not chat.get_name().startswith(
|
||||
"[%s] " % (self.account.get_config("addr").split("@")[0],)
|
||||
):
|
||||
return False # all relay groups' names begin with a [tag] with the localpart of the team-bot's address
|
||||
if (
|
||||
chat.get_messages()[0].get_sender_contact()
|
||||
!= self.account.get_self_contact()
|
||||
):
|
||||
return False # all relay groups were started by the team-bot
|
||||
if chat.is_protected():
|
||||
return False # relay groups don't need to be protected, so they are not
|
||||
for crew_member in self.crew.get_contacts():
|
||||
if crew_member not in chat.get_contacts():
|
||||
return False # all crew members have to be in any relay group
|
||||
return True
|
||||
|
||||
def get_outside_chat(self, relay_group_id: int) -> deltachat.Chat:
|
||||
"""Get the corresponding outside chat for the ID of a relay group.
|
||||
|
@ -268,22 +273,3 @@ class RelayPlugin:
|
|||
if mapping[0] == outside_id:
|
||||
return self.account.get_chat_by_id(mapping[1])
|
||||
return None
|
||||
|
||||
def offboard(self, ex_admin: deltachat.Contact) -> None:
|
||||
"""Remove a former crew member from all relay groups they are part of.
|
||||
|
||||
:param ex_admin: a contact which just got removed from the crew.
|
||||
"""
|
||||
for mapping in self.kvstore.get("relays"):
|
||||
relay_group = self.account.get_chat_by_id(mapping[1])
|
||||
if ex_admin in relay_group.get_contacts():
|
||||
relay_group.remove_contact(ex_admin)
|
||||
|
||||
def mark_last_messages_read(self, relay_group: deltachat.Chat) -> None:
|
||||
"""Mark the last incoming messages as read for a corresponding relay group.
|
||||
|
||||
:param relay_group: the relay group in which the messages which should marked read were forwarded.
|
||||
"""
|
||||
outside_chat = self.get_outside_chat(relay_group.id)
|
||||
for msg in outside_chat.get_messages():
|
||||
msg.mark_seen()
|
||||
|
|
|
@ -6,7 +6,9 @@ from pyinfra import host
|
|||
from pyinfra.facts.systemd import SystemdStatus
|
||||
|
||||
|
||||
def deploy_team_bot(unix_user: str, bot_email: str, bot_passwd: str, dbdir: str = None):
|
||||
def deploy_team_bot(
|
||||
unix_user: str, bot_email: str, bot_passwd: str, dbdir: str = None
|
||||
):
|
||||
"""Deploy TeamsBot to a UNIX user, with specified credentials
|
||||
|
||||
:param unix_user: the existing UNIX user of the bot
|
||||
|
|
|
@ -6,10 +6,10 @@ import pytest
|
|||
from deltachat.capi import lib as dclib
|
||||
|
||||
|
||||
TIMEOUT = 40
|
||||
TIMEOUT = 20
|
||||
|
||||
|
||||
def get_user_crew(crewuser: deltachat.Account, id=11) -> deltachat.Chat:
|
||||
def get_user_crew(crewuser: deltachat.Account) -> deltachat.Chat:
|
||||
"""Get the Team chat from the team member's point of view.
|
||||
|
||||
:param crewuser: the account object of the team member
|
||||
|
@ -17,7 +17,7 @@ def get_user_crew(crewuser: deltachat.Account, id=11) -> deltachat.Chat:
|
|||
"""
|
||||
for chat in crewuser.get_chats():
|
||||
print(chat.id, chat.get_name())
|
||||
user_crew = crewuser.get_chat_by_id(id)
|
||||
user_crew = crewuser.get_chat_by_id(11)
|
||||
assert user_crew.get_name().startswith("Team")
|
||||
return user_crew
|
||||
|
||||
|
@ -27,65 +27,38 @@ def test_not_relay_groups(relaycrew, outsider, lp):
|
|||
bot = relaycrew.bot
|
||||
user = relaycrew.user
|
||||
|
||||
def find_msg(ac, text):
|
||||
for chat in ac.get_chats():
|
||||
for msg in chat.get_messages():
|
||||
if msg.text == text:
|
||||
return msg
|
||||
|
||||
text = "outsider -> bot 1:1 chat"
|
||||
lp.sec(text)
|
||||
lp.sec("bot <-> outsider 1:1 chat")
|
||||
outsider_botcontact = outsider.create_contact(bot.get_config("addr"))
|
||||
outsider_outside_chat = outsider.create_chat(outsider_botcontact)
|
||||
outsider_outside_chat.send_text(text)
|
||||
lp.sec("receiving message from outsider in 1:1 chat")
|
||||
outsider_outside_chat.send_text("test 1:1 message to bot")
|
||||
|
||||
bot_message_from_outsider = bot._evtracker.wait_next_incoming_message()
|
||||
bot_outside_chat = bot_message_from_outsider.chat
|
||||
assert bot_message_from_outsider.text == text
|
||||
assert not bot.relayplugin.is_relay_group(bot_outside_chat)
|
||||
|
||||
lp.sec("leave relay group with user")
|
||||
relayed_msg = find_msg(user, text)
|
||||
if not relayed_msg:
|
||||
relayed_msg = user._evtracker.wait_next_incoming_message()
|
||||
relayed_msg.chat.remove_contact(user.get_config("addr"))
|
||||
leave_msg = bot._evtracker.wait_next_incoming_message()
|
||||
assert bot.relayplugin.is_relay_group(leave_msg.chat)
|
||||
|
||||
text = "outsider -> bot group chat"
|
||||
lp.sec(text)
|
||||
lp.sec("bot <-> outsider group chat")
|
||||
outsider_bot_group = outsider.create_group_chat(
|
||||
"test with outsider", contacts=[outsider_botcontact]
|
||||
)
|
||||
outsider_bot_group.send_text(text)
|
||||
lp.sec("receiving message from outsider in group chat")
|
||||
outsider_bot_group.send_text("test message to outsider group")
|
||||
bot_message_from_outsider = bot._evtracker.wait_next_incoming_message()
|
||||
assert bot_message_from_outsider.text == text
|
||||
assert not bot.relayplugin.is_relay_group(bot_message_from_outsider.chat)
|
||||
|
||||
text = "user -> bot 1:1 chat"
|
||||
lp.sec(text)
|
||||
lp.sec("bot <-> user 1:1 chat")
|
||||
user_botcontact = user.create_contact(bot.get_config("addr"))
|
||||
user_to_bot = user.create_chat(user_botcontact)
|
||||
user_to_bot.send_text(text)
|
||||
lp.sec("receiving message from user in 1:1 chat")
|
||||
|
||||
user_to_bot.send_text("test message to bot")
|
||||
# somehow the message doesn't trigger DC_EVENT_INCOMING_MSG
|
||||
# bot._evtracker.wait_next_incoming_message()
|
||||
bot_message_from_user = find_msg(bot, text)
|
||||
while not bot_message_from_user:
|
||||
bot_message_from_user = find_msg(bot, text)
|
||||
bot_message_from_user = bot.get_chats()[-3].get_messages()[-1] # bot._evtracker.wait_next_incoming_message()
|
||||
while bot_message_from_user.text != "test message to bot":
|
||||
bot_message_from_user = bot.get_chats()[-3].get_messages()[-1] # bot._evtracker.wait_next_incoming_message()
|
||||
time.sleep(1)
|
||||
assert bot_message_from_user.text == text
|
||||
assert not bot.relayplugin.is_relay_group(bot_message_from_user.chat)
|
||||
|
||||
text = "user -> bot group chat"
|
||||
lp.sec(text)
|
||||
lp.sec("bot <-> user group chat")
|
||||
user_group = user.create_group_chat("test with user", contacts=[user_botcontact])
|
||||
user_group.send_text(text)
|
||||
lp.sec("receiving message from user in group chat")
|
||||
user_group.send_text("testing message to user group")
|
||||
bot_message_from_user = bot._evtracker.wait_next_incoming_message()
|
||||
assert bot_message_from_user.text == text
|
||||
assert not bot.relayplugin.is_relay_group(bot_message_from_user.chat)
|
||||
|
||||
|
||||
|
@ -103,7 +76,6 @@ def test_relay_group_forwarding(relaycrew, outsider):
|
|||
message_from_outsider = bot._evtracker.wait_next_incoming_message()
|
||||
bot_outside_chat = message_from_outsider.chat
|
||||
assert not bot.relayplugin.is_relay_group(bot_outside_chat)
|
||||
assert message_from_outsider.is_in_fresh()
|
||||
|
||||
# get relay group
|
||||
user_forwarded_message_from_outsider = user._evtracker.wait_next_incoming_message()
|
||||
|
@ -133,7 +105,6 @@ def test_relay_group_forwarding(relaycrew, outsider):
|
|||
user._dc_context, user_relay_group.id, user_direct_reply._dc_msg
|
||||
)
|
||||
assert sent_id == user_direct_reply.id
|
||||
assert message_from_outsider.is_in_seen()
|
||||
|
||||
# check that direct reply was forwarded to outsider
|
||||
outsider_direct_reply = outsider._evtracker.wait_next_incoming_message()
|
||||
|
@ -159,43 +130,6 @@ def test_relay_group_forwarding(relaycrew, outsider):
|
|||
assert "This is the relay group for" not in msg.text
|
||||
|
||||
|
||||
@pytest.mark.timeout(TIMEOUT)
|
||||
def test_offboarding(team_bot, relaycrew, outsider, team_user):
|
||||
# outsider sends message, creates relay group
|
||||
outsider_botcontact = outsider.create_contact(team_bot.get_config("addr"))
|
||||
outsider_outside_chat = outsider.create_chat(outsider_botcontact)
|
||||
outsider_outside_chat.send_text("test 1:1 message to bot")
|
||||
|
||||
# get relay group
|
||||
user_relay_group = team_user._evtracker.wait_next_incoming_message().chat
|
||||
bot_relay_group = team_bot.get_chats()[-1]
|
||||
|
||||
# outsider gets added to crew
|
||||
qr = relaycrew.get_join_qr()
|
||||
outsider.qr_join_chat(qr)
|
||||
outsider._evtracker.wait_securejoin_joiner_progress(1000)
|
||||
|
||||
# user kicks outsider from crew
|
||||
user_crew = get_user_crew(team_user)
|
||||
user_crew.remove_contact(team_user.create_contact(outsider))
|
||||
team_bot._evtracker.wait_next_incoming_message()
|
||||
|
||||
# user leaves crew
|
||||
user_crew.remove_contact(team_user)
|
||||
# make sure they are also offboarded from relay group
|
||||
team_bot._evtracker.wait_next_incoming_message()
|
||||
team_user._evtracker.wait_next_incoming_message()
|
||||
team_user._evtracker.wait_next_incoming_message()
|
||||
team_user._evtracker.wait_next_incoming_message()
|
||||
for contact in bot_relay_group.get_contacts():
|
||||
assert team_user.get_config("addr") != contact.addr
|
||||
|
||||
# make sure there is no message in relay group that outsider was kicked
|
||||
for msg in user_relay_group.get_messages():
|
||||
print(msg.text)
|
||||
assert outsider.get_config("addr") + " removed by " not in msg.text
|
||||
|
||||
|
||||
@pytest.mark.timeout(TIMEOUT)
|
||||
def test_default_outside_help(relaycrew, outsider):
|
||||
bot = relaycrew.bot
|
||||
|
|
Loading…
Reference in a new issue