/[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 393 - (hide annotations)
Mon Jul 29 17:29:59 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 6400 byte(s)
style: add license comments (#77)

* style: add license commits

* fix: shebang errors
1 rakin 393 /**
2     * This file is part of SudoBot.
3     *
4     * Copyright (C) 2021-2022 OSN Inc.
5     *
6     * SudoBot is free software; you can redistribute it and/or modify it
7     * under the terms of the GNU Affero General Public License as published by
8     * the Free Software Foundation, either version 3 of the License, or
9     * (at your option) any later version.
10     *
11     * SudoBot is distributed in the hope that it will be useful, but
12     * WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU Affero General Public License for more details.
15     *
16     * You should have received a copy of the GNU Affero General Public License
17     * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18     */
19    
20 rakin 285 import { formatDistanceStrict, formatDistanceToNowStrict } from "date-fns";
21     import { APIEmbedField } from "discord-api-types/v9";
22 rakin 344 import { Util, Message, CacheType, CommandInteraction } from "discord.js";
23 rakin 285 import Client from "../../client/Client";
24     import MessageEmbed from "../../client/MessageEmbed";
25     import CommandOptions from "../../types/CommandOptions";
26     import InteractionOptions from "../../types/InteractionOptions";
27     import { emoji } from "../../utils/Emoji";
28     import getUser from "../../utils/getUser";
29     import BaseCommand from "../../utils/structures/BaseCommand";
30 rakin 290 import { getUserBadges } from "./ProfileCommand";
31 rakin 285
32     export default class UserLookupCommand extends BaseCommand {
33     supportsInteractions: boolean = true;
34    
35     constructor() {
36     super("userlookup", "information", ['user', 'ulookup']);
37     }
38    
39     async run(client: Client, message: CommandInteraction<CacheType> | Message<boolean>, options: CommandOptions | InteractionOptions): Promise<void> {
40     if (!options.isInteraction && options.args[0] === undefined) {
41     await message.reply({ ephemeral: true, content: `${emoji("error")} You must specify a user to lookup!` });
42     return;
43     }
44    
45     const user = !options.isInteraction ? await getUser(client, message as Message, options, 0) : options.options.getUser("user");
46    
47     if (!user) {
48     await message.reply({ content: `${emoji("error")} That user does not exist.` });
49     return;
50     }
51    
52     let member = undefined;
53    
54     try {
55     member = await message.guild!.members.fetch(user.id);
56    
57     if (!member)
58     throw new Error("Member not found");
59     }
60     catch (e) {
61     console.log(e);
62     member = undefined;
63     }
64    
65     const embed = new MessageEmbed({
66     author: {
67     name: user.tag,
68     iconURL: user.displayAvatarURL()
69     },
70     footer: {
71     text: `${user.id}`,
72     }
73     });
74    
75 rakin 289
76     if (user.hexAccentColor) {
77     embed.setColor(user.hexAccentColor);
78     }
79    
80 rakin 285 const fieldsCommon: APIEmbedField[] = [
81    
82     ];
83    
84     let fields: APIEmbedField[] = [
85     {
86     name: "Server Member?",
87     value: member ? "Yes" : "No",
88 rakin 289 inline: true
89 rakin 285 },
90     {
91 rakin 289 name: "Bot?",
92     value: user.bot ? "Yes" : "No",
93     inline: true
94     },
95     {
96 rakin 285 name: "Account created",
97 rakin 289 value: user.createdAt.toLocaleString() + " (" + formatDistanceToNowStrict(user.createdAt, { addSuffix: true }) + ")",
98 rakin 285 inline: true
99     }
100     ];
101    
102 rakin 290 embed.setThumbnail(user.displayAvatarURL());
103    
104 rakin 285 if (member) {
105     fields.push({
106     name: "Joined Server",
107 rakin 289 value: member.joinedAt ? member.joinedAt.toLocaleString() + " (" + formatDistanceToNowStrict(member.joinedAt, { addSuffix: true }) + ")" : "Information not available",
108 rakin 285 inline: true
109     });
110    
111     if (member.premiumSince) {
112     fields.push({
113     name: "Boosted Server",
114 rakin 289 value: member.premiumSince.toLocaleString() + " (" + formatDistanceToNowStrict(member.premiumSince, { addSuffix: true }) + ")",
115 rakin 285 inline: true
116     });
117     }
118    
119     if (member.communicationDisabledUntil) {
120     fields.push({
121     name: "Timed-out Until",
122 rakin 289 value: member.communicationDisabledUntil.toLocaleString() + " (" + formatDistanceStrict(member.communicationDisabledUntil, new Date()) + ")",
123 rakin 285 inline: true
124     });
125     }
126    
127 rakin 289 if (member.displayAvatarURL()) {
128 rakin 285 embed.setThumbnail(member.displayAvatarURL());
129     }
130 rakin 289
131     if (member.nickname) {
132     fields.push({
133     name: "Nickname",
134     value: Util.escapeMarkdown(member.nickname)
135     });
136     }
137    
138     if (member.displayHexColor) {
139     fields.push({
140     name: "Guild Profile Theme Color",
141     value: member.displayHexColor
142     });
143     }
144    
145     if (member.displayHexColor && !user.hexAccentColor) {
146     embed.setColor(member.displayHexColor);
147     }
148    
149     if (member.voice && member.voice.channel) {
150     fields.push({
151     name: "Current Voice Channel",
152     value: member.voice.channel.toString()
153     });
154     }
155    
156     fields.push({
157     name: "Completed Membership Screening",
158     value: member.pending ? "No" : "Yes"
159     });
160    
161     fields.push({
162     name: "Mention",
163     value: member.toString()
164     });
165    
166     if (member.roles.highest.id !== member.guild.id) {
167     fields.push({
168     name: "Highest Role",
169     value: member.roles.highest.toString()
170     });
171     }
172 rakin 285 }
173    
174 rakin 290 const badges = getUserBadges(user).join('\n');
175    
176     fields.push({
177     name: "Badges",
178     value: badges.trim() === '' ? '*No badges found*' : badges
179     });
180    
181 rakin 285 fields = [...fields, ...fieldsCommon];
182     embed.setFields(fields);
183 rakin 289 embed.setTimestamp();
184 rakin 285
185     await message.reply({
186     embeds: [
187     embed
188     ]
189     });
190     }
191     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26