JaBa/commands/General/minecraft.js

85 lines
2.6 KiB
JavaScript
Raw Normal View History

const Command = require("../../base/Command"),
2022-01-04 02:18:28 +05:00
Discord = require("discord.js"),
gamedig = require("gamedig");
2022-01-04 02:18:28 +05:00
class Minecraft extends Command {
constructor(client) {
super(client, {
name: "minecraft",
dirname: __dirname,
enabled: true,
guildOnly: false,
aliases: ["mc"],
memberPermissions: [],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
nsfw: false,
ownerOnly: false,
cooldown: 1000
});
}
async run(message, args, data) {
const ip = args[0];
if (!ip) return message.error("general/minecraft:MISSING_IP");
const favicon = `https://eu.mc-api.net/v3/server/favicon/${ip}`;
let options = {
type: "minecraft",
host: ip
};
if (ip.split(":").length > 1) {
2022-04-08 01:39:29 +05:00
const ipp = ip.split(":");
2022-01-04 02:18:28 +05:00
options = {
type: "minecraft",
2022-04-08 01:39:29 +05:00
host: ipp[0],
port: ipp[1]
2022-01-04 02:18:28 +05:00
};
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
const m = await message.sendT("misc:PLEASE_WAIT", null, {
prefixEmoji: "loading"
});
let json = null;
await gamedig.query(options).then((res) => {
json = res;
}).catch((err) => {
console.error(err);
2022-01-04 02:18:28 +05:00
});
if (!json) {
options.type = "minecraftpe";
await gamedig.query(options).then((res) => {
json = res;
}).catch((err) => {
console.error(err);
2022-01-04 02:18:28 +05:00
});
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
if (!json) return m.error("general/minecraft:FAILED", null, { edit: true });
2022-04-08 18:41:40 +05:00
const embed = new Discord.MessageEmbed()
.setAuthor({
name: json.name
})
2022-01-04 02:18:28 +05:00
.addField(message.translate("general/minecraft:FIELD_STATUS"), message.translate("general/minecraft:ONLINE"))
.addField(message.translate("general/minecraft:FIELD_CONNECTED"), `**${(json.raw.players ? json.raw.players.online : json.players.length)}** ${message.getNoun((json.raw.players ? json.raw.players.online : json.players.length), message.translate("misc:NOUNS:PLAYERS:1"), message.translate("misc:NOUNS:PLAYERS:2"), message.translate("misc:NOUNS:PLAYERS:5"))} / **${(json.raw.players ? json.raw.players.max : json.maxplayers)}** ${message.getNoun((json.raw.players ? json.raw.players.max : json.maxplayers), message.translate("misc:NOUNS:PLAYERS:1"), message.translate("misc:NOUNS:PLAYERS:2"), message.translate("misc:NOUNS:PLAYERS:5"))}`)
.addField(message.translate("general/minecraft:FIELD_IP"), json.connect, true)
.addField(message.translate("general/minecraft:FIELD_VERSION"), json.raw.vanilla.raw.version.name, true)
.addField(message.translate("general/minecraft:FIELD_PING"), json.raw.vanilla.ping.toString())
2022-01-04 02:18:28 +05:00
.setColor(data.config.embed.color)
.setThumbnail(favicon)
.setFooter({
text: data.config.embed.footer
});
2022-01-04 02:18:28 +05:00
m.edit({
content: null,
2022-04-08 18:41:40 +05:00
embeds: [embed]
});
2022-01-04 02:18:28 +05:00
}
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
module.exports = Minecraft;