fix help + add uptime, translate discord support

This commit is contained in:
ChomeNS 2022-10-15 11:45:40 +07:00
parent 479e132e15
commit 21a93ef844
3 changed files with 39 additions and 11 deletions

View file

@ -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'}])); 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') { if (typeof args[0]!=='undefined') {
let sent = false;
for (const command of bot.command_handler.commands) { for (const command of bot.command_handler.commands) {
if (command.name===args[0]) { function m() {
let discordSupported; let discordSupported;
let alias = command.name; let alias = command.name;
if (typeof command.discordExecute==='undefined') { if (typeof command.discordExecute==='undefined') {
@ -71,12 +69,17 @@ module.exports = {
const Embed = new MessageEmbed() const Embed = new MessageEmbed()
.setColor('#FFFF00') .setColor('#FFFF00')
.setTitle(`${prefix + command.name} (${alias}) - ${command.description}`) .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]}); 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 { } else {
let supportedCommands = ''; let supportedCommands = '';

View file

@ -1,4 +1,5 @@
/* eslint-disable max-len */ /* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const translate = require('@vitalets/google-translate-api'); const translate = require('@vitalets/google-translate-api');
module.exports = { module.exports = {
name: 'translate', name: 'translate',
@ -14,4 +15,20 @@ module.exports = {
bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: String(e), color: 'red'})); 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]});
}
},
}; };

View file

@ -1,4 +1,5 @@
/* eslint-disable max-len */ /* eslint-disable max-len */
const {MessageEmbed} = require('discord.js');
const {secondsToHms} = require('../util/secondToHms'); const {secondsToHms} = require('../util/secondToHms');
module.exports = { module.exports = {
name: 'uptime', name: 'uptime',
@ -7,6 +8,13 @@ module.exports = {
usage: '', usage: '',
trusted: 0, trusted: 0,
execute: function(bot) { 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]});
}, },
}; };