From f1d1380d9c3b1eaca0a05af8e95fa1b5bbe3c2f1 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 15 Oct 2020 04:36:28 +1300 Subject: [PATCH] [Away] per user filtering in servers (#166) * per member toggleaway * format and black * remove black format as requested --- away/away.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/away/away.py b/away/away.py index 655537b..45d9eb1 100644 --- a/away/away.py +++ b/away/away.py @@ -11,7 +11,7 @@ class Away(commands.Cog): """Le away cog""" default_global_settings = {"ign_servers": []} - default_guild_settings = {"TEXT_ONLY": False} + default_guild_settings = {"TEXT_ONLY": False, "BLACKLISTED_MEMBERS": []} default_user_settings = { "MESSAGE": False, "IDLE_MESSAGE": False, @@ -19,7 +19,7 @@ class Away(commands.Cog): "OFFLINE_MESSAGE": False, "GAME_MESSAGE": {}, "STREAMING_MESSAGE": False, - "LISTENING_MESSAGE": False, + "LISTENING_MESSAGE": False } async def red_delete_data_for_user( @@ -239,8 +239,9 @@ class Away(commands.Cog): if message.author.bot: return + bl_members = await self._away.guild(guild).BLACKLISTED_MEMBERS() for author in message.mentions: - if guild.id in list_of_guilds_ign and not await self.is_mod_or_admin(author): + if (guild.id in list_of_guilds_ign and not await self.is_mod_or_admin(author)) or author.id in bl_members: continue user_data = await self._away.user(author).all() text_only = await self._away.guild(guild).TEXT_ONLY() @@ -523,13 +524,26 @@ class Away(commands.Cog): @commands.command(name="toggleaway") @checks.admin_or_permissions(administrator=True) - async def _ignore(self, ctx): + async def _ignore(self, ctx, member: discord.Member=None): """ - Toggle away messages on the whole server. + Toggle away messages on the whole server or a specific guild member. Mods, Admins and Bot Owner are immune to this. """ guild = ctx.message.guild + if member: + bl_mems = await self._away.guild(guild).BLACKLISTED_MEMBERS() + if member.id not in bl_mems: + bl_mems.append(member.id) + await self._away.guild(guild).BLACKLISTED_MEMBERS.set(bl_mems) + msg = f"Away messages will not appear when {member.display_name} is mentioned in this guild." + await ctx.send(msg) + elif member.id in bl_mems: + bl_mems.remove(member.id) + await self._away.guild(guild).BLACKLISTED_MEMBERS.set(bl_mems) + msg = f"Away messages will appear when {member.display_name} is mentioned in this guild." + await ctx.send(msg) + return if guild.id in (await self._away.ign_servers()): guilds = await self._away.ign_servers() guilds.remove(guild.id) @@ -611,4 +625,4 @@ class Away(commands.Cog): em.set_author(name=f"{author.display_name}'s away settings", icon_url=author.avatar_url) await ctx.send(embed=em) else: - await ctx.send(f"{author.display_name} away settings\n" + msg) + await ctx.send(f"{author.display_name} away settings\n" + msg) \ No newline at end of file