From 9665851c2a6c4162f27d197e15b12017ff7567da Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Thu, 29 Jul 2021 15:04:47 -0600 Subject: [PATCH] dev command shit --- commands/dev/eval.js | 22 ++++++++++++++++------ commands/dev/execute.js | 38 ++++++++++++++++++++++++++++++++++++++ commands/dev/reload.js | 21 ++++++++++++++++++++- 3 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 commands/dev/execute.js diff --git a/commands/dev/eval.js b/commands/dev/eval.js index 97cee4a..61aca01 100644 --- a/commands/dev/eval.js +++ b/commands/dev/eval.js @@ -16,14 +16,24 @@ module.exports = { }, execute(message, msg, args, cmd, prefix, mention, client) { try { + let timer = new Date().getTime(); + if (!client.developers.includes(message.author.id)) {return message.channel.send("Sorry, but I've got trust issues, so only me devs can go commanding me around like that.");}; - if (!args.length) return message.channel.send(`Syntax: \`${prefix}eval \``); + if (!args.length) return message.channel.send(`Syntax: \`${prefix}eval \``); + + if (!args.length) {return message.reply("Please specify a bio!");} + let args2 = msg.startsWith(prefix) + ? message.content.slice(prefix.length).trim().split(/ +/g) + : msg.startsWith('<@!') + ? message.content.slice(4 + client.user.id.length).trim().split(/ +/g) + : message.content.slice(3 + client.user.id.length).trim().split(/ +/g); + args2.shift(); args2.shift(); - let options = new TagFilter([new Tag(['s', 'silent', 'nr', 'noreply'], 'silent', 'toggle')]).test(args[0]); - if (options.silent) {args.shift();} + let options = new TagFilter([new Tag(['s', 'silent', 'nr', 'noreply'], 'silent', 'toggle')]).test(args2[0]); + if (options.silent) {args2.shift();} if (!args.length) {return message.channel.send("Silly goose, if you want me to do something, you have to tell me what!");} - const result = new Promise((resolve) => resolve(eval(args.join(' ')))); + const result = new Promise((resolve) => resolve(eval(args2.join(' ')))); return result.then((output) => { if (typeof output !== 'string') { output = require('util').inspect(output, {depth: 0}); @@ -36,12 +46,12 @@ module.exports = { .setTitle('Client Evaluation') .setDescription(`\`\`\`js\n${output}\n\`\`\``) .setColor('328ba8') - .setFooter(`Luno`, client.user.avatarURL()) + .setFooter(`Luno | Evaluated in ${new Date().getTime() - timer}ms`, client.user.avatarURL()) .setTimestamp()); }).catch(error => {return message.channel.send(`Error: \`${error}\`.`);}); } catch (error) { let date = new Date; date = date.toString().slice(date.toString().search(":") - 2, date.toString().search(":") + 6); - console.error(`\n${chalk.red('[ERROR]')} >> ${chalk.yellow(`At [${date}] | Occurred while trying to run n?eval`)}`, error); + console.error(`\n${chalk.red('[ERROR]')} >> ${chalk.yellow(`At [${date}] | Occurred while trying to run l.eval`)}`, error); return message.channel.send(`Error: \`${error}\`.`); } }, diff --git a/commands/dev/execute.js b/commands/dev/execute.js new file mode 100644 index 0000000..5db0b64 --- /dev/null +++ b/commands/dev/execute.js @@ -0,0 +1,38 @@ +const Discord = require('discord.js'); + +const cp = require("child_process"); + +module.exports = { + name: "Execute", + aliases: ['exec'], + meta: { + category: 'Developer', + description: "Execute a console command", + syntax: '`Execute `', + extra: null + }, + help: "Dev only! Executes a console command", + async execute(message, msg, args, cmd, prefix, mention, client) { + if (!client.developers.includes(message.author.id)) {return message.channel.send("You must be a developer to do this!");} + if (!args.length) {return message.channel.send(`Syntax: \`${prefix}execute \``);} + return cp.exec(args.join(" "), function(error, stdout, stderr) { + if (error) { + return message.channel.send(new Discord.MessageEmbed() + .setTitle("Error") + .setDescription(`\`\`\`${error}\`\`\``) + .setColor("ff446a") + .setFooter("Luno", client.user.avatarURL()) + .setTimestamp() + ); + } + + return message.channel.send(new Discord.MessageEmbed() + .setTitle("Execution Successful") + .setDescription(`\`\`\`${stdout}\`\`\``) + .setColor("328ba8") + .setFooter("Luno", client.user.avatarURL()) + .setTimestamp() + ); + }); + } +}; \ No newline at end of file diff --git a/commands/dev/reload.js b/commands/dev/reload.js index 9b48e2c..85272bc 100644 --- a/commands/dev/reload.js +++ b/commands/dev/reload.js @@ -21,6 +21,7 @@ module.exports = { }, async execute(message, msg, args, cmd, prefix, mention, client) { if (!args.length) { + let timer = new Date().getTime(); if (!client.developers.includes(message.author.id) && message.author.id !== "480535078150340609") {return message.channel.send("You must be a Luno developer in order to do this!");} let commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); @@ -66,7 +67,7 @@ module.exports = { console.log(`\n${chalk.gray('[INFO]')} >> ${chalk.hex('ff4fd0')(`Client refresh successful`)}\n`); - return message.channel.send("Done!") + return message.channel.send(`Done! Reloaded ${commands.length} commands, ${eventFilter.length} events, and ${responses.length} responses in ${new Date().getTime() - timer}ms.`); } if (['l', 'log', 'ns', 'nosilent', 'notsilent'].includes(args[0].toLowerCase())) { ['commands', 'aliases'].forEach(x => client[x] = new Discord.Collection()); @@ -74,6 +75,24 @@ module.exports = { ['command', 'event', 'response'].forEach(x => require(`./${x}`)(client)); return message.channel.send("Done!"); } + + if (['c', 'cmd', 'command'].includes(args[0].toLowerCase())) { + let timer = new Date().getTime(); + if (!args[1]) {return message.channel.send("Oi there you headass! You have to actually tell me what command to reload!");} + let tc = args[1].toLowerCase(); + let lf = client.commands.get(tc) || client.commands.get(client.aliases.get(tc)); + lf = lf ? lf.name : tc; + let res; + fs.readdirSync(`./commands`).forEach(x => { + if (!x.includes('.')) {fs.readdirSync(`./commands/${x}`).forEach(y => {if (`${lf}.js` === y) {res = `../../commands/${x}/${y}`;}});} + else {if (x === `${lf}.js`) {res = `../../commands/${x}`;}} + }); + if (!res) {return message.channel.send("I can't reload that command as I can't find file!");} + if (require.resolve(res) in require.cache) {delete require.cache[require.resolve(res)];} + client.commands.set(lf, require(res)); + return message.channel.send(`Reloaded command \`${lf}\` in ${new Date().getTime() - timer}ms`); + } + else {return message.channel.send("Oi! 'log' is the only valid arg to use. Use no args if you want a cleaner console output instead.");} } }; \ No newline at end of file