forked from syntaxbullet/AuroraBot-discord
feat: Implement userService.getOrCreateUser and integrate it across commands, remove old utility scripts, and fix daily bonus calculation.
This commit is contained in:
@@ -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() })
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user