This repository has been archived by the owner on Jul 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
122 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"projectLanguage": "ts", | ||
"locations": { | ||
"base": "src", | ||
"arguments": "arguments", | ||
"commands": "commands", | ||
"listeners": "listeners", | ||
"preconditions": "preconditions", | ||
"interaction-handlers": "interaction-handlers", | ||
"routes": "" | ||
}, | ||
"customFileTemplates": { | ||
"enabled": false, | ||
"location": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,52 @@ | ||
import { ChatInputCommand, Command } from "@sapphire/framework"; | ||
import { BaseEmbedBuilder } from "../../libraries/structures/components/BaseEmbedBuilder"; | ||
import { DEV_USER_IDS } from "../../config"; | ||
import { ComponentType } from "discord.js"; | ||
import { deleteBtn } from "../../libraries/structures/components/Buttons"; | ||
|
||
export class EvalCommand extends Command { | ||
public constructor(context: Command.Context, options: Command.Options) { | ||
super(context, { | ||
...options, | ||
fullCategory: ["Developer"] | ||
fullCategory: ["Developer"], | ||
preconditions: ["DeveloperOnlyPrecondition"] | ||
}); | ||
} | ||
|
||
public override registerApplicationCommands(registry: ChatInputCommand.Registry) { | ||
registry.registerChatInputCommand((builder) => | ||
builder | ||
.setName("eval") | ||
.setDescription("Execute some javascript.") | ||
.setDescription("Execute some raw JavaScript code.") | ||
.addStringOption((option) => | ||
option.setName("input").setDescription("The code to execute").setRequired(true) | ||
option.setName("input").setDescription("The code to execute.").setRequired(true) | ||
) | ||
); | ||
} | ||
|
||
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { | ||
const input = interaction.options.getString("input"); | ||
const embed = new BaseEmbedBuilder(); | ||
let content = ""; | ||
|
||
try { | ||
if (!DEV_USER_IDS.includes(interaction.user.id)) { | ||
throw Error("This command is dev only."); | ||
} | ||
|
||
const evaled = eval(input as string); | ||
embed.isSuccessEmbed().setDescription(`\`\`\`xl\n${evaled}\`\`\``); | ||
const timeTaken = ((Date.now() - interaction.createdTimestamp) / 1000).toFixed(3); | ||
|
||
content = `:bricks: **EVAL COMPLETE** (${timeTaken}s) :bricks:\n\`\`\`xl\n${evaled}\`\`\``; | ||
} catch (err) { | ||
embed.setTitle("Error Occured").isErrorEmbed().setDescription(`${err}`); | ||
this.container.logger.error(`[EvalCommand] ${err}`); | ||
embed.isErrorEmbed().setDescription("An error occurred. Check the console for more details."); | ||
} | ||
|
||
return interaction.reply({ embeds: [embed] }); | ||
return interaction.reply({ | ||
content: content, | ||
embeds: embed.data.description ? [embed] : [], | ||
components: [ | ||
{ | ||
type: ComponentType.ActionRow, | ||
components: [deleteBtn] | ||
} | ||
] | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { InteractionHandler, InteractionHandlerTypes, PieceContext } from "@sapphire/framework"; | ||
import type { ButtonInteraction } from "discord.js"; | ||
|
||
export class EvalDeleteButtonHandler extends InteractionHandler { | ||
public constructor(ctx: PieceContext, options: InteractionHandler.Options) { | ||
super(ctx, { | ||
...options, | ||
interactionHandlerType: InteractionHandlerTypes.Button | ||
}); | ||
} | ||
|
||
public override parse(interaction: ButtonInteraction) { | ||
if (interaction.customId !== "evalDelete") return this.none(); | ||
|
||
return this.some(); | ||
} | ||
|
||
public async run(interaction: ButtonInteraction) { | ||
await interaction.deferUpdate(); | ||
|
||
return interaction.message.delete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ButtonBuilder, ButtonStyle } from "discord.js"; | ||
|
||
export const deleteBtn = new ButtonBuilder() | ||
.setCustomId("evalDelete") | ||
.setLabel("Delete Output") | ||
.setStyle(ButtonStyle.Danger); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Command, Precondition } from "@sapphire/framework"; | ||
import { DEV_USER_IDS } from "../config"; | ||
|
||
export class DeveloperOnlyPrecondition extends Precondition { | ||
public chatInputRun(interaction: Command.ChatInputCommandInteraction) { | ||
return this.checkDev(interaction.user.id); | ||
} | ||
|
||
public contextMenuRun(interaction: Command.ContextMenuCommandInteraction) { | ||
return this.checkDev(interaction.user.id); | ||
} | ||
|
||
checkDev(userId: string) { | ||
return DEV_USER_IDS.includes(userId) | ||
? this.ok() | ||
: this.error({ message: "You are not allowed to use this command." }); | ||
} | ||
} |