mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[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
This commit is contained in:
parent
6c338f175b
commit
847444eab1
@ -148,25 +148,34 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
|
|||||||
schema_version = await self.config.schema_version()
|
schema_version = await self.config.schema_version()
|
||||||
|
|
||||||
if schema_version == 0:
|
if schema_version == 0:
|
||||||
start = datetime.now()
|
await self._schema_0_to_1()
|
||||||
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()
|
|
||||||
|
|
||||||
schema_version += 1
|
schema_version += 1
|
||||||
await self.config.schema_version.set(schema_version)
|
await self.config.schema_version.set(schema_version)
|
||||||
log.info(
|
|
||||||
"Config conversion to schema_version 1 done. It took %s to proceed.",
|
async def _schema_0_to_1(self):
|
||||||
datetime.now() - start,
|
"""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):
|
async def cog_before_invoke(self, ctx: commands.Context):
|
||||||
await self._ready.wait()
|
await self._ready.wait()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user