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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26