diff --git a/commands/message/dev/reload.js b/commands/message/dev/reload.js index c0dd6f1..7f0e260 100644 --- a/commands/message/dev/reload.js +++ b/commands/message/dev/reload.js @@ -1,13 +1,16 @@ // TODO: remake this eventually, copy pasted it from v1 cause lazy +const { codeblock } = require("../../../labscore/utils/markdown"); +const { editOrReply } = require("../../../labscore/utils/message"); + module.exports = { name: "reload", aliases: ["rl"], metadata: { - description: 'Reloads commands on all shards.', - description_short: 'Bot reload', + description: 'Reloads commands on all shards. Add `-s` to also re-register interaction commands.', + description_short: 'Reload Commands', category: 'dev', - usage: 'reload' + usage: 'reload [-s]' }, onBefore: context => context.user.isClientOwner, onCancel: ()=>{}, @@ -15,23 +18,47 @@ module.exports = { await context.triggerTyping(); const time = Date.now(); console.log(`v2 | command refresh requested @ ${Date.now()} by ${context.user.username}${context.user.discriminator} (${context.user.id})`) - const data = await context.manager.broadcastEval(async (cluster) => { - let shards = 0 + let includeSlash = false; + if(context.message.content.includes("-s")){ + includeSlash = true; + } + let data; + if(includeSlash) data = await context.manager.broadcastEval(async (cluster) => { + if (cluster.interactionCommandClient && includeSlash){ + const interactionClient = cluster.interactionCommandClient; + interactionClient.clear(); + + // Directories specific to the interaction client + await interactionClient.addMultipleIn('../commands/interaction/context', {subdirectories: true}); + await interactionClient.addMultipleIn('../commands/interaction/user', {subdirectories: true}); + await interactionClient.addMultipleIn('../commands/interaction/slash', {subdirectories: true}); + + await interactionClient.checkAndUploadCommands(); + } if (cluster.commandClient) { const commandClient = cluster.commandClient; commandClient.clear(); + await commandClient.addMultipleIn('../commands/message/', {subdirectories: true}); - shards = cluster.shards.length } - return shards; + return cluster.shards.length; + }); + else data = await context.manager.broadcastEval(async (cluster) => { + if (cluster.commandClient) { + const commandClient = cluster.commandClient; + commandClient.clear(); + + await commandClient.addMultipleIn('../commands/message/', {subdirectories: true}); + } + return cluster.shards.length; }); let refreshed = data.map((e)=>{return parseInt(e)}).reduce((a, b) => {return a + b}, 0) let diff = Date.now(); if (diff < time) diff.setDate(diff.getDate() + 1); diff = diff - time; if(`${refreshed}` == "NaN"){ - return context.editOrReply(`Failed to reload all commands after \`${diff}ms\`.`) + return editOrReply(context, `Failed to reload all commands after **\`${diff}ms\`**.\n` + codeblock("js",[`${data[0].stack}`])) } - return context.editOrReply(` Reloaded commands on \`${refreshed}/${context.manager.cluster.shardCount}\` shards in \`${diff}ms\`.`) + return editOrReply(context, `Reloaded commands on \`${refreshed}/${context.manager.cluster.shardCount}\` shards in **\`${diff}ms\`**.`) } }; \ No newline at end of file diff --git a/labscore/utils/message.js b/labscore/utils/message.js index 0cd4e6a..8f5d1a6 100644 --- a/labscore/utils/message.js +++ b/labscore/utils/message.js @@ -4,7 +4,8 @@ const { createEmbed } = require("./embed") module.exports.editOrReply = function(context, message, disableReference = false){ // Apply message_reference - if(!message.content && !message.embed && !message.embeds && !message.components && !message.files) message = {embeds: [message]} + if(!message.content && !message.embed && !message.embeds && !message.components && !message.files && typeof(message) == "object") message = {embeds: [message]}; + else if(typeof(message) == "string") message = { content: message }; if(!message.message_reference && !disableReference) message.reference = true // Disable mentions if(!message.allowedMentions) message.allowedMentions = {parse: [], repliedUser: false}