forked from BigMichi1/IdleCodeRedeemer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodes.ts
More file actions
102 lines (86 loc) · 3.09 KB
/
codes.ts
File metadata and controls
102 lines (86 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import {
SlashCommandBuilder,
ChatInputCommandInteraction,
EmbedBuilder,
MessageFlags,
} from 'discord.js';
import { codeManager } from '../database/codeManager';
export const data = new SlashCommandBuilder()
.setName('codes')
.setDescription('Show your redeemed codes history (last 10)')
.addNumberOption((option) =>
option
.setName('count')
.setDescription('Number of codes to show (1-20)')
.setMinValue(1)
.setMaxValue(20)
.setRequired(false)
);
export async function execute(interaction: ChatInputCommandInteraction) {
try {
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
const count = interaction.options.getNumber('count', false) || 10;
const redeemedCodes = await codeManager.getRedeemedCodeDetails(interaction.user.id, count);
if (redeemedCodes.length === 0) {
const embed = new EmbedBuilder()
.setColor(0xffaa00)
.setTitle('📝 Redeemed Codes History')
.setDescription("You haven't redeemed any codes yet.");
await interaction.editReply({ embeds: [embed] });
return;
}
const embed = new EmbedBuilder()
.setColor(0x0099ff)
.setTitle('📝 Your Redeemed Codes')
.setDescription(`Showing your last ${redeemedCodes.length} redeemed codes`)
.setFooter({ text: `Total shown: ${redeemedCodes.length}` });
redeemedCodes.forEach((codeRow, index) => {
const statusLower = (codeRow.status || 'unknown').toLowerCase();
const statusEmoji =
{
success: '✅',
expired: '❌',
error: '⚠️',
}[statusLower] || '❓';
const dateStr = new Date(codeRow.redeemed_at).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: '2-digit',
hour: '2-digit',
minute: '2-digit',
});
const publicBadge = codeRow.is_public ? ' 🌐 (Public)' : '';
let fieldValue = `**Status:** ${statusEmoji} ${statusLower}\n`;
fieldValue += `**Redeemed:** ${dateStr}\n`;
if (codeRow.loot_detail) {
try {
const loot = JSON.parse(codeRow.loot_detail);
if (loot && typeof loot === 'object') {
const lootParts = [];
if (loot.gold) lootParts.push(`Gold: ${loot.gold}`);
if (loot.rubies) lootParts.push(`Rubies: ${loot.rubies}`);
if (loot.equipment) lootParts.push(`Equipment: ${loot.equipment}`);
if (lootParts.length > 0) {
fieldValue += `**Rewards:** ${lootParts.join(', ')}\n`;
}
}
} catch {
// Skip if loot detail is not valid JSON
}
}
embed.addFields({
name: `${index + 1}. ${codeRow.code}${publicBadge}`,
value: fieldValue,
inline: false,
});
});
await interaction.editReply({ embeds: [embed] });
} catch (error) {
console.error('[CODES] Error:', error);
const embed = new EmbedBuilder()
.setColor(0xff0000)
.setTitle('❌ Error')
.setDescription('Failed to retrieve redeemed codes.');
await interaction.editReply({ embeds: [embed] });
}
}