UNPKG

djskage

Version:

A Discord.js extension for utility commands

69 lines (68 loc) 3.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mockInteraction_1 = require("../utils/mockInteraction"); module.exports = { name: "debug", aliases: ["dbg"], description: "Debug a command as yourself, a different user in the current channel or a different channel.", usage: "debug <command> [args?...] (?c <#id> -> channel, ?u <@id> -> user)", execute: async (djskage, client, message) => { const args = message.content.split(" ").slice(2); if (!args.length) return; const guildCommands = await message.guild?.commands.fetch(); const globalCommands = await client.application?.commands.fetch(); const command = guildCommands?.find((cmd) => cmd.name === args[0]) || globalCommands?.find((cmd) => cmd.name === args[0]); if (!command) return message.reply(`Command "${args[0]}" not found.`); const mockInteraction = new mockInteraction_1.Mockinteraction(client, message, command); const responsePromise = new Promise((resolve) => { const originalReply = mockInteraction.reply; const originalEditReply = mockInteraction.editReply; const originalFollowUp = mockInteraction.followUp; const originalDeferReply = mockInteraction.deferReply; const originalDeferUpdate = mockInteraction.deferUpdate; //@ts-ignore mockInteraction.reply = async (options) => { const result = await originalReply.call(mockInteraction, options); return resolve(result); }; //@ts-ignore mockInteraction.editReply = async (options) => { const result = await originalEditReply.call(mockInteraction, options); return resolve(result); }; //@ts-ignore mockInteraction.followUp = async (options) => { const result = await originalFollowUp.call(mockInteraction, options); return resolve(result); }; //@ts-ignore mockInteraction.deferReply = async () => { const result = await originalDeferReply.call(mockInteraction); await y.react("⏯️"); return resolve(result); }; //@ts-ignore mockInteraction.deferUpdate = async () => { const result = await originalDeferUpdate.call(mockInteraction); await y.react("8️⃣"); return resolve(result); }; }); const y = await message.channel.send(`Running the \`${mockInteraction.fullCommandName}\` command...`); client .listeners("interactionCreate") .forEach((func) => func(mockInteraction)); const startCMD = performance.now(); await responsePromise; const endCMD = performance.now(); const startRTT = performance.now(); await y.react("✅"); const endRTT = performance.now(); return message.reply({ content: `The \`${mockInteraction.fullCommandName}\` command took \`${Math.floor((endCMD - startCMD) * 100) / 100}ms\` to execute.\nThe websocket has a latency of \`${Math.floor(client.ws.ping)}ms\`\nThe RTT was \`${Math.floor((endRTT - startRTT) * 100) / 100}ms\``, }); }, };