/[sudobot]/branches/6.x/src/utils/user.ts
ViewVC logotype

Contents of /branches/6.x/src/utils/user.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 3422 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 /*
2 * This file is part of SudoBot.
3 *
4 * Copyright (C) 2021-2023 OSN Developers.
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 { GuildMember, TimestampStyles, User, UserFlags, time } from "discord.js";
21 import Client from "../core/Client";
22 import { getEmoji } from "./utils";
23
24 const map: Record<string, [string, string]> = {
25 BugHunterLevel1: ["bughunter", "Bughunter Level 1"],
26 BugHunterLevel2: ["golden_bughunter", "Bughunter Level 2"],
27 CertifiedModerator: ["certified_mod", "Discord Certified Moderator"],
28 Staff: ["discord_staff", "Discord Staff"],
29 PremiumEarlySupporter: ["early_supporter", "Early Nitro Supporter"],
30 VerifiedDeveloper: ["verified_bot_developer", "Early Verified Bot Developer"],
31 HypeSquadOnlineHouse1: ["bravery", "HypeSquad Bravery"],
32 HypeSquadOnlineHouse2: ["brilliance", "HypeSquad Brilliance"],
33 HypeSquadOnlineHouse3: ["balance", "HypeSquad Balance"],
34 Hypesquad: ["hypesquad_events", "HypeSquad Events"],
35 Partner: ["partnered_server_owner", "Partnered Server Owner"],
36 VerifiedBot: ["verified_bot", "Verified Bot"],
37 BotHTTPInteractions: ["supports_interactions", "Supports Interactions"],
38 ActiveDeveloper: ["active_developer", "Active Developer"]
39 };
40
41 export const getUserBadges = (client: Client, user: User) => {
42 const badges = [];
43
44 for (const flagString in map) {
45 const [emojiName, badgeTitle] = map[flagString];
46 const flag = UserFlags[flagString as keyof typeof UserFlags];
47
48 if (flag && user.flags?.has(flag)) {
49 const emoji = getEmoji(client, emojiName);
50 badges.push(`${emoji.toString()} ${badgeTitle}`);
51 }
52 }
53
54 if (user.discriminator === "0") {
55 badges.push(`${getEmoji(client, "new_username")} Has opted-in to the new username system`);
56 }
57
58 return badges;
59 };
60
61 export const getMemberBadges = (client: Client, member: GuildMember) => {
62 const badges = getUserBadges(client, member.user);
63
64 if (
65 member.premiumSinceTimestamp ||
66 client.guilds.cache.some(guild => !!guild.members.cache.get(member.id)?.premiumSinceTimestamp)
67 ) {
68 badges.push(`${getEmoji(client, "nitro")} Nitro Subscriber`);
69 }
70
71 let minPremiumSince = member.premiumSince;
72
73 for (const guild of client.guilds.cache.values()) {
74 const guildMember = guild.members.cache.get(member.id);
75
76 if (
77 guildMember &&
78 guildMember.premiumSince &&
79 (minPremiumSince?.getTime() ?? 0) > (guildMember.premiumSince?.getTime() ?? 0)
80 ) {
81 minPremiumSince = guildMember.premiumSince;
82 }
83 }
84
85 if (minPremiumSince) {
86 badges.push(`${getEmoji(client, "boost")} Server boosting since ${time(minPremiumSince, TimestampStyles.LongDate)}`);
87 }
88
89 return badges;
90 };

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26