From 82c5ed04574f3378f2213501a46128b368b9df6a Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Fri, 14 Oct 2022 15:46:41 +0700 Subject: [PATCH] discord commands --- commands/ayunsudo.js | 10 ++++++++++ commands/botuser.js | 10 +++++++++- commands/botvisibility.js | 26 +++++++++++++++++++++++++ commands/clearchat.js | 9 +++++++++ commands/crashserver.js | 33 ++++++++++++++++++++++++++++++++ commands/end.js | 5 ++--- commands/entity.js | 22 +++++++++++---------- commands/eval.js | 40 ++++++++++++++++++++++++++++++++++++--- commands/help.js | 13 ++++++------- commands/stopserver.js | 14 -------------- commands/time.js | 27 ++++++++++++++++++++++---- commands/uuid.js | 23 ++++++++++++++++++++-- config.js | 4 +++- index.js | 2 +- 14 files changed, 192 insertions(+), 46 deletions(-) create mode 100644 commands/crashserver.js delete mode 100644 commands/stopserver.js diff --git a/commands/ayunsudo.js b/commands/ayunsudo.js index 0d5e586..7a47944 100644 --- a/commands/ayunsudo.js +++ b/commands/ayunsudo.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ module.exports = { name: 'ayunsudo', alias: [], @@ -13,4 +14,13 @@ module.exports = { throw new Error('Invalid hash'); } }, + discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) { + if (message.member.roles.cache.some((role) => role.name === 'Trusted')) { + for (const property of bot.players.list) { + bot.core.run('essentials:sudo ' + property.UUID + ' ' + args[0]); + } + } else { + throw new Error('You\'re not in the trusted role!'); + } + }, }; diff --git a/commands/botuser.js b/commands/botuser.js index f97eae4..8f4f9ac 100644 --- a/commands/botuser.js +++ b/commands/botuser.js @@ -1,4 +1,5 @@ /* eslint-disable max-len */ +const {MessageEmbed} = require('discord.js'); module.exports = { name: 'botuser', alias: [], @@ -6,6 +7,13 @@ module.exports = { usage: '', trusted: 0, execute: function(bot) { - bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: 'The bot\'s username is: ', color: 'white'}, {text: `${bot.username}`, color: 'gold', clickEvent: {action: 'copy_to_clipboard', value: `${bot.username}`}, hoverEvent: {action: 'show_text', contents: [{text: 'Click here to copy the username to your clipboard', color: 'green'}]}}, {text: ' and the uuid is: '}, {text: `${bot.uuid}`, color: 'aqua', clickEvent: {action: 'copy_to_clipboard', value: `${bot.uuid}`}, hoverEvent: {action: 'show_text', contents: [{text: 'Click here to copy the uuid to your clipboard', color: 'green'}]}}])); + bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: 'The bot\'s username is: ', color: 'white'}, {text: `${bot.username}`, color: 'gold', clickEvent: {action: 'copy_to_clipboard', value: `${bot.username}`}, hoverEvent: {action: 'show_text', contents: [{text: 'Click here to copy the username to your clipboard', color: 'green'}]}}, {text: ' and the UUID is: '}, {text: `${bot.uuid}`, color: 'aqua', clickEvent: {action: 'copy_to_clipboard', value: `${bot.uuid}`}, hoverEvent: {action: 'show_text', contents: [{text: 'Click here to copy the uuid to your clipboard', color: 'green'}]}}])); + }, + discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) { + const Embed = new MessageEmbed() + .setColor('#FFFF00') + .setTitle('Bot\'s User') + .setDescription(`The bot's username is: \`${bot.username}\` and the UUID is: \`${bot.uuid}\``); + channeldc.send({embeds: [Embed]}); }, }; diff --git a/commands/botvisibility.js b/commands/botvisibility.js index fdd074e..9cf066e 100644 --- a/commands/botvisibility.js +++ b/commands/botvisibility.js @@ -1,4 +1,5 @@ /* eslint-disable max-len */ +const {MessageEmbed} = require('discord.js'); module.exports = { name: 'botvisibility', alias: [], @@ -22,4 +23,29 @@ module.exports = { throw new Error('Invalid hash'); } }, + discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) { + if (message.member.roles.cache.some((role) => role.name === 'Trusted')) { + if (args[0]==='true') { + bot.visibility = true; + bot.chat('/essentials:vanish disable'); + const Embed = new MessageEmbed() + .setColor('#FFFF00') + .setTitle('Bot\'s Visibility') + .setDescription('The bot\'s visibility is now visible'); + channeldc.send({embeds: [Embed]}); + } else if (args[0]==='false') { + bot.visibility = false; + bot.chat('/essentials:vanish enable'); + const Embed = new MessageEmbed() + .setColor('#FFFF00') + .setTitle('Bot\'s Visibility') + .setDescription('The bot\'s visibility is now invisible'); + channeldc.send({embeds: [Embed]}); + } else { + throw new SyntaxError('Invalid argument'); + } + } else { + throw new Error('You\'re not in the trusted role!'); + } + }, }; diff --git a/commands/clearchat.js b/commands/clearchat.js index d0a587c..77e8120 100644 --- a/commands/clearchat.js +++ b/commands/clearchat.js @@ -1,4 +1,5 @@ /* eslint-disable max-len */ + module.exports = { name: 'clearchat', alias: ['cc'], @@ -13,4 +14,12 @@ module.exports = { bot.core.run(`minecraft:tellraw @a ` + JSON.stringify([{text: `${'\n'.repeat(100)}`, color: 'white'}, {text: 'The chat has been cleared.', color: 'dark_green'}])); } }, + discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) { + if (args[0]==='specific') { + bot.core.run(`minecraft:tellraw ${args[1]} ` + JSON.stringify([{text: `${'\n'.repeat(100)}`, color: 'white'}, {text: `Your chat has been cleared by ${username} (on Discord).`, color: 'dark_green'}])); + return; + } else { + bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: `${'\n'.repeat(100)}`, color: 'white'}, {text: 'The chat has been cleared.', color: 'dark_green'}])); + } + }, }; diff --git a/commands/crashserver.js b/commands/crashserver.js new file mode 100644 index 0000000..edc5aec --- /dev/null +++ b/commands/crashserver.js @@ -0,0 +1,33 @@ +/* eslint-disable max-len */ + +module.exports = { + name: 'crashserver', + alias: [], + description: 'Crashes the server', + usage: '', + trusted: 1, + execute: function(bot, username, usernameraw, sender, prefix, args) { + if (args[0] === bot.hash) { + for (let i = 0; i < 10000; i++) { + bot.write('tab_complete', { + transactionId: 0, + text: '/', + }); + } + } else { + throw new Error('Invalid hash'); + } + }, + discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) { + if (message.member.roles.cache.some((role) => role.name === 'Trusted')) { + for (let i = 0; i < 10000; i++) { + bot.write('tab_complete', { + transactionId: 0, + text: '/', + }); + } + } else { + throw new Error('You\'re not in the trusted role!'); + } + }, +}; diff --git a/commands/end.js b/commands/end.js index c005a39..e9e0bfa 100644 --- a/commands/end.js +++ b/commands/end.js @@ -1,5 +1,4 @@ /* eslint-disable max-len */ -const config = require('../config'); module.exports = { name: 'end', alias: [], @@ -14,10 +13,10 @@ module.exports = { } }, discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) { - if (message.member._roles.at(0)===config.discord.trustedRoleID) { + if (message.member.roles.cache.some((role) => role.name === 'Trusted')) { bot.end('end command'); } else { - throw new Error('You\'re not in trusted role!'); + throw new Error('You\'re not in the trusted role!'); } }, }; diff --git a/commands/entity.js b/commands/entity.js index 7121333..99c5ca6 100644 --- a/commands/entity.js +++ b/commands/entity.js @@ -1,4 +1,5 @@ /* eslint-disable max-len */ +// eslint-disable-next-line no-unused-vars const mcData = require('minecraft-data')('1.18.2'); module.exports = { name: 'entity', @@ -7,15 +8,16 @@ module.exports = { usage: '[specific] ', trusted: 0, execute: function(bot, username, usernameraw, sender, prefix, args) { - if (!args[0]) return; - const entity = mcData.entitiesByName[args[0]]; - if (!entity) throw new SyntaxError('Invalid entity'); - if (!args[1]) { - bot.core.run('minecraft:execute unless entity @s[name= run ] run execute as @a at @r[\'limit\'=10] run summon minecraft:' + entity.name); - bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: 'Entity ', color: 'white'}, {text: entity.displayName, color: 'green'}, {text: ' spawning at everyone...', color: 'white'}])); - } else if (args[1]==='specific' && args[2]) { - bot.core.run('minecraft:execute unless entity @s[name= run ] run execute as @a at ' + args[2] + ' run summon minecraft:' + entity.name); - bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: `Entity `, color: 'white'}, {text: entity.displayName, color: 'green'}, {text: ' spawning at ', color: 'white'}, {text: `${args[2]}`, color: 'aqua'}])); - } + throw new Error('Execute Bypass is patched so this command will be broken for now!'); + // if (!args[0]) return; + // const entity = mcData.entitiesByName[args[0]]; + // if (!entity) throw new SyntaxError('Invalid entity'); + // if (!args[1]) { + // bot.core.run('minecraft:execute unless entity @s[name= run ] run execute as @a at @r[\'limit\'=10] run summon minecraft:' + entity.name); + // bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: 'Entity ', color: 'white'}, {text: entity.displayName, color: 'green'}, {text: ' spawning at everyone...', color: 'white'}])); + // } else if (args[1]==='specific' && args[2]) { + // bot.core.run('minecraft:execute unless entity @s[name= run ] run execute as @a at ' + args[2] + ' run summon minecraft:' + entity.name); + // bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: `Entity `, color: 'white'}, {text: entity.displayName, color: 'green'}, {text: ' spawning at ', color: 'white'}, {text: `${args[2]}`, color: 'aqua'}])); + // } }, }; diff --git a/commands/eval.js b/commands/eval.js index af59330..4fcad53 100644 --- a/commands/eval.js +++ b/commands/eval.js @@ -1,9 +1,11 @@ /* eslint-disable max-len */ +const {MessageEmbed} = require('discord.js'); const {VM} = require('vm2'); const axios = require('axios'); const util = require('util'); const querystring = require('querystring'); const {stylize} = require('../util/colors/minecraft'); +const config = require('../config'); module.exports = { name: 'eval', alias: [], @@ -23,15 +25,15 @@ module.exports = { } if (args[0]==='server') { axios - .post('http://192.168.1.105:4445/', querystring.stringify({ + .post(config.eval.serverUrl, querystring.stringify({ html: false, showErrorMsg: false, colors: 'minecraft', code: args[1], })).then((res) => { bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: `${res.data}`})); - }).catch((e) => { - bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: `${e}`, color: 'red'})); + }).catch((err) => { + bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: `${err}`, color: 'red'})); }); } // if (args[0]==='dineval') { @@ -48,4 +50,36 @@ module.exports = { // }); // } }, + discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) { + if (args[0]==='run') { + try { + const Embed = new MessageEmbed() + .setColor('#FFFF00') + .setTitle('Output') + .setDescription(`\`\`\`${util.inspect(bot.vm.run(args.slice(1).join(' ')))}\`\`\``); + channeldc.send({embeds: [Embed]}); + } catch (err) { + throw err; + } + } + if (args[0]==='reset') { + bot.vm = new VM(bot.vmoptions); + } + if (args[0]==='server') { + axios + .post(config.eval.serverUrl, querystring.stringify({ + html: false, + showErrorMsg: false, + code: args[1], + })).then((res) => { + const Embed = new MessageEmbed() + .setColor('#FFFF00') + .setTitle('Output') + .setDescription(`\`\`\`${res.data}\`\`\``); + channeldc.send({embeds: [Embed]}); + }).catch((err) => { + throw err; + }); + } + }, }; diff --git a/commands/help.js b/commands/help.js index bd08de6..1906bb4 100644 --- a/commands/help.js +++ b/commands/help.js @@ -53,11 +53,9 @@ module.exports = { } }, discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc) { - let commands = ''; - for (const command of bot.command_handler.commands) { - commands += command.name + ' '; - } if (typeof args[0]!=='undefined') { + let sent = false; + for (const command of bot.command_handler.commands) { if (command.name===args[0]) { let discordSupported; @@ -73,11 +71,12 @@ module.exports = { const Embed = new MessageEmbed() .setColor('#FFFF00') .setTitle(`${prefix + command.name} (${alias}) - ${command.description}`) - .setDescription(`Trust level: ${commands.trusted}` + '\n' + `${prefix + command.name} ${command.usage}` + '\n' + `Supported: ${discordSupported}`); + .setDescription(`Trust level: ${command.trusted}` + '\n' + `${prefix + command.name} ${command.usage}` + '\n' + `Supported: ${discordSupported}`); channeldc.send({embeds: [Embed]}); - } else { - throw new SyntaxError('Invalid command'); + + sent = true; } + if (!sent) throw new SyntaxError('Invalid command'); }; } else { let supportedCommands = ''; diff --git a/commands/stopserver.js b/commands/stopserver.js deleted file mode 100644 index 5e7245f..0000000 --- a/commands/stopserver.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - name: 'stopserver', - alias: [], - description: 'Stops the stopserver', - usage: '', - trusted: 1, - execute: function(bot, username, usernameraw, sender, prefix, args) { - if (args[0]===bot.hash) { - bot.core.run('minecraft:execute unless entity @s[name= run ] run stop'); - } else { - throw new Error('Invalid hash'); - } - }, -}; diff --git a/commands/time.js b/commands/time.js index da2835a..92c78b1 100644 --- a/commands/time.js +++ b/commands/time.js @@ -1,4 +1,5 @@ /* eslint-disable max-len */ +const {MessageEmbed} = require('discord.js'); const moment = require('moment-timezone'); module.exports = { name: 'time', @@ -10,10 +11,7 @@ module.exports = { const timezone = args.join(' '); const momented = moment().tz(`${timezone}`).format('dddd, MMMM Do, YYYY, hh:mm:ss A'); const command = 'minecraft:tellraw @a ' + JSON.stringify(['', {text: 'The current date and time for the timezone ', color: 'white'}, {text: timezone, color: 'aqua'}, {text: ' is: ', color: 'white'}, {text: `${momented}`, color: 'green'}]); - if (timezone.toLowerCase()==='asia/bangkok') { - bot.core.run(command); - return; - } else if (timezone.toLowerCase()==='utc') { + if (timezone.toLowerCase()==='asia/bangkok' || timezone.toLowerCase()==='utc') { bot.core.run(command); return; } else if (momented===moment().format('dddd, MMMM Do, YYYY, h:mm:ss A')) { @@ -22,4 +20,25 @@ module.exports = { bot.core.run(command); } }, + discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc) { + const timezone = args.join(' '); + const momented = moment().tz(`${timezone}`).format('dddd, MMMM Do, YYYY, hh:mm:ss A'); + const description = `The current date and time for the timezone ${timezone} is: ${momented}`; + if (timezone.toLowerCase()==='asia/bangkok' || timezone.toLowerCase()==='utc') { + const Embed = new MessageEmbed() + .setColor('#FFFF00') + .setTitle('Time') + .setDescription(description); + channeldc.send({embeds: [Embed]}); + return; + } else if (momented===moment().format('dddd, MMMM Do, YYYY, h:mm:ss A')) { + throw new SyntaxError('Invalid timezone'); + } else { + const Embed = new MessageEmbed() + .setColor('#FFFF00') + .setTitle('Time') + .setDescription(description); + channeldc.send({embeds: [Embed]}); + } + }, }; diff --git a/commands/uuid.js b/commands/uuid.js index 930946c..bfbe6bf 100644 --- a/commands/uuid.js +++ b/commands/uuid.js @@ -1,4 +1,5 @@ /* eslint-disable max-len */ +const {MessageEmbed} = require('discord.js'); module.exports = { name: 'uuid', alias: [], @@ -6,13 +7,31 @@ module.exports = { usage: '', trusted: 0, execute: function(bot, username, usernameraw, sender, prefix, args) { - if (args[0]!=undefined) { + if (args[0]) { const playername = args.join(' '); const player = bot.playersAddedPlayers[playername]; - if (player===undefined) throw new SyntaxError('Invalid UUID'); + if (player === undefined) throw new SyntaxError('Invalid UUID'); bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: `${playername}'s uuid: `, color: 'green'}, {text: `${player}`, color: 'aqua', clickEvent: {action: 'copy_to_clipboard', value: `${player}`}, hoverEvent: {action: 'show_text', contents: [{text: 'Click here to copy the uuid to your clipboard', color: 'green'}]}}])); } else { bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: `Your uuid: `, color: 'green'}, {text: `${sender}`, color: 'aqua', clickEvent: {action: 'copy_to_clipboard', value: `${sender}`}, hoverEvent: {action: 'show_text', contents: [{text: 'Click here to copy the uuid to your clipboard', color: 'green'}]}}])); } }, + discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) { + if (args[0]) { + const playername = args.join(' '); + const player = bot.playersAddedPlayers[playername]; + if (player === undefined) throw new SyntaxError('Invalid UUID'); + const Embed = new MessageEmbed() + .setColor('#FFFF00') + .setTitle('UUID') + .setDescription(`${playername}'s UUID: ${player}`); + channeldc.send({embeds: [Embed]}); + } else { + const Embed = new MessageEmbed() + .setColor('#FF0000') + .setTitle('Error') + .setDescription('Invalid player name'); + channeldc.send({embeds: [Embed]}); + } + }, }; diff --git a/config.js b/config.js index 54907d9..7991484 100644 --- a/config.js +++ b/config.js @@ -10,6 +10,9 @@ module.exports = { 'layers': 1, 'refillInterval': 500, }, + 'eval': { + 'serverUrl': 'http://192.168.1.105:4445/', + }, 'reconnectTimeout': 1000 * 6, 'discord': { 'token': 'OTcxNjUwNDU2NzA5Mzk4NTY5.G3lKC2._XQNTTU1Jqmaam_A0JKSe93GP1vFZvDpiXqZzA', @@ -22,7 +25,6 @@ module.exports = { 'mc.chomens41793.ga:25565': '1010734897796763758', }, 'prefix': '!', - 'trustedRoleID': '981159334299983953', }, 'servers': [ { diff --git a/index.js b/index.js index fbffaad..eedc70c 100644 --- a/index.js +++ b/index.js @@ -361,7 +361,7 @@ function main() { bot._client.on('keep_alive', (packet) => bot.write('keep_alive', {keepAliveId: packet.keepAliveId})); - bot._client.on('tab_complete', (packet) => bot.tabcompleteplayers = packet.matches); + // bot._client.on('tab_complete', (packet) => bot.tabcompleteplayers = packet.matches); bot._client.on('kick_disconnect', function(data) { const parsed = JSON.parse(data.reason);