aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-02 22:33:24 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-02 22:33:24 -0500
commit75eb731d077638472abc2f2423f6759a110bcda6 (patch)
treee01795a13b4038319e7de625860eb215b06444c7 /src/commands
parentd57515ee54cc2107f2c0ee79a953fa9dd9e21a7d (diff)
downloadtanzanite-75eb731d077638472abc2f2423f6759a110bcda6.tar.gz
tanzanite-75eb731d077638472abc2f2423f6759a110bcda6.tar.bz2
tanzanite-75eb731d077638472abc2f2423f6759a110bcda6.zip
refactor user info command
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/info/userInfo.ts144
1 files changed, 87 insertions, 57 deletions
diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts
index a129182..50cb1a8 100644
--- a/src/commands/info/userInfo.ts
+++ b/src/commands/info/userInfo.ts
@@ -9,7 +9,6 @@ import {
} from '#lib';
import { ActivityType, ApplicationCommandOptionType, Embed, PermissionFlagsBits, UserFlags } from 'discord.js';
-// TODO: Add bot information
export default class UserInfoCommand extends BushCommand {
public constructor() {
super('userInfo', {
@@ -56,10 +55,12 @@ export default class UserInfoCommand extends BushCommand {
const emojis = [];
const superUsers = util.getShared('superUsers');
- const userEmbed: Embed = new Embed()
+ const userEmbed = new Embed()
.setTitle(util.discord.escapeMarkdown(user.tag))
.setThumbnail(user.displayAvatarURL({ size: 2048, extension: 'png' }))
- .setTimestamp();
+ .setTimestamp()
+ .setFooter({ text: user.tag })
+ .setColor(member?.displayColor ?? util.colors.default);
// Flags
if (client.config.owners.includes(user.id)) emojis.push(client.consts.mappings.otherEmojis.Developer);
@@ -89,78 +90,105 @@ export default class UserInfoCommand extends BushCommand {
else if (member?.permissions.has(PermissionFlagsBits.Administrator)) emojis.push(client.consts.mappings.otherEmojis.Admin);
if (member?.premiumSinceTimestamp) emojis.push(client.consts.mappings.otherEmojis.Booster);
+ await this.generateGeneralInfoField(userEmbed, user);
+
+ this.generateServerInfoField(userEmbed, member);
+
+ this.generatePresenceField(userEmbed, member);
+
+ this.generateRolesField(userEmbed, member);
+
+ this.generatePermissionsField(userEmbed, member);
+
+ if (emojis) userEmbed.setDescription(`\u200B${emojis.filter((e) => e).join(' ')}`); // zero width space
+ return userEmbed;
+ }
+
+ private static async generateGeneralInfoField(embed: Embed, user: BushUser) {
const createdAt = util.timestamp(user.createdAt),
- createdAtDelta = util.dateDelta(user.createdAt),
- joinedAt = util.timestamp(member?.joinedAt),
- joinedAtDelta = member && member.joinedAt ? util.dateDelta(member.joinedAt, 2) : undefined,
- premiumSince = util.timestamp(member?.premiumSince),
- premiumSinceDelta = member && member.premiumSince ? util.dateDelta(member.premiumSince, 2) : undefined;
+ createdAtDelta = util.dateDelta(user.createdAt);
// General Info
const generalInfo = [`**Mention:** <@${user.id}>`, `**ID:** ${user.id}`, `**Created:** ${createdAt} (${createdAtDelta} ago)`];
if (user.accentColor !== null) generalInfo.push(`**Accent Color:** ${user.hexAccentColor}`);
if (user.banner) generalInfo.push(`**Banner:** [link](${user.bannerURL({ extension: 'png', size: 4096 })})`);
- const pronouns = await Promise.race([util.getPronounsOf(user), util.sleep(2)]);
+
+ const pronouns = await Promise.race([util.getPronounsOf(user), util.sleep(2)]); // cut off request after 2 seconds
+
if (pronouns && typeof pronouns === 'string') generalInfo.push(`**Pronouns:** ${pronouns}`);
- userEmbed.addField({ name: '» General Info', value: generalInfo.join('\n') });
+ embed.addField({ name: '» General Info', value: generalInfo.join('\n') });
+ }
+
+ private static generateServerInfoField(embed: Embed, member?: BushGuildMember | undefined) {
+ if (!member) return;
+
+ const joinedAt = util.timestamp(member?.joinedAt),
+ joinedAtDelta = member.joinedAt ? util.dateDelta(member.joinedAt, 2) : undefined,
+ premiumSince = util.timestamp(member?.premiumSince),
+ premiumSinceDelta = member.premiumSince ? util.dateDelta(member.premiumSince, 2) : undefined;
// Server User Info
const serverUserInfo = [];
if (joinedAt)
- serverUserInfo.push(`**${guild!.ownerId == user.id ? 'Created Server' : 'Joined'}:** ${joinedAt} (${joinedAtDelta} ago)`);
+ serverUserInfo.push(
+ `**${member.guild!.ownerId == member.user.id ? 'Created Server' : 'Joined'}:** ${joinedAt} (${joinedAtDelta} ago)`
+ );
if (premiumSince) serverUserInfo.push(`**Boosting Since:** ${premiumSince} (${premiumSinceDelta} ago)`);
if (member?.displayHexColor) serverUserInfo.push(`**Display Color:** ${member.displayHexColor}`);
- if (user.id == '322862723090219008' && guild?.id == client.consts.mappings.guilds.bush)
+ if (member.user.id == '322862723090219008' && member.guild?.id == client.consts.mappings.guilds.bush)
serverUserInfo.push(`**General Deletions:** 1⅓`);
if (
- (['384620942577369088', '496409778822709251'] as const).includes(user.id) &&
- guild?.id == client.consts.mappings.guilds.bush
+ (['384620942577369088', '496409778822709251'] as const).includes(member.user.id) &&
+ member.guild?.id == client.consts.mappings.guilds.bush
)
serverUserInfo.push(`**General Deletions:** ⅓`);
if (member?.nickname) serverUserInfo.push(`**Nickname:** ${util.discord.escapeMarkdown(member?.nickname)}`);
- if (serverUserInfo.length)
- userEmbed
- .addField({ name: '» Server Info', value: serverUserInfo.join('\n') })
- .setColor(member?.displayColor ?? util.colors.default);
+ if (serverUserInfo.length) embed.addField({ name: '» Server Info', value: serverUserInfo.join('\n') });
+ }
+
+ private static generatePresenceField(embed: Embed, member?: BushGuildMember | undefined) {
+ if (!member || !member.presence) return;
+ if (!member.presence.status && !member.presence.clientStatus && !member.presence.activities) return;
// User Presence Info
- if (member?.presence?.status || member?.presence?.clientStatus || member?.presence?.activities) {
- let customStatus = '';
- const activitiesNames: string[] = [];
- if (member.presence.activities) {
- member.presence.activities.forEach((a) => {
- if (a.type == ActivityType.Custom && a.state) {
- const emoji = `${a.emoji ? `${a.emoji.toString()} ` : ''}`;
- customStatus = `${emoji}${a.state}`;
- }
- activitiesNames.push(`\`${a.name}\``);
- });
- }
- let devices;
- if (member?.presence.clientStatus) devices = Object.keys(member.presence.clientStatus);
- const presenceInfo = [];
- if (member?.presence.status) presenceInfo.push(`**Status:** ${member.presence.status}`);
- if (devices && devices.length)
- presenceInfo.push(`**${devices.length - 1 ? 'Devices' : 'Device'}:** ${util.oxford(devices, 'and', '')}`);
- if (activitiesNames.length)
- presenceInfo.push(`**Activit${activitiesNames.length - 1 ? 'ies' : 'y'}:** ${util.oxford(activitiesNames, 'and', '')}`);
- if (customStatus && customStatus.length)
- presenceInfo.push(`**Custom Status:** ${util.discord.escapeMarkdown(customStatus)}`);
- userEmbed.addField({ name: '» Presence', value: presenceInfo.join('\n') });
-
- enum statusEmojis {
- online = '787550449435803658',
- idle = '787550520956551218',
- dnd = '787550487633330176',
- offline = '787550565382750239',
- invisible = '787550565382750239'
- }
- userEmbed.setFooter({
- text: user.tag,
- iconURL: client.emojis.cache.get(statusEmojis[member?.presence.status])?.url ?? undefined
+ let customStatus = '';
+ const activitiesNames: string[] = [];
+ if (member.presence.activities) {
+ member.presence.activities.forEach((a) => {
+ if (a.type == ActivityType.Custom && a.state) {
+ const emoji = `${a.emoji ? `${a.emoji.toString()} ` : ''}`;
+ customStatus = `${emoji}${a.state}`;
+ }
+ activitiesNames.push(`\`${a.name}\``);
});
}
+ let devices;
+ if (member?.presence.clientStatus) devices = Object.keys(member.presence.clientStatus);
+ const presenceInfo = [];
+ if (member?.presence.status) presenceInfo.push(`**Status:** ${member.presence.status}`);
+ if (devices && devices.length)
+ presenceInfo.push(`**${devices.length - 1 ? 'Devices' : 'Device'}:** ${util.oxford(devices, 'and', '')}`);
+ if (activitiesNames.length)
+ presenceInfo.push(`**Activit${activitiesNames.length - 1 ? 'ies' : 'y'}:** ${util.oxford(activitiesNames, 'and', '')}`);
+ if (customStatus && customStatus.length) presenceInfo.push(`**Custom Status:** ${util.discord.escapeMarkdown(customStatus)}`);
+ embed.addField({ name: '» Presence', value: presenceInfo.join('\n') });
+
+ enum statusEmojis {
+ online = '787550449435803658',
+ idle = '787550520956551218',
+ dnd = '787550487633330176',
+ offline = '787550565382750239',
+ invisible = '787550565382750239'
+ }
+ embed.setFooter({
+ text: member.user.tag,
+ iconURL: client.emojis.cache.get(statusEmojis[member?.presence.status])?.url ?? undefined
+ });
+ }
+
+ private static generateRolesField(embed: Embed, member?: BushGuildMember | undefined) {
+ if (!member || !(member.roles.cache.size < 1)) return;
// roles
if (member?.roles.cache.size && member?.roles.cache.size - 1) {
@@ -168,12 +196,16 @@ export default class UserInfoCommand extends BushCommand {
.filter((role) => role.name !== '@everyone')
.sort((role1, role2) => role2.position - role1.position)
.map((role) => `${role}`);
- userEmbed.addField({ name: `» Role${roles.length - 1 ? 's' : ''} [${roles.length}]`, value: roles.join(', ') });
+ embed.addField({ name: `» Role${roles.length - 1 ? 's' : ''} [${roles.length}]`, value: roles.join(', ') });
}
+ }
+
+ private static generatePermissionsField(embed: Embed, member: BushGuildMember | undefined) {
+ if (!member) return;
// Important Perms
const perms = [];
- if (member?.permissions.has(PermissionFlagsBits.Administrator) || guild?.ownerId == user.id) {
+ if (member?.permissions.has(PermissionFlagsBits.Administrator) || member.guild?.ownerId == member.user.id) {
perms.push('`Administrator`');
} else if (member?.permissions.toArray().length) {
member.permissions.toArray().forEach((permission) => {
@@ -183,8 +215,6 @@ export default class UserInfoCommand extends BushCommand {
});
}
- if (perms.length) userEmbed.addField({ name: '» Important Perms', value: perms.join(' ') });
- if (emojis) userEmbed.setDescription(`\u200B${emojis.filter((e) => e).join(' ')}`); // zero width space
- return userEmbed;
+ if (perms.length) embed.addField({ name: '» Important Perms', value: perms.join(' ') });
}
}