diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-03 21:12:19 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-02-03 21:12:19 -0500 |
commit | 821ed93ccf55e4f32f6f25f502bce1e5b161d356 (patch) | |
tree | 42d0547f589134a6e549975f2da199f943e7b3b9 /src/commands/info | |
parent | 75eb731d077638472abc2f2423f6759a110bcda6 (diff) | |
download | tanzanite-821ed93ccf55e4f32f6f25f502bce1e5b161d356.tar.gz tanzanite-821ed93ccf55e4f32f6f25f502bce1e5b161d356.tar.bz2 tanzanite-821ed93ccf55e4f32f6f25f502bce1e5b161d356.zip |
add bot info to user info command
Diffstat (limited to 'src/commands/info')
-rw-r--r-- | src/commands/info/guildInfo.ts | 4 | ||||
-rw-r--r-- | src/commands/info/userInfo.ts | 91 |
2 files changed, 78 insertions, 17 deletions
diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index 0aabb70..55fb0b2 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -129,10 +129,10 @@ export default class GuildInfoCommand extends BushCommand { ); guildSecurity.push( - `**Verification Level**: ${BushGuildVerificationLevel[guild.verificationLevel]}`, + `**Verification Level:** ${BushGuildVerificationLevel[guild.verificationLevel]}`, `**Explicit Content Filter:** ${BushGuildExplicitContentFilter[guild.explicitContentFilter]}`, `**Default Message Notifications:** ${BushGuildDefaultMessageNotifications[guild.defaultMessageNotifications]}`, - `**2FA Required**: ${guild.mfaLevel === GuildMFALevel.Elevated ? 'True' : 'False'}` + `**2FA Required:** ${guild.mfaLevel === GuildMFALevel.Elevated ? 'True' : 'False'}` ); } else { guildAbout.push( diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index 50cb1a8..74f8185 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -7,7 +7,15 @@ import { type BushSlashMessage, type BushUser } from '#lib'; -import { ActivityType, ApplicationCommandOptionType, Embed, PermissionFlagsBits, UserFlags } from 'discord.js'; +import { APIApplication, TeamMemberMembershipState } from 'discord-api-types'; +import { + ActivityType, + ApplicationCommandOptionType, + ApplicationFlagsBitField, + Embed, + PermissionFlagsBits, + UserFlags +} from 'discord.js'; export default class UserInfoCommand extends BushCommand { public constructor() { @@ -43,7 +51,7 @@ export default class UserInfoCommand extends BushCommand { ? args.user : await client.users.fetch(`${args.user}`).catch(() => undefined); if (user === undefined) return message.util.reply(`${util.emojis.error} Invalid user.`); - const member = message.guild ? message.guild.members.cache.get(user.id) : undefined; + const member = message.guild ? await message.guild.members.fetch(user.id).catch(() => undefined) : undefined; await user.fetch(true); // gets banner info and accent color const userEmbed = await UserInfoCommand.makeUserInfoEmbed(user, member, message.guild); @@ -100,12 +108,17 @@ export default class UserInfoCommand extends BushCommand { this.generatePermissionsField(userEmbed, member); - if (emojis) userEmbed.setDescription(`\u200B${emojis.filter((e) => e).join(' ')}`); // zero width space + await this.generateBotField(userEmbed, user); + + if (emojis) + userEmbed.setDescription( + `\u200B${emojis.filter((e) => e).join(' ')}${userEmbed.description?.length ? `\n\n${userEmbed.description}` : ''}` + ); // zero width space return userEmbed; } private static async generateGeneralInfoField(embed: Embed, user: BushUser) { - const createdAt = util.timestamp(user.createdAt), + const createdAt = util.timestamp(user.createdAt, 'd'), createdAtDelta = util.dateDelta(user.createdAt); // General Info @@ -115,7 +128,7 @@ export default class UserInfoCommand extends BushCommand { 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}`); + if (pronouns && typeof pronouns === 'string' && pronouns !== 'Unspecified') generalInfo.push(`**Pronouns:** ${pronouns}`); embed.addField({ name: '» General Info', value: generalInfo.join('\n') }); } @@ -123,9 +136,9 @@ export default class UserInfoCommand extends BushCommand { private static generateServerInfoField(embed: Embed, member?: BushGuildMember | undefined) { if (!member) return; - const joinedAt = util.timestamp(member?.joinedAt), + const joinedAt = util.timestamp(member?.joinedAt, 'd'), joinedAtDelta = member.joinedAt ? util.dateDelta(member.joinedAt, 2) : undefined, - premiumSince = util.timestamp(member?.premiumSince), + premiumSince = util.timestamp(member?.premiumSince, 'd'), premiumSinceDelta = member.premiumSince ? util.dateDelta(member.premiumSince, 2) : undefined; // Server User Info @@ -188,16 +201,14 @@ export default class UserInfoCommand extends BushCommand { } private static generateRolesField(embed: Embed, member?: BushGuildMember | undefined) { - if (!member || !(member.roles.cache.size < 1)) return; + if (!member || member.roles.cache.size < 1) return; // roles - if (member?.roles.cache.size && member?.roles.cache.size - 1) { - const roles = member?.roles.cache - .filter((role) => role.name !== '@everyone') - .sort((role1, role2) => role2.position - role1.position) - .map((role) => `${role}`); - embed.addField({ name: `» Role${roles.length - 1 ? 's' : ''} [${roles.length}]`, value: roles.join(', ') }); - } + const roles = member.roles.cache + .filter((role) => role.name !== '@everyone') + .sort((role1, role2) => role2.position - role1.position) + .map((role) => `${role}`); + embed.addField({ name: `» Role${roles.length - 1 ? 's' : ''} [${roles.length}]`, value: roles.join(', ') }); } private static generatePermissionsField(embed: Embed, member: BushGuildMember | undefined) { @@ -217,4 +228,54 @@ export default class UserInfoCommand extends BushCommand { if (perms.length) embed.addField({ name: '» Important Perms', value: perms.join(' ') }); } + + private static async generateBotField(embed: Embed, user: BushUser) { + if (!user.bot) return; + + const applicationInfo = (await client.rest.get(`/applications/${user.id}/rpc`).catch(() => null)) as APIApplication | null; + if (!applicationInfo) return; + + const flags = new ApplicationFlagsBitField(applicationInfo.flags); + + const botInfo = [ + `**Publicity:** ${applicationInfo.bot_public ? 'Public' : 'Private'}`, + `**Requires Code Grant:** ${applicationInfo.bot_require_code_grant ? util.emojis.check : util.emojis.cross}`, + `**Server Members Intent:** ${ + flags.has('GatewayGuildMembers') + ? util.emojis.check + : flags.has('GatewayGuildMembersLimited') + ? util.emojis.warn + : util.emojis.cross + }`, + `**Presence Intent:** ${ + flags.has('GatewayPresence') + ? util.emojis.check + : flags.has('GatewayPresenceLimited') + ? util.emojis.warn + : util.emojis.cross + }`, + `**Message Content Intent:** ${ + flags.has('GatewayMessageContent') + ? util.emojis.check + : flags.has('GatewayMessageContentLimited') + ? util.emojis.warn + : util.emojis.cross + }` + ]; + + if (applicationInfo.owner || applicationInfo.team) { + const teamMembers = applicationInfo.owner + ? [applicationInfo.owner] + : applicationInfo + .team!.members.filter((tm) => tm.membership_state === TeamMemberMembershipState.Accepted) + .map((tm) => tm.user); + botInfo.push( + `**Developer${teamMembers.length > 1 ? 's' : ''}:** ${teamMembers + .map((m) => `${m.username}#${m.discriminator}`) + .join(', ')}` + ); + } + + if (botInfo.length) embed.addField({ name: '» Bot Info', value: botInfo.join('\n') }); + } } |