forked from blizzthewolf/SeaCogs
fix(moderation): galacticbot import loop should no longer be blocking
This commit is contained in:
parent
59f0375ad5
commit
c700782e17
1 changed files with 54 additions and 48 deletions
|
@ -5,6 +5,7 @@
|
|||
# ____) | __/ (_| \__ \\ V V /| | | | | | | | | | | | __/ |
|
||||
# |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_|
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import json
|
||||
import time
|
||||
|
@ -1734,8 +1735,11 @@ class Moderation(commands.Cog):
|
|||
'BAN',
|
||||
'UNBAN'
|
||||
]
|
||||
|
||||
file = await self.ctx.message.attachments[0].read()
|
||||
data = sorted(json.loads(file), key=lambda x: x['case'])
|
||||
|
||||
async def process_case(case, accepted_types):
|
||||
for case in data:
|
||||
if case['type'] not in accepted_types:
|
||||
continue
|
||||
|
@ -1744,7 +1748,7 @@ class Moderation(commands.Cog):
|
|||
|
||||
if case['duration']:
|
||||
try:
|
||||
duration = timedelta(seconds=round(float(case['duration']) / 1000))
|
||||
duration = timedelta(seconds=round(case['duration']) / 1000)
|
||||
except OverflowError:
|
||||
continue
|
||||
|
||||
|
@ -1790,6 +1794,8 @@ class Moderation(commands.Cog):
|
|||
|
||||
await interaction.edit_original_response(content="Import complete.")
|
||||
|
||||
await asyncio.gather(*[process_case(case, accepted_types) for case in data])
|
||||
|
||||
@discord.ui.button(label="No", style=discord.ButtonStyle.danger)
|
||||
async def import_button_n(self, interaction: discord.Interaction, button: discord.ui.Button): # pylint: disable=unused-argument
|
||||
await self.message.edit("Import cancelled.", view=None)
|
||||
|
|
Loading…
Reference in a new issue