1 |
import { ColorResolvable, CommandInteraction, GuildMember, Message, User, UserFlags } from 'discord.js'; |
/** |
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 |
|
import { CommandInteraction, GuildMember, Message, User, UserFlags } from 'discord.js'; |
21 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
22 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
23 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
24 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
25 |
import MessageEmbed from '../../client/MessageEmbed'; |
import MessageEmbed from '../../client/MessageEmbed'; |
|
import e from 'express'; |
|
|
import getUser from '../../utils/getUser'; |
|
26 |
import getMember from '../../utils/getMember'; |
import getMember from '../../utils/getMember'; |
27 |
import { timeSince } from '../../utils/util'; |
import { timeSince } from '../../utils/util'; |
28 |
import { roleMention } from '@discordjs/builders'; |
import { roleMention } from '@discordjs/builders'; |
29 |
|
|
30 |
|
export const getUserBadges = (user: User) => { |
31 |
|
const { FLAGS } = UserFlags; |
32 |
|
|
33 |
|
const badges = []; |
34 |
|
|
35 |
|
if (user.flags?.has(FLAGS.BUGHUNTER_LEVEL_1)) |
36 |
|
badges.push('Bughunter Level 1'); |
37 |
|
if (user.flags?.has(FLAGS.BUGHUNTER_LEVEL_2)) |
38 |
|
badges.push('Bughunter Level 2'); |
39 |
|
if (user.flags?.has(FLAGS.DISCORD_CERTIFIED_MODERATOR)) |
40 |
|
badges.push('Discord Certified Moderator'); |
41 |
|
if (user.flags?.has(FLAGS.DISCORD_EMPLOYEE)) |
42 |
|
badges.push('Discord Staff'); |
43 |
|
if (user.flags?.has(FLAGS.EARLY_SUPPORTER)) |
44 |
|
badges.push('Early Nitro Supporter'); |
45 |
|
if (user.flags?.has(FLAGS.EARLY_VERIFIED_BOT_DEVELOPER)) |
46 |
|
badges.push('Early Verified Bot Developer'); |
47 |
|
if (user.flags?.has(FLAGS.HOUSE_BALANCE)) |
48 |
|
badges.push('HypeSquad Balance'); |
49 |
|
if (user.flags?.has(FLAGS.HOUSE_BRILLIANCE)) |
50 |
|
badges.push('HypeSquad Brilliance'); |
51 |
|
if (user.flags?.has(FLAGS.HOUSE_BRAVERY)) |
52 |
|
badges.push('HypeSquad Bravery'); |
53 |
|
if (user.flags?.has(FLAGS.HYPESQUAD_EVENTS)) |
54 |
|
badges.push('HypeSquad Events'); |
55 |
|
if (user.flags?.has(FLAGS.PARTNERED_SERVER_OWNER)) |
56 |
|
badges.push('Partnered Server Owner'); |
57 |
|
if (user.flags?.has(FLAGS.BOT_HTTP_INTERACTIONS)) |
58 |
|
badges.push('Supports Interactions'); |
59 |
|
if (user.flags?.has(FLAGS.VERIFIED_BOT)) |
60 |
|
badges.push('Verified Bot'); |
61 |
|
|
62 |
|
return badges.map(b => `🔵 ${b}`); |
63 |
|
}; |
64 |
|
|
65 |
export default class ProfileCommand extends BaseCommand { |
export default class ProfileCommand extends BaseCommand { |
66 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
67 |
|
|
129 |
console.log(a); |
console.log(a); |
130 |
|
|
131 |
if (a.type === 'CUSTOM') { |
if (a.type === 'CUSTOM') { |
132 |
activities.push(`${a.emoji?.toString()} ${a.state}`); |
activities.push(`${a.emoji ? `${a.emoji.toString()} ` : ''}${a.state}`); |
133 |
} |
} |
134 |
else if (a.type === 'LISTENING') { |
else if (a.type === 'LISTENING') { |
135 |
if (a.name === 'Spotify') { |
if (a.name === 'Spotify') { |
156 |
|
|
157 |
activities = activities.join('\n'); |
activities = activities.join('\n'); |
158 |
|
|
159 |
const { FLAGS } = UserFlags; |
const allRoles = [...user!.roles.cache.values()].filter(role => role.id !== msg.guild!.id).sort((role1, role2) => { |
160 |
|
return role2.position - role1.position; |
161 |
const getUserBadges = (user: User) => { |
}); |
162 |
const badges = []; |
const limit = 10; |
163 |
|
const roles = (allRoles.length > limit ? allRoles.slice(0, limit) : allRoles).reduce((acc, value) => `${acc} ${roleMention(value.id)}`, '')!.trim()!; |
|
if (user.flags?.has(FLAGS.BUGHUNTER_LEVEL_1)) |
|
|
badges.push('Bughunter Level 1'); |
|
|
if (user.flags?.has(FLAGS.BUGHUNTER_LEVEL_2)) |
|
|
badges.push('Bughunter Level 2'); |
|
|
if (user.flags?.has(FLAGS.DISCORD_CERTIFIED_MODERATOR)) |
|
|
badges.push('Discord Certified Moderator'); |
|
|
if (user.flags?.has(FLAGS.DISCORD_EMPLOYEE)) |
|
|
badges.push('Discord Staff'); |
|
|
if (user.flags?.has(FLAGS.EARLY_SUPPORTER)) |
|
|
badges.push('Early Nitro Supporter'); |
|
|
if (user.flags?.has(FLAGS.EARLY_VERIFIED_BOT_DEVELOPER)) |
|
|
badges.push('Early Verified Bot Developer'); |
|
|
if (user.flags?.has(FLAGS.HOUSE_BALANCE)) |
|
|
badges.push('HypeSquad Balance'); |
|
|
if (user.flags?.has(FLAGS.HOUSE_BRILLIANCE)) |
|
|
badges.push('HypeSquad Brilliance'); |
|
|
if (user.flags?.has(FLAGS.HOUSE_BRAVERY)) |
|
|
badges.push('HypeSquad Bravery'); |
|
|
if (user.flags?.has(FLAGS.HYPESQUAD_EVENTS)) |
|
|
badges.push('HypeSquad Events'); |
|
|
if (user.flags?.has(FLAGS.PARTNERED_SERVER_OWNER)) |
|
|
badges.push('Partnered Server Owner'); |
|
|
if (user.flags?.has(FLAGS.BOT_HTTP_INTERACTIONS)) |
|
|
badges.push('Supports Interactions'); |
|
|
if (user.flags?.has(FLAGS.VERIFIED_BOT)) |
|
|
badges.push('Verified Bot'); |
|
|
|
|
|
return badges.map(b => `🔵 ${b}`); |
|
|
}; |
|
|
|
|
164 |
const fields = [ |
const fields = [ |
165 |
{ |
{ |
166 |
name: "Nickname", |
name: "Nickname", |
184 |
}, |
}, |
185 |
{ |
{ |
186 |
name: 'Roles', |
name: 'Roles', |
187 |
value: user?.roles.cache.filter(role => role.id !== msg.guild!.id).sort((role1, role2) => { |
value: roles === '' ? '*No roles assigned*' : `${roles} ${allRoles.length > limit ? `**+ ${allRoles.length - limit} More**` : ''}` |
|
return role2.position - role1.position; |
|
|
}).reduce((acc, value) => `${acc} ${roleMention(value.id)}`, '')!.trim()! |
|
188 |
} |
} |
189 |
]; |
]; |
190 |
|
|
197 |
}); |
}); |
198 |
} |
} |
199 |
|
|
200 |
|
let banner: string | undefined; |
201 |
|
|
202 |
|
try { |
203 |
|
await user?.user.fetch(true); |
204 |
|
banner = user!.user!.bannerURL({ size: 4096 }) ?? undefined; |
205 |
|
} |
206 |
|
catch (e) { |
207 |
|
console.log(e); |
208 |
|
} |
209 |
|
|
210 |
|
console.log("Banner", banner, user!.user!.banner); |
211 |
|
|
212 |
await msg.reply({ |
await msg.reply({ |
213 |
embeds: [ |
embeds: [ |
214 |
new MessageEmbed() |
new MessageEmbed({ |
215 |
|
image: { |
216 |
|
url: banner, |
217 |
|
} |
218 |
|
}) |
219 |
.setColor(user!.user!.hexAccentColor ? user!.user!.hexAccentColor! : '#007bff') |
.setColor(user!.user!.hexAccentColor ? user!.user!.hexAccentColor! : '#007bff') |
220 |
.setAuthor({ |
.setAuthor({ |
221 |
name: user?.user.tag!, |
name: user?.user.tag!, |
226 |
})) |
})) |
227 |
.setFields(fields) |
.setFields(fields) |
228 |
.setFooter({ |
.setFooter({ |
229 |
text: `${user!.id} - ${user?.user.bot ? 'Bot' : 'User'}` |
text: `${user?.user.bot ? 'Bot' : 'User'} • ${user!.id}` |
230 |
}) |
}) |
231 |
] |
] |
232 |
}); |
}); |