1 |
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 |
|
57 |
if (user.hexAccentColor) { |
58 |
embed.setColor(user.hexAccentColor); |
59 |
} |
60 |
|
61 |
const fieldsCommon: APIEmbedField[] = [ |
62 |
|
63 |
]; |
64 |
|
65 |
let fields: APIEmbedField[] = [ |
66 |
{ |
67 |
name: "Server Member?", |
68 |
value: member ? "Yes" : "No", |
69 |
inline: true |
70 |
}, |
71 |
{ |
72 |
name: "Bot?", |
73 |
value: user.bot ? "Yes" : "No", |
74 |
inline: true |
75 |
}, |
76 |
{ |
77 |
name: "Account created", |
78 |
value: user.createdAt.toLocaleString() + " (" + formatDistanceToNowStrict(user.createdAt, { addSuffix: true }) + ")", |
79 |
inline: true |
80 |
} |
81 |
]; |
82 |
|
83 |
if (member) { |
84 |
fields.push({ |
85 |
name: "Joined Server", |
86 |
value: member.joinedAt ? member.joinedAt.toLocaleString() + " (" + formatDistanceToNowStrict(member.joinedAt, { addSuffix: true }) + ")" : "Information not available", |
87 |
inline: true |
88 |
}); |
89 |
|
90 |
if (member.premiumSince) { |
91 |
fields.push({ |
92 |
name: "Boosted Server", |
93 |
value: member.premiumSince.toLocaleString() + " (" + formatDistanceToNowStrict(member.premiumSince, { addSuffix: true }) + ")", |
94 |
inline: true |
95 |
}); |
96 |
} |
97 |
|
98 |
if (member.communicationDisabledUntil) { |
99 |
fields.push({ |
100 |
name: "Timed-out Until", |
101 |
value: member.communicationDisabledUntil.toLocaleString() + " (" + formatDistanceStrict(member.communicationDisabledUntil, new Date()) + ")", |
102 |
inline: true |
103 |
}); |
104 |
} |
105 |
|
106 |
if (member.displayAvatarURL()) { |
107 |
embed.setThumbnail(member.displayAvatarURL()); |
108 |
} |
109 |
|
110 |
if (member.nickname) { |
111 |
fields.push({ |
112 |
name: "Nickname", |
113 |
value: Util.escapeMarkdown(member.nickname) |
114 |
}); |
115 |
} |
116 |
|
117 |
if (member.displayHexColor) { |
118 |
fields.push({ |
119 |
name: "Guild Profile Theme Color", |
120 |
value: member.displayHexColor |
121 |
}); |
122 |
} |
123 |
|
124 |
if (member.displayHexColor && !user.hexAccentColor) { |
125 |
embed.setColor(member.displayHexColor); |
126 |
} |
127 |
|
128 |
if (member.voice && member.voice.channel) { |
129 |
fields.push({ |
130 |
name: "Current Voice Channel", |
131 |
value: member.voice.channel.toString() |
132 |
}); |
133 |
} |
134 |
|
135 |
fields.push({ |
136 |
name: "Completed Membership Screening", |
137 |
value: member.pending ? "No" : "Yes" |
138 |
}); |
139 |
|
140 |
fields.push({ |
141 |
name: "Mention", |
142 |
value: member.toString() |
143 |
}); |
144 |
|
145 |
if (member.roles.highest.id !== member.guild.id) { |
146 |
fields.push({ |
147 |
name: "Highest Role", |
148 |
value: member.roles.highest.toString() |
149 |
}); |
150 |
} |
151 |
} |
152 |
|
153 |
fields = [...fields, ...fieldsCommon]; |
154 |
embed.setFields(fields); |
155 |
embed.setTimestamp(); |
156 |
|
157 |
await message.reply({ |
158 |
embeds: [ |
159 |
embed |
160 |
] |
161 |
}); |
162 |
} |
163 |
} |