[Mutes] Prevent modlog updates on unmute due to category channel sync (#4539)

* [Mutes] Prevent modlog updates on unmute due to category channel sync

* Try here

* would help to remember to change all the right things
This commit is contained in:
TrustyJAID 2020-10-26 18:18:55 -06:00 committed by GitHub
parent 0b0ace10dd
commit fd77e97712
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,6 +90,10 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
self._unmute_tasks: Dict[str, asyncio.Task] = {} self._unmute_tasks: Dict[str, asyncio.Task] = {}
self._unmute_task = None self._unmute_task = None
self.mute_role_cache: Dict[int, int] = {} self.mute_role_cache: Dict[int, int] = {}
self._channel_mute_events: Dict[int, asyncio.Event] = {}
# this is a dict of guild ID's and asyncio.Events
# to wait for a guild to finish channel unmutes before
# checking for manual overwrites
async def red_delete_data_for_user( async def red_delete_data_for_user(
self, self,
@ -322,6 +326,10 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
self, member: discord.Member, guild: discord.Guild, channels: Dict[int, dict] self, member: discord.Member, guild: discord.Guild, channels: Dict[int, dict]
): ):
"""This is meant to handle multiple channels all being unmuted at once""" """This is meant to handle multiple channels all being unmuted at once"""
if guild.id in self._channel_mute_events:
self._channel_mute_events[guild.id].clear()
else:
self._channel_mute_events[guild.id] = asyncio.Event()
tasks = [] tasks = []
for channel, mute_data in channels.items(): for channel, mute_data in channels.items():
author = guild.get_member(mute_data["author"]) author = guild.get_member(mute_data["author"])
@ -351,6 +359,7 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
modlog_reason, modlog_reason,
until=None, until=None,
) )
self._channel_mute_events[guild.id].set()
if any(results): if any(results):
reasons = {} reasons = {}
for result in results: for result in results:
@ -515,6 +524,8 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
if await self.bot.cog_disabled_in_guild(self, after.guild): if await self.bot.cog_disabled_in_guild(self, after.guild):
return return
await i18n.set_contextual_locales_from_guild(self.bot, after.guild) await i18n.set_contextual_locales_from_guild(self.bot, after.guild)
if after.guild.id in self._channel_mute_events:
await self._channel_mute_events[after.guild.id].wait()
if after.id in self._channel_mutes: if after.id in self._channel_mutes:
before_perms: Dict[int, Dict[str, Optional[bool]]] = { before_perms: Dict[int, Dict[str, Optional[bool]]] = {
o.id: {name: attr for name, attr in p} for o, p in before.overwrites.items() o.id: {name: attr for name, attr in p} for o, p in before.overwrites.items()
@ -1161,6 +1172,10 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
audit_reason = get_audit_reason(author, reason) audit_reason = get_audit_reason(author, reason)
issue_list = [] issue_list = []
success_list = [] success_list = []
if guild.id in self._channel_mute_events:
self._channel_mute_events[guild.id].clear()
else:
self._channel_mute_events[guild.id] = asyncio.Event()
for user in users: for user in users:
success = await self.unmute_user(guild, author, user, audit_reason) success = await self.unmute_user(guild, author, user, audit_reason)
@ -1178,6 +1193,7 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
) )
else: else:
issue_list.append(success) issue_list.append(success)
self._channel_mute_events[guild.id].set()
if success_list: if success_list:
if ctx.guild.id in self._server_mutes and self._server_mutes[ctx.guild.id]: if ctx.guild.id in self._server_mutes and self._server_mutes[ctx.guild.id]:
await self.config.guild(ctx.guild).muted_users.set( await self.config.guild(ctx.guild).muted_users.set(