galactic-bot/structure/client/components/commands/information/Guild.js
2021-06-23 11:51:34 +03:00

118 lines
3.9 KiB
JavaScript

const { Command } = require('../../../../interfaces');
class GuildCommand extends Command {
constructor(client) {
super(client, {
name: 'guild',
module: 'information',
clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS'],
aliases: [
'server'
]
});
this.client = client;
}
async execute(message, { params }) {
let guild = null;
//if(params[0]) guild = await this.client.fetchGuildPreview(params[0]);
guild = await message.guild.fetch();
let vc = 0,
tc = 0,
cat = 0,
news = 0,
store = 0,
totalChannels = 0;
const createdAt = `${guild.createdAt.toDateString()} (${this.client.resolver.timeAgo(Math.floor(Date.now() / 1000) - Math.floor(guild.createdTimestamp / 1000))} ago)`,
description = guild.description || guild._settings.description || message.format('C_GUILD_NODESC'),
maxMembers = guild.maximumMembers,
maxPresences = guild.maximumPresences,
approxPresences = guild.approximatePresenceCount,
{ memberCount } = guild;
for (const channel of guild.channels.cache.values()) {
if (channel.type === 'voice') vc++;
if (channel.type === 'text') tc++;
if (channel.type === 'category') cat++;
if (channel.type === 'news') news++;
if (channel.type === 'store') store++;
totalChannels++;
}
const embed = {
description: message.format('C_GUILD_TEMPLATE', {
name: guild.name,
description,
owner: guild.ownerID,
id: guild.id,
shard: guild.shardID,
createdAt,
region: guild.region,
boosters: guild.premiumSubscriptionCount,
tier: guild.premiumTier
}),
fields: [
{
name: message.format('C_GUILD_MEMBERS_NAME'),
value: message.format('C_GUILD_MEMBERS', {
memberCount,
maxMembers,
maxPresences,
approxPresences
}),
inline: true
},
{
name: message.format('C_GUILD_CHANNELS_NAME'),
value: message.format('C_GUILD_CHANNELS', {
vc,
tc,
cat,
news: news > 0 ? message.format('C_GUILD_NEWS', { news }) : '',
store: store > 0 ? message.format('C_GUILD_STORE', { store }) : '',
totalChannels
}),
inline: true
},
{
name: message.format('C_GUILD_OTHER_NAME'),
value: message.format('C_GUILD_OTHER', {
roleCount: guild.roles.cache.size,
emojiCount: guild.emojis.cache.filter((e) => !e.animated).size,
gifEmojiCount: guild.emojis.cache.filter((e) => e.animated).size,
emojiTotal: 50 + 50 * guild.premiumTier
}),
inline: true
}
],
thumbnail: {
url: guild.iconURL()
},
footer: {
text: `• Server ID: ${guild.id} • Shard ID: ${guild.shardID}`
}
};
if (guild.features.length) embed.fields.push({
name: message.format('C_GUILD_FEATURES_NAME'),
value: message.format('C_GUILD_FEATURES', {
features: guild.features.join(', ')
}),
inline: true
});
return message.embed(embed);
}
}
module.exports = GuildCommand;