JaBa/commands/General/minecraft.js

96 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"),
fetch = require("node-fetch"),
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 });
const imgRes = await fetch(`https://www.minecraftskinstealer.com/achievement/a.php?i=2&h=Success&t=${ip}`);
const imgAttachment = new Discord.MessageAttachment(await imgRes.buffer(), "success.png");
const mcEmbed = new Discord.MessageEmbed()
.setAuthor({
name: message.translate("general/minecraft:FIELD_NAME", {
ip: json.name
})
})
2022-01-04 02:18:28 +05:00
.addField(message.translate("general/minecraft:FIELD_VERSION"), json.raw.vanilla.raw.version.name)
.addField(message.translate("general/minecraft:FIELD_CONNECTED"), message.translate("general/minecraft:PLAYERS", {
count: (json.raw.players ? json.raw.players.online : json.players.length)
}))
.addField(message.translate("general/minecraft:FIELD_MAX"), message.translate("general/minecraft:PLAYERS", {
count: (json.raw.players ? json.raw.players.max : json.maxplayers)
}))
.addField(message.translate("general/minecraft:FIELD_STATUS"), message.translate("general/minecraft:ONLINE"))
.addField(message.translate("general/minecraft:FIELD_IP"), json.connect)
.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,
embeds: [mcEmbed],
files: [imgAttachment]
});
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;