From d458ada051af95baffe617eaf214ada54d4323b2 Mon Sep 17 00:00:00 2001 From: Vraj Ved Date: Fri, 5 Dec 2025 18:09:24 +0530 Subject: [PATCH 1/3] Added Setbalance and balance check --- app/src/commands/cookies.ts | 10 ++++++++ app/src/commands/economy/balance.ts | 35 ++++++++++++++++++++++---- app/src/commands/economy/setbalance.ts | 26 +++++++++++++++++++ 3 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 app/src/commands/cookies.ts create mode 100644 app/src/commands/economy/setbalance.ts diff --git a/app/src/commands/cookies.ts b/app/src/commands/cookies.ts new file mode 100644 index 0000000..5fbc8d2 --- /dev/null +++ b/app/src/commands/cookies.ts @@ -0,0 +1,10 @@ +import { createCommand } from "@lib/utils"; +import { SlashCommandBuilder, EmbedBuilder } from "discord.js"; + +export const cookies = createCommand({ + data: new SlashCommandBuilder().setName("cookies").setDescription("Say sadhasj"), + execute: async (interaction) => { + const embed = new EmbedBuilder().setDescription("HELLO sandwich"); + await interaction.reply({ embeds: [embed] }); + } +}); diff --git a/app/src/commands/economy/balance.ts b/app/src/commands/economy/balance.ts index 2cd9ad1..56a77b2 100644 --- a/app/src/commands/economy/balance.ts +++ b/app/src/commands/economy/balance.ts @@ -1,13 +1,38 @@ import { createCommand } from "@lib/utils"; import { getUserBalance } from "@/modules/economy/economy.service"; -import { SlashCommandBuilder, EmbedBuilder } from "discord.js"; +import { createUser, getUserById } from "@/modules/users/users.service"; +import { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } from "discord.js"; export const balance = createCommand({ - data: new SlashCommandBuilder().setName("balance").setDescription("Check your balance"), + data: new SlashCommandBuilder() + .setName("balance") + .setDescription("Check your balance or another user's balance (admins only)") + .addUserOption(option => + option + .setName("user") + .setDescription("User to view balance of (admin only)") + .setRequired(false) + ), + execute: async (interaction) => { - const balance = await getUserBalance(interaction.user.id) || 0; - const embed = new EmbedBuilder().setDescription(`Your balance is ${balance}`); + const isAdmin = interaction.memberPermissions?.has(PermissionFlagsBits.Administrator) || false; + + const target = interaction.options.getUser("user"); + const finalTarget = (!isAdmin || !target) ? interaction.user : target; + + // Ensure user exists in DB + let dbUser = await getUserById(finalTarget.id); + if (!dbUser) { + await createUser(finalTarget.id); + } + + const balance = await getUserBalance(finalTarget.id); + + const embed = new EmbedBuilder() + .setTitle(`${finalTarget.username}'s Balance`) + .setDescription(`💰 **${balance} coins**`) + .setColor("Green"); + await interaction.reply({ embeds: [embed] }); } }); - diff --git a/app/src/commands/economy/setbalance.ts b/app/src/commands/economy/setbalance.ts new file mode 100644 index 0000000..0af7045 --- /dev/null +++ b/app/src/commands/economy/setbalance.ts @@ -0,0 +1,26 @@ +import { createCommand } from "@lib/utils"; +import { getUserBalance, setUserBalance } from "@/modules/economy/economy.service"; +import { createUser, getUserById } from "@/modules/users/users.service"; +import { SlashCommandBuilder, EmbedBuilder } from "discord.js"; + +export const setbalance = createCommand({ + data: new SlashCommandBuilder().setName("setbalance").setDescription("Set your balance").addUserOption(option => option.setName("user").setDescription("The user to set the balance for").setRequired(true)).addNumberOption(option => + option.setName("amount") + .setDescription("The amount to set your balance to") + .setRequired(true) + ), execute: async (interaction) => { + const user = await getUserById(interaction.options.getUser("user", true).id); + if (!user) { + await createUser(interaction.options.getUser("user", true).id); + } else { + console.log(`User ${interaction.options.getUser("user", true).id} already exists.`); + } + const amount = interaction.options.getNumber("amount", true); + const oldbalance = await getUserBalance(interaction.options.getUser("user", true).id); + await setUserBalance(interaction.options.getUser("user", true).id, amount); + const balance = await getUserBalance(interaction.options.getUser("user", true).id) ; + const embed = new EmbedBuilder().setDescription(`${interaction.options.getUser("user", true).username}'s old balance is: ${oldbalance}. ${interaction.options.getUser("user", true).username}'s amount is ${amount}. ${interaction.options.getUser("user", true).username}'s new balance is ${balance}.`); + await interaction.reply({ embeds: [embed] }); + } +}); + -- 2.49.1 From d541ed2fb3f1bf099c30188b84c306005bd58481 Mon Sep 17 00:00:00 2001 From: Vraj Ved Date: Fri, 5 Dec 2025 20:03:51 +0530 Subject: [PATCH 2/3] studio script and balance command --- app/package.json | 8 ++++---- app/src/commands/economy/balance.ts | 25 ++++++++----------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/app/package.json b/app/package.json index a690eb0..d737d25 100644 --- a/app/package.json +++ b/app/package.json @@ -12,12 +12,12 @@ "typescript": "^5" }, "scripts": { - "generate": "drizzle-kit generate", - "migrate": "drizzle-kit migrate", - "db:push": "drizzle-kit push", + "generate": "docker compose run --rm app bun drizzle-kit generate", + "migrate": "docker compose run --rm app bun drizzle-kit migrate", + "db:push": "docker compose run --rm app bun drizzle-kit push", "deploy": "docker compose run --rm app bun src/scripts/deploy.ts", "dev": "bun --watch src/index.ts", - "db:studio": "drizzle-kit studio" + "db:studio": "docker compose run --rm -p 8080:8080 app bun drizzle-kit studio --host 127.0.0.1 --port 8080" }, "dependencies": { "discord.js": "^14.25.1", diff --git a/app/src/commands/economy/balance.ts b/app/src/commands/economy/balance.ts index 56a77b2..212dd3e 100644 --- a/app/src/commands/economy/balance.ts +++ b/app/src/commands/economy/balance.ts @@ -6,30 +6,21 @@ import { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } from "discord. export const balance = createCommand({ data: new SlashCommandBuilder() .setName("balance") - .setDescription("Check your balance or another user's balance (admins only)") - .addUserOption(option => - option - .setName("user") - .setDescription("User to view balance of (admin only)") - .setRequired(false) - ), - - execute: async (interaction) => { - const isAdmin = interaction.memberPermissions?.has(PermissionFlagsBits.Administrator) || false; - - const target = interaction.options.getUser("user"); - const finalTarget = (!isAdmin || !target) ? interaction.user : target; + .setDescription("Check your balance") + + ,execute: async (interaction) => { + const user = interaction.user; // Ensure user exists in DB - let dbUser = await getUserById(finalTarget.id); + let dbUser = await getUserById(user.id); if (!dbUser) { - await createUser(finalTarget.id); + await createUser(user.id); } - const balance = await getUserBalance(finalTarget.id); + const balance = await getUserBalance(user.id); const embed = new EmbedBuilder() - .setTitle(`${finalTarget.username}'s Balance`) + .setTitle(`${user.username}'s Balance`) .setDescription(`💰 **${balance} coins**`) .setColor("Green"); -- 2.49.1 From 5b503e96abd068354cd82b40279b38bded9cf1bf Mon Sep 17 00:00:00 2001 From: Vraj Ved Date: Fri, 5 Dec 2025 20:04:32 +0530 Subject: [PATCH 3/3] studio script and balance command --- app/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/package.json b/app/package.json index d737d25..8c754a5 100644 --- a/app/package.json +++ b/app/package.json @@ -17,7 +17,7 @@ "db:push": "docker compose run --rm app bun drizzle-kit push", "deploy": "docker compose run --rm app bun src/scripts/deploy.ts", "dev": "bun --watch src/index.ts", - "db:studio": "docker compose run --rm -p 8080:8080 app bun drizzle-kit studio --host 127.0.0.1 --port 8080" + "db:studio": "docker compose run --rm -p 4983:4983 app bun drizzle-kit studio --host 127.0.0.1" }, "dependencies": { "discord.js": "^14.25.1", -- 2.49.1