fix: fix potential issues with trivia command
This commit is contained in:
@@ -37,7 +37,8 @@ export async function handleTriviaInteraction(interaction: ButtonInteraction) {
|
|||||||
const { components, flags } = getTriviaTimeoutView(
|
const { components, flags } = getTriviaTimeoutView(
|
||||||
session.question.question,
|
session.question.question,
|
||||||
session.question.correctAnswer,
|
session.question.correctAnswer,
|
||||||
session.allAnswers
|
session.allAnswers,
|
||||||
|
session.entryFee
|
||||||
);
|
);
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
@@ -91,7 +92,8 @@ export async function handleTriviaInteraction(interaction: ButtonInteraction) {
|
|||||||
const { components, flags } = getTriviaTimeoutView(
|
const { components, flags } = getTriviaTimeoutView(
|
||||||
session.question.question,
|
session.question.question,
|
||||||
session.question.correctAnswer,
|
session.question.correctAnswer,
|
||||||
session.allAnswers
|
session.allAnswers,
|
||||||
|
session.entryFee
|
||||||
);
|
);
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
@@ -116,7 +118,8 @@ export async function handleTriviaInteraction(interaction: ButtonInteraction) {
|
|||||||
result,
|
result,
|
||||||
session.question.question,
|
session.question.question,
|
||||||
userAnswer,
|
userAnswer,
|
||||||
session.allAnswers
|
session.allAnswers,
|
||||||
|
session.entryFee
|
||||||
);
|
);
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
|
|||||||
@@ -166,7 +166,8 @@ export function getTriviaResultView(
|
|||||||
result: TriviaResult,
|
result: TriviaResult,
|
||||||
question: string,
|
question: string,
|
||||||
userAnswer?: string,
|
userAnswer?: string,
|
||||||
allAnswers?: string[]
|
allAnswers?: string[],
|
||||||
|
entryFee: bigint = 0n
|
||||||
): {
|
): {
|
||||||
components: any[];
|
components: any[];
|
||||||
flags: number;
|
flags: number;
|
||||||
@@ -216,7 +217,7 @@ export function getTriviaResultView(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 10, // Text Display
|
type: 10, // Text Display
|
||||||
content: `${answerDisplay}\n\n💸 **Entry fee lost:** ${reward} AU\n\n📚 Better luck next time!`
|
content: `${answerDisplay}\n\n💸 **Entry fee lost:** ${entryFee} AU\n\n📚 Better luck next time!`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -267,7 +268,8 @@ export function getTriviaResultView(
|
|||||||
export function getTriviaTimeoutView(
|
export function getTriviaTimeoutView(
|
||||||
question: string,
|
question: string,
|
||||||
correctAnswer: string,
|
correctAnswer: string,
|
||||||
allAnswers?: string[]
|
allAnswers?: string[],
|
||||||
|
entryFee: bigint = 0n
|
||||||
): {
|
): {
|
||||||
components: any[];
|
components: any[];
|
||||||
flags: number;
|
flags: number;
|
||||||
@@ -290,7 +292,7 @@ export function getTriviaTimeoutView(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 10, // Text Display
|
type: 10, // Text Display
|
||||||
content: `⏰ **You ran out of time!**\n✅ **Correct answer:** ${correctAnswer}\n\n💸 Entry fee lost\n\n⚡ Be faster next time!`
|
content: `⏰ **You ran out of time!**\n✅ **Correct answer:** ${correctAnswer}\n\n💸 **Entry fee lost:** ${entryFee} AU\n\n⚡ Be faster next time!`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { users, userTimers, transactions } from "@db/schema";
|
import { users, userTimers, transactions } from "@db/schema";
|
||||||
import { eq, and } from "drizzle-orm";
|
import { eq, and, sql } from "drizzle-orm";
|
||||||
import { config } from "@shared/lib/config";
|
import { config } from "@shared/lib/config";
|
||||||
import { withTransaction } from "@/lib/db";
|
import { withTransaction } from "@/lib/db";
|
||||||
import type { Transaction } from "@shared/lib/types";
|
import type { Transaction } from "@shared/lib/types";
|
||||||
@@ -171,7 +171,7 @@ class TriviaService {
|
|||||||
// Deduct entry fee (SINK MECHANISM)
|
// Deduct entry fee (SINK MECHANISM)
|
||||||
await tx.update(users)
|
await tx.update(users)
|
||||||
.set({
|
.set({
|
||||||
balance: (user.balance ?? 0n) - entryFee,
|
balance: sql`${users.balance} - ${entryFee}`,
|
||||||
})
|
})
|
||||||
.where(eq(users.id, BigInt(userId)));
|
.where(eq(users.id, BigInt(userId)));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user