-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheval.ts
More file actions
59 lines (53 loc) · 1.85 KB
/
eval.ts
File metadata and controls
59 lines (53 loc) · 1.85 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
import {
type ChatInputCommandInteraction,
codeBlock,
MessageFlags,
PermissionFlagsBits,
SlashCommandBuilder,
} from "discord.js";
import type { DatadropClient } from "../../datadrop.js";
import { clean } from "../../helpers.js";
import type { Command } from "../../models/index.js";
export default {
data: new SlashCommandBuilder()
.setName("eval")
.setDescription("Évalue du code Javascript.")
.addStringOption((option) =>
option
.setName("code")
.setDescription("Le code à évaluer.")
.setRequired(true),
)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
ownerOnly: true,
async execute(
client: DatadropClient,
interaction: ChatInputCommandInteraction,
) {
// double check sur l'identité juste pour la sécurité
const { ownerIds } = client.config;
if (!ownerIds.includes(interaction.user.id)) {
await interaction.reply({
content:
"❌ **Oups!** - Vous n'êtes pas autorisé à utiliser cette commande.",
flags: MessageFlags.Ephemeral,
});
return;
}
let content = "";
try {
const code = interaction.options.getString("code", true);
// biome-ignore lint/security/noGlobalEval: normal use case for an eval command
let evaled = eval(code);
if (typeof evaled !== "string") {
const util = await import("node:util");
evaled = util.inspect(evaled);
}
content = clean(evaled);
} catch (err) {
content = `// An error occured\n\n${clean(err)}`;
} finally {
await interaction.reply(codeBlock("xl", content));
}
},
} as Command;