-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval.js
86 lines (78 loc) · 2.79 KB
/
eval.js
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
import {
SlashCommandBuilder,
ModalBuilder,
ActionRowBuilder,
TextInputBuilder,
TextInputStyle,
InteractionContextType,
ApplicationIntegrationType,
CommandInteraction // eslint-disable-line no-unused-vars
} from 'discord.js';
import * as util from '@lib/util.js';
// Create API-compatible JSON data for the command.
export const data = new SlashCommandBuilder()
.setName('eval')
.setDescription('Evaluate JavaScript code and executes it')
.setDescriptionLocalizations({
'es-ES': 'Evalúa código JavaScript y lo ejecuta'
})
.setContexts(
InteractionContextType.Guild,
InteractionContextType.PrivateChannel
)
.setIntegrationTypes(
ApplicationIntegrationType.UserInstall,
ApplicationIntegrationType.GuildInstall
)
.addUserOption(opt => opt
.setName('target')
.setDescription('Mention a member')
.setDescriptionLocalizations({
'es-ES': 'Menciona a un miembro'
})
)
.addBooleanOption(opt => opt
.setName('ephemeral')
.setDescription('Whether the reply should be ephemeral')
.setDescriptionLocalizations({
'es-ES': 'Si la respuesta debe ser efímera'
})
);
/**
* Represents a slash command interaction.
* @param {CommandInteraction} interaction
*/
export async function execute(interaction) {
// Ignore if it is not executed by the owner.
if (!interaction.isOwner) throw null;
const target = interaction.options.getUser('target');
// By default, the message is ephemeral if the target is not specified.
const ephemeral = interaction.options.getBoolean('ephemeral') ?? !target;
// The name of the file that handles the event when the modal is submitted.
const module = 'eval.js'; // src/events/interaction/modal/forms/eval.js
// Create a custom ID and associate data with it.
const customId = interaction.client.bot.createId({ target, ephemeral, module });
const defaultValue = util.stripIndents(/* js */`
(interaction) => {
// This code is evaluated in 'bot.js'.
return interaction.client.bot.eval(ctx => {
// This code is evaluated in 'index.js'.
return 'Shard ID: ' + ctx.shard.id;
});
}
`);
await interaction.showModal(
new ModalBuilder({ customId })
.setTitle('JavaScript Eval')
.addComponents(
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setRequired(true)
.setCustomId('code')
.setLabel('Expresion')
.setValue(defaultValue)
.setStyle(TextInputStyle.Paragraph)
)
)
);
}