diff --git a/commands/help.js b/commands/help.js index 1906bb4..1232a06 100644 --- a/commands/help.js +++ b/commands/help.js @@ -42,9 +42,9 @@ module.exports = { bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: prefix + command.name, color: 'gold'}, {text: ' ' + command.usage, color: 'aqua'}])); } - if (command.name===args[0]) m(); + if (command.name === args[0]) m(); for (const alias of command.alias) { - if (alias===args[0]) m(); + if (alias === args[0]) m(); } }; } else { @@ -52,12 +52,10 @@ module.exports = { bot.core.run('minecraft:tellraw @a ' + JSON.stringify([pre, {text: generalCommands, color: 'green'}, {text: trustedCommands, color: 'red'}, {text: ownerCommands, color: 'dark_red'}])); } }, - discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc) { + discordExecute: async function(bot, username, usernameraw, sender, prefix, args, channeldc) { if (typeof args[0]!=='undefined') { - let sent = false; - for (const command of bot.command_handler.commands) { - if (command.name===args[0]) { + function m() { let discordSupported; let alias = command.name; if (typeof command.discordExecute==='undefined') { @@ -71,12 +69,17 @@ module.exports = { const Embed = new MessageEmbed() .setColor('#FFFF00') .setTitle(`${prefix + command.name} (${alias}) - ${command.description}`) - .setDescription(`Trust level: ${command.trusted}` + '\n' + `${prefix + command.name} ${command.usage}` + '\n' + `Supported: ${discordSupported}`); + .setDescription(`Trust level: ${command.trusted}` + '\n' + + `Supported: ${discordSupported}` + '\n' + + `${prefix + command.name} ${command.usage}`, + ); channeldc.send({embeds: [Embed]}); - - sent = true; } - if (!sent) throw new SyntaxError('Invalid command'); + + if (command.name === args[0]) m(); + for (const alias of command.alias) { + if (alias === args[0]) m(); + } }; } else { let supportedCommands = ''; diff --git a/commands/translate.js b/commands/translate.js index a83197d..58f4b2e 100644 --- a/commands/translate.js +++ b/commands/translate.js @@ -1,4 +1,5 @@ /* eslint-disable max-len */ +const {MessageEmbed} = require('discord.js'); const translate = require('@vitalets/google-translate-api'); module.exports = { name: 'translate', @@ -14,4 +15,20 @@ module.exports = { bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: String(e), color: 'red'})); } }, + discordExecute: async function(bot, username, usernameraw, sender, prefix, args, channeldc, message) { + try { + const res = await translate(args.slice(2).join(' '), {from: args[0], to: args[1]}); + const Embed = new MessageEmbed() + .setColor('#FFFF00') + .setTitle('Result') + .setDescription(res.text); + channeldc.send({embeds: [Embed]}); + } catch (e) { + const Embed = new MessageEmbed() + .setColor('#FF0000') + .setTitle('Error') + .setDescription(`\`\`\`${e}\`\`\``); + channeldc.send({embeds: [Embed]}); + } + }, }; diff --git a/commands/uptime.js b/commands/uptime.js index 30850c2..6a3ce34 100644 --- a/commands/uptime.js +++ b/commands/uptime.js @@ -1,4 +1,5 @@ /* eslint-disable max-len */ +const {MessageEmbed} = require('discord.js'); const {secondsToHms} = require('../util/secondToHms'); module.exports = { name: 'uptime', @@ -7,6 +8,13 @@ module.exports = { usage: '', trusted: 0, execute: function(bot) { - bot.core.run(`minecraft:tellraw @a ["",{"text":"The bot's uptime is ","color":"white"},{"text":"${secondsToHms(Math.floor(performance.now() / 1000))}","color":"green"}]`); return; + bot.core.run('minecraft:tellraw @a ' + JSON.stringify(['', {text: 'The bot\'s uptime is ', color: 'white'}, {text: `${secondsToHms(Math.floor(performance.now() / 1000))}`, color: 'green'}])); + }, + discordExecute: function(bot, username, usernameraw, sender, prefix, args, channeldc, message) { + const Embed = new MessageEmbed() + .setColor('#FFFF00') + .setTitle('Bot\'s Uptime') + .setDescription(`The bot\'s uptime is ${secondsToHms(Math.floor(performance.now() / 1000))}`); + channeldc.send({embeds: [Embed]}); }, };