import { Command, CommandoMessage, CommandoClient } from 'discord.js-commando'; import { MessageEmbed } from 'discord.js'; import axios from 'axios' //@ts-ignore no types import emoji from 'emoji-random' module.exports = class MinecraftServerMinecraft extends Command { constructor(client: CommandoClient) { super(client, { name: 'minecraftserverstatus', aliases: [ 'mcserverstatus', 'minecraft-server-status', 'mcss' ], group: 'utility', memberName: 'minecraftserverstatus', description: 'Grabs you the server status of a Minecraft server.', examples: [ 'uwu!minecraftserverstatus', 'uwu!mcss' ], userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'], clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'], throttling: { usages: 5, duration: 30 }, args: [ { key: 'ip', prompt: 'What is the IP of the server?', type: 'string' }, { key: 'port', prompt: 'What is the port of the server?', type: 'integer', default: '25565', max: 65535, min: 1 } ] }); } async run(msg: CommandoMessage, { ip, port }: any) { const res = ( await axios(`https://mcapi.us/server/status?ip=${ip}&port=${port}`).catch(err => { console.error(err) return msg.reply('Woops, an error has occured. ' + emoji.random()) }) //@ts-ignore yes this exists... ).data if (res.status !== 'success') { return msg.reply('Woops, there was an error with your request. ' + emoji.random()) } let emb = new MessageEmbed() .setTitle(ip) .setTimestamp(res.last_updated) .setColor(0xFFCC4D) if (res.online) { emb.addField('Server Status', 'Currentaly online.', true) emb.addField('Version', res.server.name, true) emb.addField('Members', `${res.players.now}/${res.players.max}`, true) emb.addField('MOTD', `\`\`\`${res.motd}\`\`\``, true) } else if (res.last_online) { emb.addField('Server Status', `Offline. Last seen ${new Date(res.last_online)}`, true) } else { emb.addField('Server Status', 'Offline. Never seen online before.', true) } return msg.reply(emb) } };