JaBa/commands/General/info.js

237 lines
7.8 KiB
JavaScript
Raw Normal View History

2024-09-19 23:58:06 +05:00
const { SlashCommandBuilder, ChannelType, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
2024-08-18 13:12:49 +05:00
const BaseCommand = require("../../base/BaseCommand");
class Info extends BaseCommand {
/**
*
* @param {import("../base/Client")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("info")
.setDescription(client.translate("general/info:DESCRIPTION"))
.setDescriptionLocalizations({
uk: client.translate("general/info:DESCRIPTION", null, "uk-UA"),
ru: client.translate("general/info:DESCRIPTION", null, "ru-RU"),
})
2024-09-19 23:58:06 +05:00
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall])
2024-09-14 19:52:56 +05:00
.setContexts([InteractionContextType.Guild])
2024-08-18 13:12:49 +05:00
.addSubcommand(subcommand =>
subcommand
.setName("user")
.setDescription(client.translate("general/info:USER"))
.setDescriptionLocalizations({
uk: client.translate("general/info:USER", null, "uk-UA"),
ru: client.translate("general/info:USER", null, "ru-RU"),
})
.addUserOption(option =>
option
.setName("user")
.setDescription(client.translate("common:USER"))
.setDescriptionLocalizations({
uk: client.translate("common:USER", null, "uk-UA"),
ru: client.translate("common:USER", null, "ru-RU"),
}),
),
)
.addSubcommand(subcommand =>
subcommand
.setName("server")
.setDescription(client.translate("general/info:SERVER"))
.setDescriptionLocalizations({
uk: client.translate("general/info:SERVER", null, "uk-UA"),
ru: client.translate("general/info:SERVER", null, "ru-RU"),
}),
),
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
* @param {import("../../base/Client")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
async execute(client, interaction) {
await interaction.deferReply();
const command = interaction.options.getSubcommand();
if (command === "user") {
const member = interaction.options.getMember("user") || interaction.member;
2024-08-21 12:03:33 +05:00
const embed = getUserInfo(client, interaction, member);
2024-08-18 13:12:49 +05:00
return interaction.editReply({
embeds: [embed],
});
} else {
2024-08-21 12:03:33 +05:00
const embed = await getServerInfo(client, interaction);
2024-08-18 13:12:49 +05:00
return interaction.editReply({
embeds: [embed],
});
}
}
}
/**
*
2024-08-21 12:03:33 +05:00
* @param {import("../../base/Client")} client
2024-08-18 13:12:49 +05:00
* @param {import("discord.js").ChatInputCommandInteraction} interaction
* @returns {Promise<import("discord.js").Embed>} Embed containing information about the guild
*/
2024-08-21 12:03:33 +05:00
async function getServerInfo(client, interaction) {
2024-08-18 13:12:49 +05:00
const { guild } = interaction;
await guild.members.fetch();
const owner = await guild.fetchOwner();
2024-08-21 12:03:33 +05:00
const embed = client.embed({
2024-08-18 13:12:49 +05:00
author: guild.name,
thumbnail: guild.iconURL(),
fields: [
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.title + interaction.translate("common:NAME"),
2024-08-18 13:12:49 +05:00
value: guild.name,
inline: true,
},
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.calendar + interaction.translate("common:CREATION"),
2024-08-21 11:59:02 +05:00
value: `<t:${Math.floor(guild.createdTimestamp / 1000)}:D>`,
2024-08-18 13:12:49 +05:00
inline: true,
},
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.users + interaction.translate("common:MEMBERS"),
2024-08-18 13:12:49 +05:00
value:
2024-08-21 12:03:33 +05:00
`${guild.members.cache.filter(m => !m.user.bot).size} ${client.functions.getNoun(
2024-08-18 13:12:49 +05:00
guild.members.cache.filter(m => !m.user.bot).size,
interaction.translate("misc:NOUNS:MEMBERS:1"),
interaction.translate("misc:NOUNS:MEMBERS:2"),
interaction.translate("misc:NOUNS:MEMBERS:5"),
)}` +
"\n" +
2024-08-21 12:03:33 +05:00
`${guild.members.cache.filter(m => m.user.bot).size} ${client.functions.getNoun(
2024-08-18 13:12:49 +05:00
guild.members.cache.filter(m => m.user.bot).size,
interaction.translate("misc:NOUNS:BOTS:1"),
interaction.translate("misc:NOUNS:BOTS:2"),
interaction.translate("misc:NOUNS:BOTS:5"),
)}`,
inline: true,
},
{
2024-08-21 19:44:04 +05:00
name: client.customEmojis.afk + interaction.translate("general/info:AFK_CHANNEL"),
2024-08-18 13:12:49 +05:00
value: guild.afkChannel?.toString() || interaction.translate("common:MISSING"),
inline: true,
},
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.id + interaction.translate("common:SERVER_ID"),
2024-08-18 13:12:49 +05:00
value: guild.id,
inline: true,
},
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.crown + interaction.translate("common:OWNER"),
2024-08-18 13:12:49 +05:00
value: owner.toString(),
inline: true,
},
{
2024-08-21 19:44:04 +05:00
name: client.customEmojis.boost + interaction.translate("general/info:BOOSTS"),
2024-08-18 13:12:49 +05:00
value: guild.premiumSubscriptionCount?.toString() || "0",
inline: true,
},
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.channels + interaction.translate("common:CHANNELS"),
2024-08-18 13:12:49 +05:00
value:
2024-08-21 12:03:33 +05:00
`${guild.channels.cache.filter(c => c.type === ChannelType.GuildText).size} ${client.functions.getNoun(
2024-08-18 13:12:49 +05:00
guild.channels.cache.filter(c => c.type === ChannelType.GuildText).size,
interaction.translate("misc:NOUNS:TEXT:1"),
interaction.translate("misc:NOUNS:TEXT:2"),
interaction.translate("misc:NOUNS:TEXT:5"),
)}` +
"\n" +
2024-08-21 12:03:33 +05:00
`${guild.channels.cache.filter(c => c.type === ChannelType.GuildVoice).size} ${client.functions.getNoun(
2024-08-18 13:12:49 +05:00
guild.channels.cache.filter(c => c.type === ChannelType.GuildVoice).size,
interaction.translate("misc:NOUNS:VOICE:1"),
interaction.translate("misc:NOUNS:VOICE:2"),
interaction.translate("misc:NOUNS:VOICE:5"),
)}` +
"\n" +
2024-08-21 12:03:33 +05:00
`${guild.channels.cache.filter(c => c.type === ChannelType.GuildCategory).size} ${client.functions.getNoun(
2024-08-18 13:12:49 +05:00
guild.channels.cache.filter(c => c.type === ChannelType.GuildCategory).size,
interaction.translate("misc:NOUNS:CATEGORY:1"),
interaction.translate("misc:NOUNS:CATEGORY:2"),
interaction.translate("misc:NOUNS:CATEGORY:5"),
)}`,
inline: true,
},
],
});
return embed;
}
/**
*
2024-08-21 12:03:33 +05:00
* @param {import("../../base/Client")} client
2024-08-18 13:12:49 +05:00
* @param {import("discord.js").ChatInputCommandInteraction} interaction
* @param {import("discord.js").Member} member
* @returns {import("discord.js").Embed} Embed containing information about the user
*/
2024-08-21 12:03:33 +05:00
function getUserInfo(client, interaction, member) {
const embed = client.embed({
2024-08-18 13:12:49 +05:00
author: {
name: `${member.user.getUsername()} (${member.id})`,
iconURL: member.displayAvatarURL(),
},
thumbnail: member.displayAvatarURL(),
fields: [
{
name: ":man: " + interaction.translate("common:USERNAME"),
value: member.user.getUsername(),
inline: true,
},
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.pencil + " " + interaction.translate("common:NICKNAME"),
2024-08-21 19:44:04 +05:00
value: member.nickname || interaction.translate("general/info:NO_NICKNAME"),
2024-08-18 13:12:49 +05:00
inline: true,
},
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.bot + " " + interaction.translate("common:ROBOT"),
2024-08-18 13:12:49 +05:00
value: member.user.bot ? interaction.translate("common:YES") : interaction.translate("common:NO"),
inline: true,
},
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.calendar + " " + interaction.translate("common:CREATION"),
2024-08-18 13:12:49 +05:00
value: `<t:${Math.floor(member.user.createdTimestamp / 1000)}:D>`,
inline: true,
},
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.calendar2 + " " + interaction.translate("common:JOINED"),
2024-08-18 13:12:49 +05:00
value: `<t:${Math.floor(member.joinedTimestamp / 1000)}:D>`,
inline: true,
},
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.color + " " + interaction.translate("common:COLOR"),
2024-08-18 13:12:49 +05:00
value: member.displayHexColor,
inline: true,
},
{
2024-08-21 12:03:33 +05:00
name: client.customEmojis.roles + " " + interaction.translate("common:ROLES"),
2024-08-18 13:12:49 +05:00
value:
member.roles.size > 10
? member.roles.cache.map(r => r).filter(r => r.id !== interaction.guild.roles.everyone.id).slice(0, 10).join(", ") + " " +
2024-08-21 19:44:04 +05:00
interaction.translate("general/info:MORE_ROLES", {
2024-08-18 13:12:49 +05:00
count: member.roles.cache.size - 10,
})
2024-08-21 19:44:04 +05:00
: member.roles.cache.size < 1 ? interaction.translate("general/info:NO_ROLE") : member.roles.cache.map(r => r).filter(r => r.id !== interaction.guild.roles.everyone.id).slice(0, 10).join(", "),
2024-08-18 13:12:49 +05:00
inline: true,
},
],
});
return embed;
}
module.exports = Info;