From 847444eab1addff8ac49c4a6d160e2f1b98d4367 Mon Sep 17 00:00:00 2001 From: PredaaA <46051820+PredaaA@users.noreply.github.com> Date: Sun, 4 Apr 2021 02:43:36 +0200 Subject: [PATCH] [Mutes] Fix data conversion to shema_version 1 and add a note about it (#4934) * [Mutes] Add a note about conversion to schema_version 1 * Only start the conversion if all_channels * Actually do what the previous commit said * okay this time is the right time * Update mutes.py * Move conversion to its own method * Update mutes.py --- redbot/cogs/mutes/mutes.py | 43 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/redbot/cogs/mutes/mutes.py b/redbot/cogs/mutes/mutes.py index b12a72bb1..ce30709f4 100644 --- a/redbot/cogs/mutes/mutes.py +++ b/redbot/cogs/mutes/mutes.py @@ -148,25 +148,34 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass): schema_version = await self.config.schema_version() if schema_version == 0: - start = datetime.now() - log.info("Config conversion to schema_version 1 started.") - all_channels = await self.config.all_channels() - async for channel_id in AsyncIter(all_channels.keys()): - try: - if (channel := self.bot.get_channel(channel_id)) is None: - channel = await self.bot.fetch_channel(channel_id) - async with self.config.channel_from_id(channel_id) as muted_users: - for user_id, mute_data in muted_users.items(): - mute_data["guild"] = channel.guild.id - except (discord.NotFound, discord.Forbidden): - await self.config.channel_from_id(channel_id).clear() - + await self._schema_0_to_1() schema_version += 1 await self.config.schema_version.set(schema_version) - log.info( - "Config conversion to schema_version 1 done. It took %s to proceed.", - datetime.now() - start, - ) + + async def _schema_0_to_1(self): + """This contains conversion that adds guild ID to channel mutes data.""" + all_channels = await self.config.all_channels() + if not all_channels: + return + + start = datetime.now() + log.info( + "Config conversion to schema_version 1 started. This may take a while to proceed..." + ) + async for channel_id in AsyncIter(all_channels.keys()): + try: + if (channel := self.bot.get_channel(channel_id)) is None: + channel = await self.bot.fetch_channel(channel_id) + async with self.config.channel_from_id(channel_id).muted_users() as muted_users: + for mute_id, mute_data in muted_users.items(): + mute_data["guild"] = channel.guild.id + except (discord.NotFound, discord.Forbidden): + await self.config.channel_from_id(channel_id).clear() + + log.info( + "Config conversion to schema_version 1 done. It took %s to proceed.", + datetime.now() - start, + ) async def cog_before_invoke(self, ctx: commands.Context): await self._ready.wait()