/[sudobot]/branches/2.x/src/commands/information/ProfileCommand.ts
ViewVC logotype

Annotation of /branches/2.x/src/commands/information/ProfileCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 8021 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 import { ColorResolvable, CommandInteraction, GuildMember, Message, User, UserFlags } from 'discord.js';
2     import BaseCommand from '../../utils/structures/BaseCommand';
3     import DiscordClient from '../../client/Client';
4     import CommandOptions from '../../types/CommandOptions';
5     import InteractionOptions from '../../types/InteractionOptions';
6     import MessageEmbed from '../../client/MessageEmbed';
7     import getMember from '../../utils/getMember';
8     import { timeSince } from '../../utils/util';
9     import { roleMention } from '@discordjs/builders';
10    
11     export default class ProfileCommand extends BaseCommand {
12     supportsInteractions: boolean = true;
13    
14     constructor() {
15     super('profile', 'information', []);
16     }
17    
18     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
19     let user: GuildMember | null = null;
20    
21     if (msg instanceof CommandInteraction && options.isInteraction) {
22     if (options.options.getMember('user'))
23     user = <GuildMember> await options.options.getMember('user');
24     else
25     user = <GuildMember> msg.member!;
26     }
27     else if (msg instanceof Message && !options.isInteraction) {
28     if (options.normalArgs[0]) {
29     try {
30     const tempMember = await getMember(msg, options);
31    
32     if (!tempMember)
33     throw new Error();
34    
35     user = tempMember;
36     }
37     catch (e) {
38     console.log(e);
39    
40     await msg.reply({
41     embeds: [
42     new MessageEmbed()
43     .setColor('#f14a60')
44     .setDescription(':x: The user doesn\'t exist or not a member of this server.')
45     ]
46     });
47    
48     return;
49     }
50     }
51     else {
52     user = msg.member!;
53     }
54     }
55    
56     const status = (s: 'idle' | 'online' | 'dnd' | 'invisible' | null | undefined): string => {
57     if (s === 'idle')
58     return 'Idle';
59     else if (s === 'dnd')
60     return 'Do not disturb';
61     else if (s === 'online')
62     return 'Online';
63     else if (s === undefined || s === null || s === 'invisible')
64     return 'Offline/Invisible';
65    
66     return s;
67     };
68    
69     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) + ')' : ''));
70     // const state = user?.presence?.activities.find(a => a.type === 'CUSTOM')?.state;
71     let activities: string[] | string = [];
72    
73     if (user?.presence) {
74     for (const a of user?.presence?.activities.values()!) {
75     console.log(a);
76    
77     if (a.type === 'CUSTOM') {
78     activities.push(`${a.emoji?.toString()} ${a.state}`);
79     }
80     else if (a.type === 'LISTENING') {
81     if (a.name === 'Spotify') {
82     activities.push(`:notes: Listening to **Spotify**: **${a.state?.replace(/\;/, ',')} - ${a.details}**`);
83     continue;
84     }
85    
86     activities.push(`:musical_note: Listening to **${a.name}**`);
87     }
88     else if (a.type === 'COMPETING') {
89     activities.push(`:fire: Competing **${a.name}**`);
90     }
91     else if (a.type === 'PLAYING') {
92     activities.push(`:video_game: Playing **${a.name}**`);
93     }
94     else if (a.type === 'STREAMING') {
95     activities.push(`:video_camera: Streaming **${a.name}**`);
96     }
97     else if (a.type === 'WATCHING') {
98     activities.push(`:tv: Watching **${a.name}**`);
99     }
100     }
101     }
102    
103     activities = activities.join('\n');
104    
105     const { FLAGS } = UserFlags;
106    
107     const getUserBadges = (user: User) => {
108     const badges = [];
109    
110     if (user.flags?.has(FLAGS.BUGHUNTER_LEVEL_1))
111     badges.push('Bughunter Level 1');
112     if (user.flags?.has(FLAGS.BUGHUNTER_LEVEL_2))
113     badges.push('Bughunter Level 2');
114     if (user.flags?.has(FLAGS.DISCORD_CERTIFIED_MODERATOR))
115     badges.push('Discord Certified Moderator');
116     if (user.flags?.has(FLAGS.DISCORD_EMPLOYEE))
117     badges.push('Discord Staff');
118     if (user.flags?.has(FLAGS.EARLY_SUPPORTER))
119     badges.push('Early Nitro Supporter');
120     if (user.flags?.has(FLAGS.EARLY_VERIFIED_BOT_DEVELOPER))
121     badges.push('Early Verified Bot Developer');
122     if (user.flags?.has(FLAGS.HOUSE_BALANCE))
123     badges.push('HypeSquad Balance');
124     if (user.flags?.has(FLAGS.HOUSE_BRILLIANCE))
125     badges.push('HypeSquad Brilliance');
126     if (user.flags?.has(FLAGS.HOUSE_BRAVERY))
127     badges.push('HypeSquad Bravery');
128     if (user.flags?.has(FLAGS.HYPESQUAD_EVENTS))
129     badges.push('HypeSquad Events');
130     if (user.flags?.has(FLAGS.PARTNERED_SERVER_OWNER))
131     badges.push('Partnered Server Owner');
132     if (user.flags?.has(FLAGS.BOT_HTTP_INTERACTIONS))
133     badges.push('Supports Interactions');
134     if (user.flags?.has(FLAGS.VERIFIED_BOT))
135     badges.push('Verified Bot');
136    
137     return badges.map(b => `🔵 ${b}`);
138     };
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({
179     embeds: [
180     new MessageEmbed()
181     .setColor(user!.user!.hexAccentColor ? user!.user!.hexAccentColor! : '#007bff')
182     .setAuthor({
183     name: user?.user.tag!,
184     iconURL: user!.user.displayAvatarURL()
185     })
186     .setThumbnail(user!.displayAvatarURL({
187     size: 4096
188     }))
189     .setFields(fields)
190     .setFooter({
191     text: `${user!.id} - ${user?.user.bot ? 'Bot' : 'User'}`
192     })
193     ]
194     });
195     }
196     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26