Compare commits
4 Commits
ee2fda83e5
...
7dd9052c9b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7dd9052c9b | ||
|
|
9d1d4aeaea | ||
|
|
bd59f01a41 | ||
|
|
4639fecf45 |
@@ -19,7 +19,7 @@ export const balance = createCommand({
|
|||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setAuthor({ name: targetUser.username, iconURL: targetUser.displayAvatarURL() })
|
.setAuthor({ name: targetUser.username, iconURL: targetUser.displayAvatarURL() })
|
||||||
.setDescription(`**Balance**: ${user.balance || 0n} 🪙`)
|
.setDescription(`**Balance**: ${user.balance || 0n} AU`)
|
||||||
.setColor("Yellow");
|
.setColor("Yellow");
|
||||||
|
|
||||||
await interaction.editReply({ embeds: [embed] });
|
await interaction.editReply({ embeds: [embed] });
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ export const daily = createCommand({
|
|||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle("💰 Daily Reward Claimed!")
|
.setTitle("💰 Daily Reward Claimed!")
|
||||||
.setDescription(`You claimed **${result.amount}** coins!`)
|
.setDescription(`You claimed **${result.amount}** Astral Units!`)
|
||||||
.addFields(
|
.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 }
|
{ name: "Next Reward", value: `<t:${Math.floor(result.nextReadyAt.getTime() / 1000)}:R>`, inline: true }
|
||||||
)
|
)
|
||||||
.setColor("Gold")
|
.setColor("Gold")
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { createErrorEmbed, createWarningEmbed } from "@lib/embeds";
|
|||||||
export const pay = createCommand({
|
export const pay = createCommand({
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("pay")
|
.setName("pay")
|
||||||
.setDescription("Transfer coins to another user")
|
.setDescription("Transfer Astral Units to another user")
|
||||||
.addUserOption(option =>
|
.addUserOption(option =>
|
||||||
option.setName("user")
|
option.setName("user")
|
||||||
.setDescription("The user to pay")
|
.setDescription("The user to pay")
|
||||||
@@ -41,7 +41,7 @@ export const pay = createCommand({
|
|||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle("💸 Transfer Successful")
|
.setTitle("💸 Transfer Successful")
|
||||||
.setDescription(`Successfully sent **${amount}** coins to <@${targetUser.id}>.`)
|
.setDescription(`Successfully sent **${amount}** Astral Units to <@${targetUser.id}>.`)
|
||||||
.setColor("Green")
|
.setColor("Green")
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
||||||
|
|||||||
75
src/commands/system/webhook.ts
Normal file
75
src/commands/system/webhook.ts
Normal 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")]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -100,11 +100,11 @@ export const economyService = {
|
|||||||
|
|
||||||
let streak = (user.dailyStreak || 0) + 1;
|
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) {
|
if (cooldown) {
|
||||||
const timeSinceReady = now.getTime() - cooldown.expiresAt.getTime();
|
const timeSinceReady = now.getTime() - cooldown.expiresAt.getTime();
|
||||||
if (timeSinceReady > 24 * 60 * 60 * 1000) {
|
if (timeSinceReady > 24 * 60 * 60 * 1000) {
|
||||||
streak = 1;
|
streak = Math.max(1, streak - Math.floor(timeSinceReady / (24 * 60 * 60 * 1000)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
streak = 1;
|
streak = 1;
|
||||||
@@ -113,9 +113,6 @@ export const economyService = {
|
|||||||
const bonus = (BigInt(streak) - 1n) * GameConfig.economy.daily.streakBonus;
|
const bonus = (BigInt(streak) - 1n) * GameConfig.economy.daily.streakBonus;
|
||||||
|
|
||||||
const totalReward = GameConfig.economy.daily.amount + bonus;
|
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)
|
await txFn.update(users)
|
||||||
.set({
|
.set({
|
||||||
balance: sql`${users.balance} + ${totalReward}`,
|
balance: sql`${users.balance} + ${totalReward}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user