JaBa/commands/General/minecraft.js

120 lines
3.8 KiB
JavaScript
Raw Permalink Normal View History

2024-09-19 23:58:06 +05:00
const { SlashCommandBuilder, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
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
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("minecraft")
.setDescription(client.translate("general/minecraft:DESCRIPTION"))
.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"),
})
2024-09-19 23:58:06 +05:00
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall])
2024-09-14 19:52:56 +05:00
.setContexts([InteractionContextType.BotDM, InteractionContextType.PrivateChannel, InteractionContextType.Guild])
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),
2024-09-19 23:58:06 +05:00
)
.addBooleanOption(option =>
option
.setName("ephemeral")
.setDescription(client.translate("misc:EPHEMERAL_RESPONSE"))
.setDescriptionLocalizations({
uk: client.translate("misc:EPHEMERAL_RESPONSE", null, "uk-UA"),
ru: client.translate("misc:EPHEMERAL_RESPONSE", null, "ru-RU"),
}),
2023-07-05 00:58:06 +05:00
),
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
async execute(client, interaction) {
2024-09-19 23:58:06 +05:00
await interaction.deferReply({ ephemeral: interaction.options.getBoolean("ephemeral") || false });
const ip = interaction.options.getString("ip");
const options = {
type: "minecraft",
host: ip,
};
if (ip.split(":").length > 1) {
const splitIp = ip.split(":");
options.host = splitIp[0];
options.port = splitIp[1];
}
let res = await gamedig.query(options).catch(() => {});
if (!res) {
2024-11-17 13:58:35 +05:00
options.type = "mbe";
res = await gamedig.query(options).catch(() => {});
}
if (!res) return interaction.error("general/minecraft:FAILED", null, { edit: true });
const embed = client.embed({
author: { name: res.name || "Unknown" },
thumbnail: `https://eu.mc-api.net/v3/server/favicon/${ip}`,
fields: [
{
name: interaction.translate("general/minecraft:FIELD_STATUS"),
value: interaction.translate("general/minecraft:ONLINE"),
},
{
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"),
)}`,
},
{
name: interaction.translate("general/minecraft:FIELD_IP"),
value: res.connect,
inline: true,
},
{
name: interaction.translate("general/minecraft:FIELD_VERSION"),
value: res.raw.vanilla.raw.version.name,
inline: true,
},
{
name: interaction.translate("general/minecraft:FIELD_PING"),
value: res.raw.vanilla.ping.toString(),
},
],
});
interaction.editReply({
embeds: [embed],
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Minecraft;