feat: Add user existence checks to economy commands and refactor trade service to expose sessions for testing.

This commit is contained in:
syntaxbullet
2026-01-05 12:57:22 +01:00
parent 599684cde8
commit d0b4cb80de
7 changed files with 48 additions and 36 deletions

View File

@@ -25,6 +25,10 @@ export const exam = createCommand({
execute: async (interaction) => {
await interaction.deferReply();
const user = await userService.getOrCreateUser(interaction.user.id, interaction.user.username);
if (!user) {
await interaction.editReply({ embeds: [createErrorEmbed("Failed to retrieve user data.")] });
return;
}
const now = new Date();
const currentDay = now.getDay();
@@ -47,7 +51,7 @@ export const exam = createCommand({
const metadata: ExamMetadata = {
examDay: currentDay,
lastXp: user.xp.toString()
lastXp: (user.xp ?? 0n).toString()
};
await DrizzleClient.insert(userTimers).values({
@@ -98,7 +102,7 @@ export const exam = createCommand({
const newMetadata: ExamMetadata = {
examDay: examDay,
lastXp: user.xp.toString() // Reset tracking
lastXp: (user.xp ?? 0n).toString()
};
await DrizzleClient.update(userTimers)
@@ -125,7 +129,7 @@ export const exam = createCommand({
// 5. Reward Calculation
const lastXp = BigInt(metadata.lastXp || "0"); // Fallback just in case
const currentXp = user.xp;
const currentXp = user.xp ?? 0n;
const diff = currentXp - lastXp;
// Calculate Reward