feat: Implement userService.getOrCreateUser and integrate it across commands, remove old utility scripts, and fix daily bonus calculation.

This commit is contained in:
syntaxbullet
2025-12-08 10:29:40 +01:00
parent 29c0a4752d
commit 866cfab03e
12 changed files with 42 additions and 94 deletions

View File

@@ -15,12 +15,7 @@ export const balance = createCommand({
await interaction.deferReply();
const targetUser = interaction.options.getUser("user") || interaction.user;
const user = await userService.getUserById(targetUser.id);
if (!user) {
await interaction.editReply({ content: "❌ User not found in database." });
return;
}
const user = await userService.getOrCreateUser(targetUser.id, targetUser.username);
const embed = new EmbedBuilder()
.setAuthor({ name: targetUser.username, iconURL: targetUser.displayAvatarURL() })

View File

@@ -1,6 +1,7 @@
import { createCommand } from "@/lib/utils";
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
import { economyService } from "@/modules/economy/economy.service";
import { userService } from "@/modules/user/user.service";
export const daily = createCommand({
data: new SlashCommandBuilder()

View File

@@ -21,7 +21,7 @@ export const pay = createCommand({
execute: async (interaction) => {
await interaction.deferReply();
const targetUser = interaction.options.getUser("user", true);
const targetUser = await userService.getOrCreateUser(interaction.options.getUser("user", true).id, interaction.options.getUser("user", true).username);
const amount = BigInt(interaction.options.getInteger("amount", true));
const senderId = interaction.user.id;
const receiverId = targetUser.id;
@@ -31,12 +31,6 @@ export const pay = createCommand({
return;
}
// Ensure receiver exists
let receiver = await userService.getUserById(receiverId);
if (!receiver) {
receiver = await userService.createUser(receiverId, targetUser.username, undefined);
}
try {
await economyService.transfer(senderId, receiverId, amount);