diff --git a/cogs/fitwide/cog.py b/cogs/fitwide/cog.py index 3568bba7..7345f5cb 100644 --- a/cogs/fitwide/cog.py +++ b/cogs/fitwide/cog.py @@ -368,7 +368,15 @@ async def verify_db(self, inter: disnake.ApplicationCommandInteraction): pass @verify_db.sub_command(name="update", description=MessagesCZ.update_db_brief) - async def update_db(self, inter: disnake.ApplicationCommandInteraction): + async def update_db( + self, + inter: disnake.ApplicationCommandInteraction, + continue_from_login: str = commands.Param( + default="", + autocomplete=autocomp_user_logins, + description=MessagesCZ.update_db_continue_from_login, + ), + ): await inter.send(MessagesCZ.update_db_start) message = await inter.original_response() @@ -376,6 +384,12 @@ async def update_db(self, inter: disnake.ApplicationCommandInteraction): persons_count = len(all_persons) dropout_count = 0 + if continue_from_login: + for index, person in enumerate(all_persons): + if person.login == continue_from_login: + all_persons = all_persons[index:] + break + for index, person in enumerate(all_persons): if (index % 50) == 0: progress_bar = utils.general.create_bar(index, persons_count) @@ -385,8 +399,8 @@ async def update_db(self, inter: disnake.ApplicationCommandInteraction): # The simplest solution we could think of so that we don't hit rate limit await asyncio.sleep(60) - updated_person = await self.helper.check_api(person.login) self.bot.logger.info(f"Checking {person.login}") + updated_person = await self.helper.check_api(person.login) if updated_person is None: if person.year != "MUNI" and person.year != "dropout": person.year = "dropout" diff --git a/cogs/fitwide/messages_cz.py b/cogs/fitwide/messages_cz.py index 4a585dd3..50dd9015 100644 --- a/cogs/fitwide/messages_cz.py +++ b/cogs/fitwide/messages_cz.py @@ -24,6 +24,7 @@ class MessagesCZ(GlobalMessages): role_check_debug_mode = "jk, debug mode" fitwide_brief = "Příkazy na manipulaci verify studentů" update_db_brief = "Aktualizuje databázi s loginy" + update_db_continue_from_login = "Pokračovat v aktualizaci databáze od loginu (včetně)" update_db_start = "Aktualizuji databázi..." update_db_progress = "Progress: {progress_bar}." update_db_done = "Aktualizace databáze proběhla úspěšně. Nalezeno {dropout_count} nových dropout." diff --git a/features/error.py b/features/error.py index cf52b1bf..05d03586 100644 --- a/features/error.py +++ b/features/error.py @@ -26,7 +26,7 @@ rubbegod_logger = logging.getLogger("rubbergod") -class ContextMock(disnake.ApplicationCommandInteraction): +class ContextMock: """Create event context similar to commands.Context This will be used in ignore_errors function""" @@ -47,6 +47,9 @@ async def send(self, *args, ephemeral=False): async def reply(self, *args, ephemeral=False): return await self.channel.send(*args) + async def is_expired(self): + pass + class ErrorLogger: def __init__(self, bot: Rubbergod): @@ -434,7 +437,8 @@ async def ignore_errors( if isinstance(error, commands.CommandInvokeError): if inter.is_expired(): - await inter.message.reply(Messages.command_invoke_error) + # if the webhook is expired we can't use the interaction object so we send to channel + await inter.channel.send(f"{inter.author.mention} {Messages.command_invoke_error}") else: await inter.send(Messages.command_invoke_error) # return False, because we want to log these errors