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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (hide annotations)
Mon Jul 29 17:29:40 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 5676 byte(s)
chore: eslint autofix
1 rakin 285 import { formatDistanceStrict, formatDistanceToNowStrict } from "date-fns";
2     import { APIEmbedField } from "discord-api-types/v9";
3 rakin 344 import { Util, Message, CacheType, CommandInteraction } from "discord.js";
4 rakin 285 import Client from "../../client/Client";
5     import MessageEmbed from "../../client/MessageEmbed";
6     import CommandOptions from "../../types/CommandOptions";
7     import InteractionOptions from "../../types/InteractionOptions";
8     import { emoji } from "../../utils/Emoji";
9     import getUser from "../../utils/getUser";
10     import BaseCommand from "../../utils/structures/BaseCommand";
11 rakin 290 import { getUserBadges } from "./ProfileCommand";
12 rakin 285
13     export default class UserLookupCommand extends BaseCommand {
14     supportsInteractions: boolean = true;
15    
16     constructor() {
17     super("userlookup", "information", ['user', 'ulookup']);
18     }
19    
20     async run(client: Client, message: CommandInteraction<CacheType> | Message<boolean>, options: CommandOptions | InteractionOptions): Promise<void> {
21     if (!options.isInteraction && options.args[0] === undefined) {
22     await message.reply({ ephemeral: true, content: `${emoji("error")} You must specify a user to lookup!` });
23     return;
24     }
25    
26     const user = !options.isInteraction ? await getUser(client, message as Message, options, 0) : options.options.getUser("user");
27    
28     if (!user) {
29     await message.reply({ content: `${emoji("error")} That user does not exist.` });
30     return;
31     }
32    
33     let member = undefined;
34    
35     try {
36     member = await message.guild!.members.fetch(user.id);
37    
38     if (!member)
39     throw new Error("Member not found");
40     }
41     catch (e) {
42     console.log(e);
43     member = undefined;
44     }
45    
46     const embed = new MessageEmbed({
47     author: {
48     name: user.tag,
49     iconURL: user.displayAvatarURL()
50     },
51     footer: {
52     text: `${user.id}`,
53     }
54     });
55    
56 rakin 289
57     if (user.hexAccentColor) {
58     embed.setColor(user.hexAccentColor);
59     }
60    
61 rakin 285 const fieldsCommon: APIEmbedField[] = [
62    
63     ];
64    
65     let fields: APIEmbedField[] = [
66     {
67     name: "Server Member?",
68     value: member ? "Yes" : "No",
69 rakin 289 inline: true
70 rakin 285 },
71     {
72 rakin 289 name: "Bot?",
73     value: user.bot ? "Yes" : "No",
74     inline: true
75     },
76     {
77 rakin 285 name: "Account created",
78 rakin 289 value: user.createdAt.toLocaleString() + " (" + formatDistanceToNowStrict(user.createdAt, { addSuffix: true }) + ")",
79 rakin 285 inline: true
80     }
81     ];
82    
83 rakin 290 embed.setThumbnail(user.displayAvatarURL());
84    
85 rakin 285 if (member) {
86     fields.push({
87     name: "Joined Server",
88 rakin 289 value: member.joinedAt ? member.joinedAt.toLocaleString() + " (" + formatDistanceToNowStrict(member.joinedAt, { addSuffix: true }) + ")" : "Information not available",
89 rakin 285 inline: true
90     });
91    
92     if (member.premiumSince) {
93     fields.push({
94     name: "Boosted Server",
95 rakin 289 value: member.premiumSince.toLocaleString() + " (" + formatDistanceToNowStrict(member.premiumSince, { addSuffix: true }) + ")",
96 rakin 285 inline: true
97     });
98     }
99    
100     if (member.communicationDisabledUntil) {
101     fields.push({
102     name: "Timed-out Until",
103 rakin 289 value: member.communicationDisabledUntil.toLocaleString() + " (" + formatDistanceStrict(member.communicationDisabledUntil, new Date()) + ")",
104 rakin 285 inline: true
105     });
106     }
107    
108 rakin 289 if (member.displayAvatarURL()) {
109 rakin 285 embed.setThumbnail(member.displayAvatarURL());
110     }
111 rakin 289
112     if (member.nickname) {
113     fields.push({
114     name: "Nickname",
115     value: Util.escapeMarkdown(member.nickname)
116     });
117     }
118    
119     if (member.displayHexColor) {
120     fields.push({
121     name: "Guild Profile Theme Color",
122     value: member.displayHexColor
123     });
124     }
125    
126     if (member.displayHexColor && !user.hexAccentColor) {
127     embed.setColor(member.displayHexColor);
128     }
129    
130     if (member.voice && member.voice.channel) {
131     fields.push({
132     name: "Current Voice Channel",
133     value: member.voice.channel.toString()
134     });
135     }
136    
137     fields.push({
138     name: "Completed Membership Screening",
139     value: member.pending ? "No" : "Yes"
140     });
141    
142     fields.push({
143     name: "Mention",
144     value: member.toString()
145     });
146    
147     if (member.roles.highest.id !== member.guild.id) {
148     fields.push({
149     name: "Highest Role",
150     value: member.roles.highest.toString()
151     });
152     }
153 rakin 285 }
154    
155 rakin 290 const badges = getUserBadges(user).join('\n');
156    
157     fields.push({
158     name: "Badges",
159     value: badges.trim() === '' ? '*No badges found*' : badges
160     });
161    
162 rakin 285 fields = [...fields, ...fieldsCommon];
163     embed.setFields(fields);
164 rakin 289 embed.setTimestamp();
165 rakin 285
166     await message.reply({
167     embeds: [
168     embed
169     ]
170     });
171     }
172     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26