Skip to content

Commit

Permalink
fix: error.py dead webhook + restore update from login
Browse files Browse the repository at this point in the history
  • Loading branch information
solumath authored and peterdragun committed Sep 6, 2024
1 parent 9f048dc commit 20aaea0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
18 changes: 16 additions & 2 deletions cogs/fitwide/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,28 @@ 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()

all_persons = ValidPersonDB.get_all_persons()
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)
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions cogs/fitwide/messages_cz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
8 changes: 6 additions & 2 deletions features/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 20aaea0

Please sign in to comment.