mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 22:23:03 -04:00
add ability to reload slash commands
This commit is contained in:
parent
33d518b262
commit
ee2b4a22f4
2 changed files with 38 additions and 10 deletions
|
@ -1,13 +1,16 @@
|
||||||
// TODO: remake this eventually, copy pasted it from v1 cause lazy
|
// 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 = {
|
module.exports = {
|
||||||
name: "reload",
|
name: "reload",
|
||||||
aliases: ["rl"],
|
aliases: ["rl"],
|
||||||
metadata: {
|
metadata: {
|
||||||
description: 'Reloads commands on all shards.',
|
description: 'Reloads commands on all shards. Add `-s` to also re-register interaction commands.',
|
||||||
description_short: 'Bot reload',
|
description_short: 'Reload Commands',
|
||||||
category: 'dev',
|
category: 'dev',
|
||||||
usage: 'reload'
|
usage: 'reload [-s]'
|
||||||
},
|
},
|
||||||
onBefore: context => context.user.isClientOwner,
|
onBefore: context => context.user.isClientOwner,
|
||||||
onCancel: ()=>{},
|
onCancel: ()=>{},
|
||||||
|
@ -15,23 +18,47 @@ module.exports = {
|
||||||
await context.triggerTyping();
|
await context.triggerTyping();
|
||||||
const time = Date.now();
|
const time = Date.now();
|
||||||
console.log(`v2 | command refresh requested @ ${Date.now()} by ${context.user.username}${context.user.discriminator} (${context.user.id})`)
|
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 includeSlash = false;
|
||||||
let shards = 0
|
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) {
|
if (cluster.commandClient) {
|
||||||
const commandClient = cluster.commandClient;
|
const commandClient = cluster.commandClient;
|
||||||
commandClient.clear();
|
commandClient.clear();
|
||||||
|
|
||||||
await commandClient.addMultipleIn('../commands/message/', {subdirectories: true});
|
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 refreshed = data.map((e)=>{return parseInt(e)}).reduce((a, b) => {return a + b}, 0)
|
||||||
let diff = Date.now();
|
let diff = Date.now();
|
||||||
if (diff < time) diff.setDate(diff.getDate() + 1);
|
if (diff < time) diff.setDate(diff.getDate() + 1);
|
||||||
diff = diff - time;
|
diff = diff - time;
|
||||||
if(`${refreshed}` == "NaN"){
|
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\`**.`)
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -4,7 +4,8 @@ const { createEmbed } = require("./embed")
|
||||||
|
|
||||||
module.exports.editOrReply = function(context, message, disableReference = false){
|
module.exports.editOrReply = function(context, message, disableReference = false){
|
||||||
// Apply message_reference
|
// 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
|
if(!message.message_reference && !disableReference) message.reference = true
|
||||||
// Disable mentions
|
// Disable mentions
|
||||||
if(!message.allowedMentions) message.allowedMentions = {parse: [], repliedUser: false}
|
if(!message.allowedMentions) message.allowedMentions = {parse: [], repliedUser: false}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue