feat: implement basic balance command
This commit is contained in:
13
app/src/commands/economy/balance.ts
Normal file
13
app/src/commands/economy/balance.ts
Normal 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] });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
12
app/src/modules/economy/economy.service.ts
Normal file
12
app/src/modules/economy/economy.service.ts
Normal 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));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user