/[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 285 - (hide annotations)
Mon Jul 29 17:29:22 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3666 byte(s)
feat: add basic user lookup 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    
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     const fieldsCommon: APIEmbedField[] = [
57    
58     ];
59    
60     let fields: APIEmbedField[] = [
61     {
62     name: "Server Member?",
63     value: member ? "Yes" : "No",
64     },
65     {
66     name: "Account created",
67     value: formatDistanceToNowStrict(user.createdAt, { addSuffix: true }),
68     inline: true
69     }
70     ];
71    
72     if (member) {
73     fields.push({
74     name: "Joined Server",
75     value: member.joinedAt ? formatDistanceToNowStrict(member.joinedAt, { addSuffix: true }) : "Information not available",
76     inline: true
77     });
78    
79     if (member.premiumSince) {
80     fields.push({
81     name: "Boosted Server",
82     value: formatDistanceToNowStrict(member.premiumSince, { addSuffix: true }),
83     inline: true
84     });
85     }
86    
87     if (member.communicationDisabledUntil) {
88     fields.push({
89     name: "Timed-out Until",
90     value: formatDistanceStrict(member.communicationDisabledUntil, new Date()),
91     inline: true
92     });
93     }
94    
95     if (member.displayAvatarURL() != user.displayAvatarURL()) {
96     embed.setThumbnail(member.displayAvatarURL());
97     }
98     }
99    
100     fields = [...fields, ...fieldsCommon];
101     embed.setFields(fields);
102    
103     await message.reply({
104     embeds: [
105     embed
106     ]
107     });
108     }
109     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26