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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (hide annotations)
Mon Jul 29 17:28:27 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 5010 byte(s)
Added slash commands autocompletion support
1 rakin 51 import { ColorResolvable, CommandInteraction, GuildMember, Message, User } 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 e from 'express';
8     import getUser from '../../utils/getUser';
9     import getMember from '../../utils/getMember';
10     import { timeSince } from '../../utils/util';
11     import { roleMention } from '@discordjs/builders';
12    
13     export default class ProfileCommand extends BaseCommand {
14     supportsInteractions: boolean = true;
15    
16     constructor() {
17     super('profile', 'information', []);
18     }
19    
20     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
21     let user: GuildMember | null = null;
22    
23     if (msg instanceof CommandInteraction && options.isInteraction) {
24     if (options.options.getMember('user'))
25     user = <GuildMember> await options.options.getMember('user');
26     else
27     user = <GuildMember> msg.member!;
28     }
29     else if (msg instanceof Message && !options.isInteraction) {
30     if (options.normalArgs[0]) {
31     try {
32     const tempMember = await getMember(msg, options);
33    
34     if (!tempMember)
35     throw new Error();
36    
37     user = tempMember;
38     }
39     catch (e) {
40     console.log(e);
41    
42     await msg.reply({
43     embeds: [
44     new MessageEmbed()
45     .setColor('#f14a60')
46     .setDescription(':x: The user doesn\'t exist or not a member of this server.')
47     ]
48     });
49    
50     return;
51     }
52     }
53     else {
54     user = msg.member!;
55     }
56     }
57    
58 rakin 64 const status = (s: 'idle' | 'online' | 'dnd' | 'invisible' | null | undefined): string => {
59     if (s === 'idle')
60     return 'Idle';
61     else if (s === 'dnd')
62     return 'Do not disturb';
63     else if (s === 'online')
64     return 'Online';
65     else if (s === undefined || s === null || s === 'invisible')
66     return 'Offline/Invisible';
67    
68     return s;
69     };
70    
71     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) + ')' : ''));
72     const state = user?.presence?.activities.find(a => a.type === 'CUSTOM')?.state;
73    
74 rakin 51 await msg.reply({
75     embeds: [
76     new MessageEmbed()
77     .setColor(user!.user!.hexAccentColor ? user!.user!.hexAccentColor! : '#007bff')
78     .setAuthor({
79     name: user?.user.tag!,
80 rakin 64 iconURL: user!.user.displayAvatarURL()
81 rakin 51 })
82     .setImage(user!.displayAvatarURL({
83     size: 4096
84     }))
85     .setURL(user!.displayAvatarURL({
86     size: 4096
87     }))
88     .setFields([
89     {
90     name: "ID",
91     value: `${user!.id}`
92     },
93     {
94     name: "Nickname",
95     value: `${user!.nickname?.replace(/\*\<\>\@\_\~\|/g, '') ?? '*Nickname not set*'}`
96     },
97     {
98     name: "Account Created",
99     value: `${user!.user.createdAt.toLocaleDateString('en-US')} (${timeSince(user!.user.createdTimestamp)})`
100     },
101     {
102 rakin 64 name: "Joined at",
103     value: `${user!.joinedAt!.toLocaleDateString('en-US')} (${timeSince(user!.joinedTimestamp!)})`
104     },
105     {
106     name: 'Active Devices',
107     value: `${statusText === '' ? 'Offline/Invisible' : statusText}`
108     },
109     {
110     name: 'Custom Status',
111     value: `${state ?? '*No custom status set*'}`
112     },
113     {
114 rakin 51 name: 'Roles',
115     value: user?.roles.cache.filter(role => role.id !== msg.guild!.id).reduce((acc, value) => `${acc} ${roleMention(value.id)}`, '')!.trim()!
116     }
117     ])
118     ]
119     });
120     }
121     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26