Skip to content

Commit

Permalink
feat: offboarding: remove ex-admins from relay groups
Browse files Browse the repository at this point in the history
fix #6
  • Loading branch information
missytake committed Aug 20, 2024
1 parent c1ccfcb commit db8ff5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/team_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def ac_outgoing_message(self, message: deltachat.Message):
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."""
Expand Down Expand Up @@ -262,3 +267,7 @@ def get_relay_group(self, outside_id: int) -> deltachat.Chat:
if mapping[0] == outside_id:
return self.account.get_chat_by_id(mapping[1])
return None

def offboard(self, ex_admin):
for mapping in self.kvstore.get("relays"):
self.account.get_chat_by_id(mapping[1]).remove_contact(ex_admin)
7 changes: 7 additions & 0 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ def test_relay_group_forwarding(relaycrew, outsider):
for msg in chat.get_messages():
assert "This is the relay group for" not in msg.text

# user leaves crew
get_user_crew(user).remove_contact(user)
# make sure they are also offboarded from relay group
user._evtracker.wait_next_incoming_message()
for contact in bot_relay_group.get_contacts():
assert user.get_config("addr") != contact.addr


@pytest.mark.timeout(TIMEOUT)
def test_default_outside_help(relaycrew, outsider):
Expand Down

0 comments on commit db8ff5c

Please sign in to comment.