1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
import { Command, CommandoMessage } from 'discord.js-commando';
import { MessageEmbed } from 'discord.js';
import axios from 'axios'
import emoji from 'emoji-random'
module.exports = class MinecraftServerMinecraft extends Command {
constructor(client) {
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 }) {
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())
})
).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)
}
};
|