From d76cb084e2f6f733e51d6bde2b927b799f048ea7 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 16 Aug 2022 17:38:44 -0500 Subject: [PATCH] Add removal of activity roles for excluded role Only takes effect on message/voice --- tasks/activity.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tasks/activity.py b/tasks/activity.py index 2f2c938..52fa904 100644 --- a/tasks/activity.py +++ b/tasks/activity.py @@ -45,8 +45,15 @@ async def on_ready(event): # Listener for guild messages @plugin.listener(hikari.GuildMessageCreateEvent) async def on_message(event): - # Exclude bots, unselected guild, and excluded role - if event.is_bot or event.guild_id != c.config["guild"] or c.config["exclude"] in event.member.role_ids: + # Exclude bots and other guilds + if event.is_bot or event.guild_id != c.config["guild"]: + return + # Exclude and remove activity roles from excluded role + if c.config["exclude"] in event.member.role_ids: + if c.config["active"] in event.member.role_ids: + await event.member.remove_role(c.config["active"]) + if c.config["inactive"] in event.member.role_ids: + await event.member.remove_role(c.config["inactive"]) return # Insert current timestamp into db @@ -62,12 +69,15 @@ async def on_message(event): # Listener for voice state @plugin.listener(hikari.VoiceStateUpdateEvent) async def on_voice(event): - # Exclude bots, unselected guild, and excluded role - if ( - event.state.member.is_bot - or event.guild_id != c.config["guild"] - or c.config["exclude"] in event.state.member.role_ids - ): + # Exclude bots and other guilds + if event.state.member.is_bot or event.guild_id != c.config["guild"]: + return + # Exclude and remove activity roles from excluded role + if c.config["exclude"] in event.state.member.role_ids: + if c.config["active"] in event.state.member.role_ids: + await event.state.member.remove_role(c.config["active"]) + if c.config["inactive"] in event.state.member.role_ids: + await event.state.member.remove_role(c.config["inactive"]) return # Insert current timestamp into db