forked from Xeio/IdleCodeRedeemer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakepublic.ts
More file actions
62 lines (51 loc) · 2.03 KB
/
makepublic.ts
File metadata and controls
62 lines (51 loc) · 2.03 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
import {
SlashCommandBuilder,
ChatInputCommandInteraction,
EmbedBuilder,
MessageFlags,
} from 'discord.js';
import { codeManager } from '../database/codeManager';
import { auditManager } from '../database/auditManager';
export const data = new SlashCommandBuilder()
.setName('makepublic')
.setDescription('Share one of your redeemed codes with other users')
.addStringOption((option) =>
option.setName('code').setDescription('The code you want to share').setRequired(true)
);
export async function execute(interaction: ChatInputCommandInteraction) {
try {
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
const code = interaction.options.getString('code', true).toUpperCase().replaceAll('-', '');
// Check if user has redeemed this code
const userCodes = await codeManager.getRedeemedCodes(interaction.user.id);
if (!userCodes.includes(code)) {
const embed = new EmbedBuilder()
.setColor(0xff0000)
.setTitle('❌ Code Not Found')
.setDescription(
`You haven't redeemed the code \`${code}\`.\n\nYou can only share codes that you've already redeemed.`
);
await interaction.editReply({ embeds: [embed] });
return;
}
// Mark code as public
await codeManager.markCodeAsPublic(code);
// Log action
await auditManager.logAction(interaction.user.id, 'CODE_MADE_PUBLIC', { code });
const embed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('✅ Code Shared Successfully')
.setDescription(
`The code \`${code}\` is now public!\n\nOther users can now redeem it using \`/redeem code:${code}\``
)
.setFooter({ text: 'Public codes are shared with all server members' });
await interaction.editReply({ embeds: [embed] });
} catch (error) {
console.error('[MAKEPUBLIC] Error:', error);
const embed = new EmbedBuilder()
.setColor(0xff0000)
.setTitle('❌ Error')
.setDescription('Failed to share the code.');
await interaction.editReply({ embeds: [embed] });
}
}