JaBa/commands/General/minecraft.js

89 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js"),
Discord = require("discord.js"),
fetch = require("node-fetch"),
gamedig = require("gamedig"),
Sentry = require("@sentry/node");
class Minecraft extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "minecraft",
dirname: __dirname,
enabled: true,
guildOnly: false,
2021-12-26 19:29:37 +05:00
aliases: ["mc"],
2021-12-10 21:39:54 +05:00
memberPermissions: [],
2021-12-26 19:29:37 +05:00
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 1000
2021-12-10 21:39:54 +05:00
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2021-12-10 21:39:54 +05:00
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) {
2021-12-26 19:29:37 +05:00
const ip = ip.split(":");
2021-12-10 21:39:54 +05:00
options = {
type: "minecraft",
host: ip[0],
port: ip[1]
};
};
2021-12-26 19:29:37 +05:00
const m = await message.sendT("misc:PLEASE_WAIT", null, {
prefixEmoji: "loading"
});
2021-12-10 21:39:54 +05:00
let json = null;
await gamedig.query(options).then((res) => {
json = res;
}).catch((err) => {
Sentry.captureException(err);
});
if (!json) {
options.type = "minecraftpe";
await gamedig.query(options).then((res) => {
json = res;
}).catch((err) => {
Sentry.captureException(err);
});
};
if (!json) return m.error("general/minecraft:FAILED", null, { edit: true });
2021-12-24 20:52:27 +05:00
const imgRes = await fetch(`https://www.minecraftskinstealer.com/achievement/a.php?i=2&h=Success&t=${ip}`);
2021-12-10 21:39:54 +05:00
const imgAttachment = new Discord.MessageAttachment(await imgRes.buffer(), "success.png");
const mcEmbed = new Discord.MessageEmbed()
2021-12-26 19:29:37 +05:00
.setAuthor(message.translate("general/minecraft:FIELD_NAME", {
ip: json.name
}))
2021-12-10 21:39:54 +05:00
.addField(message.translate("general/minecraft:FIELD_VERSION"), json.raw.vanilla.raw.version.name)
2021-12-26 19:29:37 +05:00
.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)
}))
2021-12-10 21:39:54 +05:00
.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(data.config.embed.footer);
2021-12-26 19:29:37 +05:00
m.edit(null, [mcEmbed, imgAttachment]);
2021-12-10 21:39:54 +05:00
}
};
module.exports = Minecraft;