Skip to content

Commit

Permalink
feat: Auto update lang settings
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Jan 15, 2025
1 parent 9362dd9 commit 09b7b45
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions hoyo_buddy/bot/command_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@

class CommandTree(app_commands.CommandTree):
async def interaction_check(self, i: Interaction) -> Literal[True]:
if (
i.type not in {InteractionType.application_command, InteractionType.autocomplete}
or i.user.id in i.client.user_ids
):
if i.type not in {InteractionType.application_command, InteractionType.autocomplete}:
return True

# Set user's language if not set
async with i.client.pool.acquire() as conn:
await conn.execute(
'UPDATE "user" SET lang = $2 WHERE id = $1 AND lang IS NULL;',
i.user.id,
i.locale.value,
)

if i.user.id in i.client.user_ids:
return True

async with i.client.pool.acquire() as conn:
Expand All @@ -30,8 +38,9 @@ async def interaction_check(self, i: Interaction) -> Literal[True]:
"{}",
)
await conn.execute(
'INSERT INTO "settings" (user_id) VALUES ($1) ON CONFLICT (user_id) DO NOTHING;',
'INSERT INTO "settings" (user_id, lang) VALUES ($1, $2) ON CONFLICT (user_id) DO NOTHING;',
i.user.id,
i.locale.value,
)
i.client.user_ids.add(i.user.id)

Expand Down

0 comments on commit 09b7b45

Please sign in to comment.