feat: implement basic balance command

This commit is contained in:
syntaxbullet
2025-12-03 12:13:07 +01:00
parent 25c7ba46f0
commit 0d05623076
2 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
import type { Command } from "@lib/types";
import { getUserBalance } from "@/modules/economy/economy.service";
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
export const balance: Command = {
data: new SlashCommandBuilder().setName("balance").setDescription("Check your balance"),
execute: async (interaction) => {
const balance = await getUserBalance(interaction.user.id) || 0;
const embed = new EmbedBuilder().setDescription(`Your balance is ${balance}`);
await interaction.reply({ embeds: [embed] });
}
};

View File

@@ -0,0 +1,12 @@
import { DrizzleClient } from "@lib/DrizzleClient";
import { users } from "@/db/schema";
import { eq } from "drizzle-orm";
export async function getUserBalance(userId: string) {
const user = await DrizzleClient.query.users.findFirst({ where: eq(users.userId, userId) });
return user?.balance ?? 0;
}
export async function setUserBalance(userId: string, balance: number) {
await DrizzleClient.update(users).set({ balance }).where(eq(users.userId, userId));
}