/[sudobot]/trunk/src/commands/information/ProfileCommand.ts
ViewVC logotype

Diff of /trunk/src/commands/information/ProfileCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 51 by rakin, Mon Jul 29 17:28:23 2024 UTC revision 290 by rakin, Mon Jul 29 17:29:23 2024 UTC
# Line 1  Line 1 
1  import { ColorResolvable, CommandInteraction, GuildMember, Message, User } from 'discord.js';  import { CommandInteraction, GuildMember, Message, User, UserFlags } from 'discord.js';
2  import BaseCommand from '../../utils/structures/BaseCommand';  import BaseCommand from '../../utils/structures/BaseCommand';
3  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
4  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
5  import InteractionOptions from '../../types/InteractionOptions';  import InteractionOptions from '../../types/InteractionOptions';
6  import MessageEmbed from '../../client/MessageEmbed';  import MessageEmbed from '../../client/MessageEmbed';
 import e from 'express';  
 import getUser from '../../utils/getUser';  
7  import getMember from '../../utils/getMember';  import getMember from '../../utils/getMember';
8  import { timeSince } from '../../utils/util';  import { timeSince } from '../../utils/util';
9  import { roleMention } from '@discordjs/builders';  import { roleMention } from '@discordjs/builders';
10    
11    export const getUserBadges = (user: User) => {
12        const { FLAGS } = UserFlags;
13        
14        const badges = [];
15    
16        if (user.flags?.has(FLAGS.BUGHUNTER_LEVEL_1))
17            badges.push('Bughunter Level 1');
18        if (user.flags?.has(FLAGS.BUGHUNTER_LEVEL_2))
19            badges.push('Bughunter Level 2');
20        if (user.flags?.has(FLAGS.DISCORD_CERTIFIED_MODERATOR))
21            badges.push('Discord Certified Moderator');
22        if (user.flags?.has(FLAGS.DISCORD_EMPLOYEE))
23            badges.push('Discord Staff');
24        if (user.flags?.has(FLAGS.EARLY_SUPPORTER))
25            badges.push('Early Nitro Supporter');
26        if (user.flags?.has(FLAGS.EARLY_VERIFIED_BOT_DEVELOPER))
27            badges.push('Early Verified Bot Developer');
28        if (user.flags?.has(FLAGS.HOUSE_BALANCE))
29            badges.push('HypeSquad Balance');
30        if (user.flags?.has(FLAGS.HOUSE_BRILLIANCE))
31            badges.push('HypeSquad Brilliance');
32        if (user.flags?.has(FLAGS.HOUSE_BRAVERY))
33            badges.push('HypeSquad Bravery');
34        if (user.flags?.has(FLAGS.HYPESQUAD_EVENTS))
35            badges.push('HypeSquad Events');
36        if (user.flags?.has(FLAGS.PARTNERED_SERVER_OWNER))
37            badges.push('Partnered Server Owner');
38        if (user.flags?.has(FLAGS.BOT_HTTP_INTERACTIONS))
39            badges.push('Supports Interactions');
40        if (user.flags?.has(FLAGS.VERIFIED_BOT))
41            badges.push('Verified Bot');
42        
43        return badges.map(b => `🔵 ${b}`);
44    };
45    
46  export default class ProfileCommand extends BaseCommand {  export default class ProfileCommand extends BaseCommand {
47      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
48    
# Line 55  export default class ProfileCommand exte Line 88  export default class ProfileCommand exte
88              }              }
89          }          }
90    
91            const status = (s: 'idle' | 'online' | 'dnd' | 'invisible' | null | undefined): string => {
92                if (s === 'idle')
93                    return 'Idle';
94                else if (s === 'dnd')
95                    return 'Do not disturb';
96                else if (s === 'online')
97                    return 'Online';
98                else if (s === undefined || s === null || s === 'invisible')
99                    return 'Offline/Invisible';
100    
101                return s;
102            };    
103    
104            const statusText = '' + ((user?.presence?.clientStatus?.desktop ? 'Desktop (' + status(user?.presence?.clientStatus?.desktop) + ')\n' : '') + (user?.presence?.clientStatus?.web ? 'Web (' + status(user?.presence?.clientStatus?.web) + ')\n' : '') + (user?.presence?.clientStatus?.mobile ? 'Mobile (' + status(user?.presence?.clientStatus?.mobile) + ')' : ''));
105            // const state = user?.presence?.activities.find(a => a.type === 'CUSTOM')?.state;
106            let activities: string[] | string = [];
107    
108            if (user?.presence) {
109                for (const a of user?.presence?.activities.values()!) {
110                    console.log(a);
111                    
112                    if (a.type === 'CUSTOM') {
113                        activities.push(`${a.emoji ? `${a.emoji.toString()} ` : ''}${a.state}`);
114                    }
115                    else if (a.type === 'LISTENING') {
116                        if (a.name === 'Spotify') {
117                            activities.push(`:notes: Listening to **Spotify**: **${a.state?.replace(/\;/, ',')} - ${a.details}**`);
118                            continue;
119                        }
120    
121                        activities.push(`:musical_note: Listening to **${a.name}**`);
122                    }
123                    else if (a.type === 'COMPETING') {
124                        activities.push(`:fire: Competing **${a.name}**`);
125                    }
126                    else if (a.type === 'PLAYING') {
127                        activities.push(`:video_game: Playing **${a.name}**`);
128                    }
129                    else if (a.type === 'STREAMING') {
130                        activities.push(`:video_camera: Streaming **${a.name}**`);
131                    }
132                    else if (a.type === 'WATCHING') {
133                        activities.push(`:tv: Watching **${a.name}**`);
134                    }
135                }
136            }
137    
138            activities = activities.join('\n');
139    
140            const fields = [
141                {
142                    name: "Nickname",
143                    value: `${user!.nickname?.replace(/\*\<\>\@\_\~\|/g, '') ?? '*Nickname not set*'}`
144                },
145                {
146                    name: "Account Created",
147                    value: `${user!.user.createdAt.toLocaleDateString('en-US')} (${timeSince(user!.user.createdTimestamp)})`
148                },
149                {
150                    name: "Joined at",
151                    value: `${user!.joinedAt!.toLocaleDateString('en-US')} (${timeSince(user!.joinedTimestamp!)})`
152                },
153                {
154                    name: 'Active Devices',
155                    value: `${statusText === '' ? 'Offline/Invisible' : statusText}`
156                },
157                {
158                    name: 'Status',
159                    value: `${activities?.trim() === '' ? '*No status set*' : activities}`
160                },
161                {
162                    name: 'Roles',
163                    value: user?.roles.cache.filter(role => role.id !== msg.guild!.id).sort((role1, role2) => {
164                        return role2.position - role1.position;
165                    }).reduce((acc, value) => `${acc} ${roleMention(value.id)}`, '')!.trim()!
166                }
167            ];
168    
169            const badges = getUserBadges(user!.user);
170    
171            if (badges.length > 0) {
172                fields.push({
173                    name: 'Badges',
174                    value: badges.join("\n")
175                });
176            }
177    
178          await msg.reply({          await msg.reply({
179              embeds: [              embeds: [
180                  new MessageEmbed()                  new MessageEmbed()
181                  .setColor(user!.user!.hexAccentColor ? user!.user!.hexAccentColor! : '#007bff')                  .setColor(user!.user!.hexAccentColor ? user!.user!.hexAccentColor! : '#007bff')
182                  .setAuthor({                  .setAuthor({
183                      name: user?.user.tag!,                      name: user?.user.tag!,
184                      iconURL: user!.displayAvatarURL()                      iconURL: user!.user.displayAvatarURL()
185                  })                  })
186                  .setImage(user!.displayAvatarURL({                  .setThumbnail(user!.displayAvatarURL({
                     size: 4096  
                 }))  
                 .setURL(user!.displayAvatarURL({  
187                      size: 4096                      size: 4096
188                  }))                  }))
189                  .setFields([                  .setFields(fields)
190                      {                  .setFooter({
191                          name: "ID",                      text: `${user!.id} - ${user?.user.bot ? 'Bot' : 'User'}`
192                          value: `${user!.id}`                  })
                     },  
                     {  
                         name: "Nickname",  
                         value: `${user!.nickname?.replace(/\*\<\>\@\_\~\|/g, '') ?? '*Nickname not set*'}`  
                     },  
                     {  
                         name: "Account Created",  
                         value: `${user!.user.createdAt.toLocaleDateString('en-US')} (${timeSince(user!.user.createdTimestamp)})`  
                     },  
                     {  
                         name: 'Roles',  
                         value: user?.roles.cache.filter(role => role.id !== msg.guild!.id).reduce((acc, value) => `${acc} ${roleMention(value.id)}`, '')!.trim()!  
                     }  
                 ])  
193              ]              ]
194          });          });
195      }      }

Legend:
Removed from v.51  
changed lines
  Added in v.290

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26