diff --git a/src/team_bot/bot.py b/src/team_bot/bot.py index 4c79d5e..fa2ca26 100644 --- a/src/team_bot/bot.py +++ b/src/team_bot/bot.py @@ -66,6 +66,11 @@ 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.""" @@ -262,3 +267,7 @@ class RelayPlugin: 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) diff --git a/tests/test_bot.py b/tests/test_bot.py index 7f8621a..1632f76 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -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):