From 7576968a062988cbaf8cb6f403b715c0611524bd Mon Sep 17 00:00:00 2001 From: ry Date: Sun, 16 Feb 2020 20:43:07 +0100 Subject: [PATCH] add dev commands back --- DiscordModules/Developers/blacklist.js | 25 ++++++++ DiscordModules/Developers/dig.js | 45 +++++++++++++++ DiscordModules/Developers/eval.js | 80 ++++++++++++++++++++++++++ DiscordModules/Developers/exec.js | 28 +++++++++ DiscordModules/Developers/reload.js | 38 ++++++++++++ DiscordModules/Developers/stop.js | 19 ++++++ DiscordModules/Developers/update.js | 34 +++++++++++ 7 files changed, 269 insertions(+) create mode 100644 DiscordModules/Developers/blacklist.js create mode 100644 DiscordModules/Developers/dig.js create mode 100755 DiscordModules/Developers/eval.js create mode 100644 DiscordModules/Developers/exec.js create mode 100755 DiscordModules/Developers/reload.js create mode 100755 DiscordModules/Developers/stop.js create mode 100644 DiscordModules/Developers/update.js diff --git a/DiscordModules/Developers/blacklist.js b/DiscordModules/Developers/blacklist.js new file mode 100644 index 0000000..aa92f54 --- /dev/null +++ b/DiscordModules/Developers/blacklist.js @@ -0,0 +1,25 @@ +const Command = require('../../src/structures/Command'); +module.exports = class Blacklist extends Command { + constructor() { + super({ + name: 'blacklist', + description: 'Master the Blacklist', + aliases: ['bl'], + module: 'Developers', + cooldown: 0, + guildOnly: false, + developerOnly: true + }); + } + + async command(ctx) { + console.log(ctx.args) + let ACTION = ctx.args[0] + let ID = ctx.args[1] + let REASON = ctx.args.shift().shift().join(' ') + // let REASON = ctx.args[2] + + let X = await ctx.utils.db.blacklist(ID, ACTION, REASON) + console.log(X) + } +}; \ No newline at end of file diff --git a/DiscordModules/Developers/dig.js b/DiscordModules/Developers/dig.js new file mode 100644 index 0000000..42f080b --- /dev/null +++ b/DiscordModules/Developers/dig.js @@ -0,0 +1,45 @@ +const Command = require("../../src/structures/Command"); +const exec = require("shell-exec"); +const dig = require("node-dig-dns"); +const { + MessageEmbed +} = require("discord.js"); +let DomainReg = new RegExp( + `(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]` +); +module.exports = class Dig extends Command { + constructor() { + super({ + name: "dig", + description: "dig website dns information stuff", + aliases: [], + module: "Developers", + cooldown: 10, + guildOnly: false, + developerOnly: true, + nsfw: false + }); + } + + async command(ctx) { + let count = 0; + let domain = ctx.args[0]; + let type = ctx.args[1]; + const DIG = new MessageEmbed().setTitle(`${domain} (${type})`); + if (domain.match(DomainReg)) { + try { + let result = await dig([domain, type]); + + result.answer.forEach(r => { + count++; + DIG.addField(`Answer ${count}`, r.value); + }); + } catch (error) { + DIG.setDescription( + `Either the Domain you are trying to dig for doesn't exist or the record you are requesting does not exist.` + ); + } + } + ctx.send(DIG); + } +}; \ No newline at end of file diff --git a/DiscordModules/Developers/eval.js b/DiscordModules/Developers/eval.js new file mode 100755 index 0000000..a1223e4 --- /dev/null +++ b/DiscordModules/Developers/eval.js @@ -0,0 +1,80 @@ +const Command = require('../../src/structures/Command'); +const { table } = require('quick.db'); +const Servers = new table('servers'); +const Users = new table('users'); +const Bot = new table('bot'); + +const clean = (text) => { + if (typeof text == 'string') + return text.replace(/`/g, '`' + String.fromCharCode(8203)).replace(/@/g, '@' + String.fromCharCode(8203)); + else return text; +}; + +module.exports = class Eval extends Command { + constructor() { + super({ + name: 'eval', + description: 'Run JavaScript code directly from the process.', + aliases: [ 'ev', 'e' ], + module: 'Developers', + cooldown: 0, + guildOnly: false, + developerOnly: true + }); + } + + async command(ctx) { + if (!ctx.args.length) return; + + const client = ctx.client; + + let code = ctx.args.join(' '); + let silent = false; + + if (code.endsWith('-s')) (code = code.split('-s')[0]), (silent = true); + if (code.endsWith('--silent')) (code = code.split('--silent')[0]), (silent = true); + + try { + let evaled = await eval(code); + + if (typeof evaled != 'string') + evaled = require('util').inspect(evaled, false, await ctx.db.backend.get('eval')); + + evaled.replace(new RegExp(client.token.replace(/\./g, '\\.', 'g')), 'uwu'); + + if (!silent) { + ctx + .send(`\`\`\`js\n${clean(evaled)}\n\`\`\``) + .then(async (m) => { + await m.react('📥'); + await m.react('🗑'); + }) + .catch((err) => { + ctx + .send(`\`Content is over 2,000 characters: react to upload to Hastebin\``) + .then(async (m) => { + client.lastEval = clean(evaled); + + await m.react('📥'); + await m.react('🗑'); + }); + }); + } + } catch (error) { + ctx + .send(`\`\`\`js\n${clean(error)}\n\`\`\``) + .then(async (m) => { + await m.react('📥'); + await m.react('🗑'); + }) + .catch((err) => { + ctx.send(`\`Content is over 2,000 characters: react to upload to Hastebin\``).then(async (m) => { + client.lastEval = clean(error); + + await m.react('📥'); + await m.react('🗑'); + }); + }); + } + } +}; diff --git a/DiscordModules/Developers/exec.js b/DiscordModules/Developers/exec.js new file mode 100644 index 0000000..be6ceb6 --- /dev/null +++ b/DiscordModules/Developers/exec.js @@ -0,0 +1,28 @@ +const Command = require('../../src/structures/Command'); +const exec = require('shell-exec'); +module.exports = class Exec extends Command { + constructor() { + super({ + name: 'exec', + description: 'Execute shell commands', + aliases: [ 'ex' ], + module: 'Developers', + cooldown: 1, + guildOnly: false, + developerOnly: true, + nsfw: false + }); + } + + async command(ctx) { + const trying = await ctx.send('Attempting to execute ' + ctx.utils.format.bold(ctx.args.join(' '))); + + await exec(ctx.args.join(' ')) + .then((r) => { + trying.edit('```bash\n' + r.stdout + '```'); + }) + .catch((error) => { + trying.edit('Failed to execute ' + ctx.utils.format.bold(ctx.args.join(' '))); + }); + } +}; diff --git a/DiscordModules/Developers/reload.js b/DiscordModules/Developers/reload.js new file mode 100755 index 0000000..b293e72 --- /dev/null +++ b/DiscordModules/Developers/reload.js @@ -0,0 +1,38 @@ +const Command = require('../../src/structures/Command'); + +module.exports = class Reload extends Command { + constructor() { + super({ + name: 'reload', + description: 'Reload a command without restarting the process.', + aliases: [ 're' ], + module: 'Developers', + cooldown: 0, + guildOnly: false, + developerOnly: true + }); + } + + async command(ctx) { + if (!ctx.args.length) return; + const date = Date.now(); + + const data = ctx.args[0]; + const [ module, command ] = data.split('/'); + + if (!module || !command) return; + + try { + delete require.cache[require.resolve(`../${module}/${command}`)]; + delete ctx.client.commands.get(command); + + const cmd = require(`../${module}/${command}`); + const Command = new cmd(); + ctx.client.commands.set(Command.name, Command); + + return ctx.send(`Reloaded \`${Command.name}\` in ${(Date.now() - date) / 1000}s.`); + } catch (err) { + return ctx.send(`Failed to reload the command.\n\`${err}\``); + } + } +}; diff --git a/DiscordModules/Developers/stop.js b/DiscordModules/Developers/stop.js new file mode 100755 index 0000000..9ef0893 --- /dev/null +++ b/DiscordModules/Developers/stop.js @@ -0,0 +1,19 @@ +const Command = require('../../src/structures/Command'); +module.exports = class Stop extends Command { + constructor() { + super({ + name: 'stop', + description: 'Stops the bot', + aliases: [], + module: 'Developers', + cooldown: 0, + guildOnly: false, + developerOnly: true + }); + } + + async command(ctx) { + await ctx.send('Restarting.'); + process.exit(); + } +}; diff --git a/DiscordModules/Developers/update.js b/DiscordModules/Developers/update.js new file mode 100644 index 0000000..b98bf5e --- /dev/null +++ b/DiscordModules/Developers/update.js @@ -0,0 +1,34 @@ +const Command = require('../../src/structures/Command'); +const exec = require('shell-exec'); +module.exports = class Update extends Command { + constructor() { + super({ + name: 'update', + description: 'Execute shell commands', + aliases: [ 'up', 'pull' ], + module: 'Developers', + cooldown: 1, + guildOnly: false, + developerOnly: true, + nsfw: false + }); + } + + async command(ctx) { + const trying = await ctx.send( + `${ctx.utils.emotes.random.loading} Getting the latest updates from ${ctx.config.source.replace( + 'https://', + '' + )} ${ctx.utils.emotes.random.loading}` + ); + + await exec('git pull') + .then((r) => { + trying.edit('```fix\n' + r.stdout + '```'); + }) + .catch((error) => { + trying.edit(`Failed to get the latest updates.`); + console.error(error); + }); + } +};