/[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 51 - (hide annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3534 byte(s)
Release version 2.0
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     await msg.reply({
59     embeds: [
60     new MessageEmbed()
61     .setColor(user!.user!.hexAccentColor ? user!.user!.hexAccentColor! : '#007bff')
62     .setAuthor({
63     name: user?.user.tag!,
64     iconURL: user!.displayAvatarURL()
65     })
66     .setImage(user!.displayAvatarURL({
67     size: 4096
68     }))
69     .setURL(user!.displayAvatarURL({
70     size: 4096
71     }))
72     .setFields([
73     {
74     name: "ID",
75     value: `${user!.id}`
76     },
77     {
78     name: "Nickname",
79     value: `${user!.nickname?.replace(/\*\<\>\@\_\~\|/g, '') ?? '*Nickname not set*'}`
80     },
81     {
82     name: "Account Created",
83     value: `${user!.user.createdAt.toLocaleDateString('en-US')} (${timeSince(user!.user.createdTimestamp)})`
84     },
85     {
86     name: 'Roles',
87     value: user?.roles.cache.filter(role => role.id !== msg.guild!.id).reduce((acc, value) => `${acc} ${roleMention(value.id)}`, '')!.trim()!
88     }
89     ])
90     ]
91     });
92     }
93     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26