2022-08-04 19:26:17 +05:00
|
|
|
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand"),
|
|
|
|
gamedig = require("gamedig");
|
|
|
|
|
|
|
|
class Minecraft extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("minecraft")
|
|
|
|
.setDescription(client.translate("general/minecraft:DESCRIPTION"))
|
2023-03-26 18:31:19 +05:00
|
|
|
.setDescriptionLocalizations({ "uk": client.translate("general/minecraft:DESCRIPTION", null, "uk-UA") })
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(true)
|
2022-08-04 19:26:17 +05:00
|
|
|
.addStringOption(option => option.setName("ip")
|
|
|
|
.setDescription(client.translate("common:IP"))
|
2023-03-26 18:31:19 +05:00
|
|
|
.setDescriptionLocalizations({ "uk": client.translate("common:IP", null, "uk-UA") })
|
2022-08-04 19:26:17 +05:00
|
|
|
.setRequired(true)),
|
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-04 19:26:17 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
async onLoad() {
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
2022-08-09 23:48:33 +05:00
|
|
|
* @param {Object} data
|
2022-08-04 19:26:17 +05:00
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
|
|
|
await interaction.deferReply();
|
|
|
|
|
2022-11-18 16:04:04 +05:00
|
|
|
const ip = interaction.options.getString("ip");
|
2022-08-04 19:26:17 +05:00
|
|
|
const options = {
|
|
|
|
type: "minecraft",
|
2022-12-15 21:02:38 +05:00
|
|
|
host: ip,
|
2022-08-04 19:26:17 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
if (ip.split(":").length > 1) {
|
|
|
|
const splitIp = ip.split(":");
|
|
|
|
options.host = splitIp[0];
|
|
|
|
options.port = splitIp[1];
|
|
|
|
}
|
|
|
|
|
2022-12-15 21:02:38 +05:00
|
|
|
let res = await gamedig.query(options).catch(() => {});
|
2022-08-04 19:26:17 +05:00
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
options.type = "minecraftpe";
|
|
|
|
res = await gamedig.query(options).catch(() => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!res) return interaction.error("general/minecraft:FAILED", null, { edit: true });
|
|
|
|
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setAuthor({
|
2022-12-15 21:02:38 +05:00
|
|
|
name: res.name,
|
2022-08-04 19:26:17 +05:00
|
|
|
})
|
|
|
|
.addFields([
|
|
|
|
{
|
|
|
|
name: interaction.translate("general/minecraft:FIELD_STATUS"),
|
2022-12-15 21:02:38 +05:00
|
|
|
value: interaction.translate("general/minecraft:ONLINE"),
|
2022-08-04 19:26:17 +05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("general/minecraft:FIELD_CONNECTED"),
|
2023-04-20 11:47:47 +05:00
|
|
|
value: `**${(res.raw.players ? res.raw.players.online : res.players.length)}** ${client.functions.getNoun((res.raw.players ? res.raw.players.online : res.players.length), interaction.translate("misc:NOUNS:PLAYERS:1"), interaction.translate("misc:NOUNS:PLAYERS:2"), interaction.translate("misc:NOUNS:PLAYERS:5"))} / **${(res.raw.players ? res.raw.players.max : res.maxplayers)}** ${client.functions.getNoun((res.raw.players ? res.raw.players.max : res.maxplayers), interaction.translate("misc:NOUNS:PLAYERS:1"), interaction.translate("misc:NOUNS:PLAYERS:2"), interaction.translate("misc:NOUNS:PLAYERS:5"))}`,
|
2022-08-04 19:26:17 +05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("general/minecraft:FIELD_IP"),
|
|
|
|
value: res.connect,
|
2022-12-15 21:02:38 +05:00
|
|
|
inline: true,
|
2022-08-04 19:26:17 +05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("general/minecraft:FIELD_VERSION"),
|
|
|
|
value: res.raw.vanilla.raw.version.name,
|
2022-12-15 21:02:38 +05:00
|
|
|
inline: true,
|
2022-08-04 19:26:17 +05:00
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: interaction.translate("general/minecraft:FIELD_PING"),
|
2022-12-15 21:02:38 +05:00
|
|
|
value: res.raw.vanilla.ping.toString(),
|
|
|
|
},
|
2022-08-04 19:26:17 +05:00
|
|
|
])
|
|
|
|
.setColor(client.config.embed.color)
|
|
|
|
.setThumbnail(`https://eu.mc-api.net/v3/server/favicon/${ip}`)
|
|
|
|
.setFooter({
|
2022-12-15 21:02:38 +05:00
|
|
|
text: client.config.embed.footer,
|
2022-08-04 19:26:17 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
interaction.editReply({
|
2022-12-15 21:02:38 +05:00
|
|
|
embeds: [embed],
|
2022-08-04 19:26:17 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Minecraft;
|