4 Commits

5 changed files with 82 additions and 10 deletions

View File

@@ -19,7 +19,7 @@ export const balance = createCommand({
const embed = new EmbedBuilder()
.setAuthor({ name: targetUser.username, iconURL: targetUser.displayAvatarURL() })
.setDescription(`**Balance**: ${user.balance || 0n} 🪙`)
.setDescription(`**Balance**: ${user.balance || 0n} AU`)
.setColor("Yellow");
await interaction.editReply({ embeds: [embed] });

View File

@@ -13,9 +13,9 @@ export const daily = createCommand({
const embed = new EmbedBuilder()
.setTitle("💰 Daily Reward Claimed!")
.setDescription(`You claimed **${result.amount}** coins!`)
.setDescription(`You claimed **${result.amount}** Astral Units!`)
.addFields(
{ name: "Current Streak", value: `🔥 ${result.streak} days`, inline: true },
{ name: "Streak", value: `🔥 ${result.streak} days`, inline: true },
{ name: "Next Reward", value: `<t:${Math.floor(result.nextReadyAt.getTime() / 1000)}:R>`, inline: true }
)
.setColor("Gold")

View File

@@ -8,7 +8,7 @@ import { createErrorEmbed, createWarningEmbed } from "@lib/embeds";
export const pay = createCommand({
data: new SlashCommandBuilder()
.setName("pay")
.setDescription("Transfer coins to another user")
.setDescription("Transfer Astral Units to another user")
.addUserOption(option =>
option.setName("user")
.setDescription("The user to pay")
@@ -41,7 +41,7 @@ export const pay = createCommand({
const embed = new EmbedBuilder()
.setTitle("💸 Transfer Successful")
.setDescription(`Successfully sent **${amount}** coins to <@${targetUser.id}>.`)
.setDescription(`Successfully sent **${amount}** Astral Units to <@${targetUser.id}>.`)
.setColor("Green")
.setTimestamp();

View File

@@ -0,0 +1,75 @@
import { createCommand } from "@/lib/utils";
import { SlashCommandBuilder, PermissionFlagsBits, TextChannel, NewsChannel, VoiceChannel } from "discord.js";
import { createErrorEmbed } from "@/lib/embeds";
export const webhook = createCommand({
data: new SlashCommandBuilder()
.setName("webhook")
.setDescription("Send a message via webhook using a JSON payload")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageWebhooks)
.addStringOption(option =>
option.setName("payload")
.setDescription("The JSON payload for the webhook message")
.setRequired(true)
),
execute: async (interaction) => {
await interaction.deferReply({ ephemeral: true });
const payloadString = interaction.options.getString("payload", true);
let payload;
try {
payload = JSON.parse(payloadString);
} catch (error) {
await interaction.editReply({
embeds: [createErrorEmbed("The provided payload is not valid JSON.", "Invalid JSON")]
});
return;
}
const channel = interaction.channel;
if (!channel || !('createWebhook' in channel)) {
await interaction.editReply({
embeds: [createErrorEmbed("This channel does not support webhooks.", "Unsupported Channel")]
});
return;
}
let webhook;
try {
webhook = await channel.createWebhook({
name: `${interaction.client.user.username} - Proxy`,
avatar: interaction.client.user.displayAvatarURL(),
reason: `Proxy message requested by ${interaction.user.tag}`
});
// Support snake_case keys for raw API compatibility
if (payload.avatar_url && !payload.avatarURL) {
payload.avatarURL = payload.avatar_url;
delete payload.avatar_url;
}
await webhook.send(payload);
await webhook.delete("Proxy message sent");
await interaction.editReply({ content: "Message sent successfully!" });
} catch (error) {
console.error("Webhook error:", error);
// Attempt cleanup if webhook was created but sending failed
if (webhook) {
try {
await webhook.delete("Cleanup after failure");
} catch (cleanupError) {
console.error("Failed to delete webhook during cleanup:", cleanupError);
}
}
await interaction.editReply({
embeds: [createErrorEmbed("Failed to send message via webhook. Ensure the bot has 'Manage Webhooks' permission and the payload is valid.", "Delivery Failed")]
});
}
}
});

View File

@@ -100,11 +100,11 @@ export const economyService = {
let streak = (user.dailyStreak || 0) + 1;
// If previous cooldown exists and expired more than 24h ago (meaning >48h since last claim), reset streak
// If previous cooldown exists and expired more than 24h ago (meaning >48h since last claim), reduce streak by one for each day passed minimum 1
if (cooldown) {
const timeSinceReady = now.getTime() - cooldown.expiresAt.getTime();
if (timeSinceReady > 24 * 60 * 60 * 1000) {
streak = 1;
streak = Math.max(1, streak - Math.floor(timeSinceReady / (24 * 60 * 60 * 1000)));
}
} else {
streak = 1;
@@ -113,9 +113,6 @@ export const economyService = {
const bonus = (BigInt(streak) - 1n) * GameConfig.economy.daily.streakBonus;
const totalReward = GameConfig.economy.daily.amount + bonus;
// Update User w/ Economy Service (reuse modifyUserBalance if we split it out, but here manual is fine for atomic combined streak update)
// Actually, we can just update directly here as we are already refining specific fields like streak.
await txFn.update(users)
.set({
balance: sql`${users.balance} + ${totalReward}`,