forked from syntaxbullet/AuroraBot-discord
feat: Introduce new modules for class, inventory, leveling, and quests with expanded schema, refactor user service, and add verification scripts.
This commit is contained in:
@@ -1,29 +1,32 @@
|
||||
import { createCommand } from "@lib/utils";
|
||||
import { getUserBalance } from "@/modules/economy/economy.service";
|
||||
import { createUser, getUserById } from "@/modules/users/users.service";
|
||||
import { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } from "discord.js";
|
||||
import { createCommand } from "@/lib/utils";
|
||||
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
|
||||
import { userService } from "@/modules/user/user.service";
|
||||
|
||||
export const balance = createCommand({
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("balance")
|
||||
.setDescription("Check your balance")
|
||||
.setDescription("Check your or another user's balance")
|
||||
.addUserOption(option =>
|
||||
option.setName("user")
|
||||
.setDescription("The user to check")
|
||||
.setRequired(false)
|
||||
),
|
||||
execute: async (interaction) => {
|
||||
await interaction.deferReply();
|
||||
|
||||
const targetUser = interaction.options.getUser("user") || interaction.user;
|
||||
const user = await userService.getUserById(targetUser.id);
|
||||
|
||||
, execute: async (interaction) => {
|
||||
const user = interaction.user;
|
||||
// Ensure user exists in DB
|
||||
let dbUser = await getUserById(user.id);
|
||||
if (!dbUser) {
|
||||
await createUser(user.id);
|
||||
if (!user) {
|
||||
await interaction.editReply({ content: "❌ User not found in database." });
|
||||
return;
|
||||
}
|
||||
|
||||
const balance = await getUserBalance(user.id);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`${user.username}'s Balance`)
|
||||
.setDescription(`💰 **${balance} coins**`)
|
||||
.setColor("Green");
|
||||
.setAuthor({ name: targetUser.username, iconURL: targetUser.displayAvatarURL() })
|
||||
.setDescription(`**Balance**: ${user.balance || 0n} 🪙`)
|
||||
.setColor("Yellow");
|
||||
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,68 +1,42 @@
|
||||
import { createCommand } from "@lib/utils";
|
||||
import { addUserBalance } from "@/modules/economy/economy.service";
|
||||
import { createUser, getUserById, updateUserDaily } from "@/modules/users/users.service";
|
||||
import { createCommand } from "@/lib/utils";
|
||||
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
|
||||
import { economyService } from "@/modules/economy/economy.service";
|
||||
|
||||
export const daily = createCommand({
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("daily")
|
||||
.setDescription("Get rewarded with daily coins"),
|
||||
.setDescription("Claim your daily reward"),
|
||||
execute: async (interaction) => {
|
||||
const user = interaction.user;
|
||||
// Ensure user exists in DB
|
||||
let dbUser = await getUserById(user.id);
|
||||
if (!dbUser) {
|
||||
dbUser = await createUser(user.id);
|
||||
}
|
||||
await interaction.deferReply();
|
||||
|
||||
const now = new Date();
|
||||
const lastDaily = dbUser.lastDaily;
|
||||
try {
|
||||
const result = await economyService.claimDaily(interaction.user.id);
|
||||
|
||||
if (lastDaily) {
|
||||
const diff = now.getTime() - lastDaily.getTime();
|
||||
const oneDay = 24 * 60 * 60 * 1000;
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("💰 Daily Reward Claimed!")
|
||||
.setDescription(`You claimed **${result.amount}** coins!`)
|
||||
.addFields(
|
||||
{ name: "Current Streak", value: `🔥 ${result.streak} days`, inline: true },
|
||||
{ name: "Next Reward", value: `<t:${Math.floor(result.nextReadyAt.getTime() / 1000)}:R>`, inline: true }
|
||||
)
|
||||
.setColor("Gold")
|
||||
.setTimestamp();
|
||||
|
||||
if (diff < oneDay) {
|
||||
const remaining = oneDay - diff;
|
||||
const hours = Math.floor(remaining / (1000 * 60 * 60));
|
||||
const minutes = Math.floor((remaining % (1000 * 60 * 60)) / (1000 * 60));
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
} catch (error: any) {
|
||||
if (error.message.includes("Daily already claimed")) {
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("Daily Reward")
|
||||
.setDescription(`You have already claimed your daily reward.\nCome back in **${hours}h ${minutes}m**.`)
|
||||
.setColor("Red");
|
||||
|
||||
await interaction.reply({ embeds: [embed], ephemeral: true });
|
||||
.setTitle("⏳ Cooldown")
|
||||
.setDescription(error.message)
|
||||
.setColor("Orange");
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
return;
|
||||
}
|
||||
|
||||
console.error(error);
|
||||
await interaction.editReply({ content: "❌ An error occurred while claiming your daily reward." });
|
||||
}
|
||||
|
||||
// Calculate streak
|
||||
let streak = dbUser.dailyStreak;
|
||||
if (lastDaily) {
|
||||
const diff = now.getTime() - lastDaily.getTime();
|
||||
const twoDays = 48 * 60 * 60 * 1000;
|
||||
if (diff < twoDays) {
|
||||
streak += 1;
|
||||
} else {
|
||||
streak = 1;
|
||||
}
|
||||
} else {
|
||||
streak = 1;
|
||||
}
|
||||
|
||||
const baseReward = 100;
|
||||
const streakBonus = (streak - 1) * 10;
|
||||
const totalReward = baseReward + streakBonus;
|
||||
|
||||
await updateUserDaily(user.id, now, streak);
|
||||
await addUserBalance(user.id, totalReward);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("Daily Reward Claimed!")
|
||||
.setDescription(`You received **${totalReward} coins**! 💰\n\n**Streak:** ${streak} days 🔥`)
|
||||
.setColor("Green");
|
||||
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,61 +1,60 @@
|
||||
import { createCommand } from "@lib/utils";
|
||||
import { getUserBalance, setUserBalance } from "@/modules/economy/economy.service";
|
||||
import { createUser, getUserById } from "@/modules/users/users.service";
|
||||
import { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } from "discord.js";
|
||||
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 pay = createCommand({
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("pay")
|
||||
.setDescription("Send balance to another user")
|
||||
.setDescription("Transfer coins to another user")
|
||||
.addUserOption(option =>
|
||||
option.setName('recipient')
|
||||
.setDescription('The user to send balance to')
|
||||
.setRequired(true))
|
||||
option.setName("user")
|
||||
.setDescription("The user to pay")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addIntegerOption(option =>
|
||||
option.setName('amount')
|
||||
.setDescription('The amount of balance to send')
|
||||
.setRequired(true))
|
||||
option.setName("amount")
|
||||
.setDescription("Amount to transfer")
|
||||
.setMinValue(1)
|
||||
.setRequired(true)
|
||||
),
|
||||
execute: async (interaction) => {
|
||||
await interaction.deferReply();
|
||||
|
||||
const targetUser = interaction.options.getUser("user", true);
|
||||
const amount = BigInt(interaction.options.getInteger("amount", true));
|
||||
const senderId = interaction.user.id;
|
||||
const receiverId = targetUser.id;
|
||||
|
||||
, execute: async (interaction) => {
|
||||
const user = interaction.user;
|
||||
// Ensure if your user exists in DB
|
||||
let dbUser = await getUserById(user.id);
|
||||
if (!dbUser) {
|
||||
await createUser(user.id);
|
||||
}
|
||||
|
||||
const balance = await getUserBalance(user.id);
|
||||
const recipient = interaction.options.getUser('recipient');
|
||||
const amount = interaction.options.getInteger('amount');
|
||||
|
||||
if (amount! <= 0) {
|
||||
await interaction.reply({ content: "❌ Amount must be greater than zero.", ephemeral: true });
|
||||
return;
|
||||
}
|
||||
if (amount! > balance) {
|
||||
await interaction.reply({ content: "❌ You do not have enough coins to complete this transaction.", ephemeral: true });
|
||||
if (senderId === receiverId) {
|
||||
await interaction.editReply({ content: "❌ You cannot pay yourself." });
|
||||
return;
|
||||
}
|
||||
|
||||
if (recipient!.id === user.id) {
|
||||
await interaction.reply({ content: "❌ You cannot send coins to yourself.", ephemeral: true });
|
||||
return;
|
||||
// Ensure receiver exists
|
||||
let receiver = await userService.getUserById(receiverId);
|
||||
if (!receiver) {
|
||||
receiver = await userService.createUser(receiverId, targetUser.username, undefined);
|
||||
}
|
||||
|
||||
// Ensure recipient exists in DB
|
||||
let dbRecipient = await getUserById(recipient!.id);
|
||||
if (!dbRecipient) {
|
||||
dbRecipient = await createUser(recipient!.id);
|
||||
try {
|
||||
await economyService.transfer(senderId, receiverId, amount);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("💸 Transfer Successful")
|
||||
.setDescription(`Successfully sent **${amount}** coins to ${targetUser}.`)
|
||||
.setColor("Green")
|
||||
.setTimestamp();
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
} catch (error: any) {
|
||||
if (error.message.includes("Insufficient funds")) {
|
||||
await interaction.editReply({ content: "❌ Insufficient funds." });
|
||||
return;
|
||||
}
|
||||
console.error(error);
|
||||
await interaction.editReply({ content: "❌ Transfer failed." });
|
||||
}
|
||||
|
||||
await setUserBalance(user.id, balance - amount!); // Deduct from sender
|
||||
await setUserBalance(recipient!.id, (await getUserBalance(recipient!.id)) + amount!); // Add to recipient
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setDescription(`sent **${amount} coins** to ${recipient!.username}`)
|
||||
.setColor("Green");
|
||||
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user