2024-02-06 21:45:53 +05:00
|
|
|
const { SlashCommandBuilder } = require("discord.js");
|
2022-08-04 19:26:17 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand"),
|
|
|
|
gamedig = require("gamedig");
|
|
|
|
|
|
|
|
class Minecraft extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../base/Client")} client
|
2022-08-04 19:26:17 +05:00
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("minecraft")
|
|
|
|
.setDescription(client.translate("general/minecraft:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("general/minecraft:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("general/minecraft:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(true)
|
2023-07-05 00:58:06 +05:00
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName("ip")
|
|
|
|
.setDescription(client.translate("common:IP"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("common:IP", null, "uk-UA"),
|
|
|
|
ru: client.translate("common:IP", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setRequired(true),
|
|
|
|
),
|
2022-08-04 19:26:17 +05:00
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-04 19:26:17 +05:00
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2022-08-04 19:26:17 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-08-04 19:26:17 +05:00
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
|
|
*/
|
|
|
|
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 });
|
|
|
|
|
2024-02-06 21:45:53 +05:00
|
|
|
const embed = client.embed({
|
|
|
|
author: { name: res.name || "Unknown" },
|
|
|
|
thumbnail: `https://eu.mc-api.net/v3/server/favicon/${ip}`,
|
|
|
|
fields: [
|
2022-08-04 19:26:17 +05:00
|
|
|
{
|
|
|
|
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-07-05 00:58:06 +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(),
|
|
|
|
},
|
2024-02-06 21:45:53 +05:00
|
|
|
],
|
|
|
|
});
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Minecraft;
|