aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2023-04-13 21:04:19 +0200
committerVendicated <vendicated@riseup.net>2023-04-13 21:04:19 +0200
commitc8817e805f9d0ea2b5cff370eb0c9e10b7a60f59 (patch)
treeba760e9e9ff56d214ab14c23a5002f283b3de5cd
parentc6f0d0763c1c1866aab55e32c4d1a1b8863c6b11 (diff)
downloadVencord-c8817e805f9d0ea2b5cff370eb0c9e10b7a60f59.tar.gz
Vencord-c8817e805f9d0ea2b5cff370eb0c9e10b7a60f59.tar.bz2
Vencord-c8817e805f9d0ea2b5cff370eb0c9e10b7a60f59.zip
Fix badges
-rw-r--r--src/api/Badges.ts15
-rw-r--r--src/plugins/apiBadges.tsx33
2 files changed, 28 insertions, 20 deletions
diff --git a/src/api/Badges.ts b/src/api/Badges.ts
index d4aabaf..9abaefe 100644
--- a/src/api/Badges.ts
+++ b/src/api/Badges.ts
@@ -29,11 +29,12 @@ export enum BadgePosition {
export interface ProfileBadge {
/** The tooltip to show on hover. Required for image badges */
- tooltip?: string;
+ description?: string;
/** Custom component for the badge (tooltip not included) */
component?: ComponentType<ProfileBadge & BadgeUserArgs>;
/** The custom image to use */
image?: string;
+ link?: string;
/** Action to perform when you click the badge */
onClick?(): void;
/** Should the user display this badge? */
@@ -69,17 +70,19 @@ export function removeBadge(badge: ProfileBadge) {
* Inject badges into the profile badges array.
* You probably don't need to use this.
*/
-export function inject(badgeArray: ProfileBadge[], args: BadgeUserArgs) {
+export function _getBadges(args: BadgeUserArgs) {
+ const badges = [] as ProfileBadge[];
for (const badge of Badges) {
if (!badge.shouldShow || badge.shouldShow(args)) {
badge.position === BadgePosition.START
- ? badgeArray.unshift({ ...badge, ...args })
- : badgeArray.push({ ...badge, ...args });
+ ? badges.unshift({ ...badge, ...args })
+ : badges.push({ ...badge, ...args });
}
}
- (Plugins.BadgeAPI as any).addDonorBadge(badgeArray, args.user.id);
+ const donorBadge = (Plugins.BadgeAPI as any).getDonorBadge(args.user.id);
+ if (donorBadge) badges.unshift(donorBadge);
- return badgeArray;
+ return badges;
}
export interface BadgeUserArgs {
diff --git a/src/plugins/apiBadges.tsx b/src/plugins/apiBadges.tsx
index 975a7d6..6167dd0 100644
--- a/src/plugins/apiBadges.tsx
+++ b/src/plugins/apiBadges.tsx
@@ -35,7 +35,7 @@ const CONTRIBUTOR_BADGE = "https://cdn.discordapp.com/attachments/10336802034336
const contributorIds: string[] = Object.values(Devs).map(d => d.id.toString());
const ContributorBadge: ProfileBadge = {
- tooltip: "Vencord Contributor",
+ description: "Vencord Contributor",
image: CONTRIBUTOR_BADGE,
position: BadgePosition.START,
props: {
@@ -45,10 +45,10 @@ const ContributorBadge: ProfileBadge = {
}
},
shouldShow: ({ user }) => contributorIds.includes(user.id),
- onClick: () => VencordNative.ipc.invoke(IpcEvents.OPEN_EXTERNAL, "https://github.com/Vendicated/Vencord")
+ link: "https://github.com/Vendicated/Vencord"
};
-const DonorBadges = {} as Record<string, Pick<ProfileBadge, "image" | "tooltip">>;
+const DonorBadges = {} as Record<string, Pick<ProfileBadge, "image" | "description">>;
export default definePlugin({
name: "BadgeAPI",
@@ -58,10 +58,10 @@ export default definePlugin({
patches: [
/* Patch the badges array */
{
- find: "Messages.PROFILE_USER_BADGES,",
+ find: "Messages.ACTIVE_DEVELOPER_BADGE_TOOLTIP",
replacement: {
- match: /&&((\i)\.push\({tooltip:\i\.\i\.Messages\.PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP\.format.+?;)(?:return\s\i;?})/,
- replace: (_, m, badgeArray) => `&&${m} return Vencord.Api.Badges.inject(${badgeArray}, arguments[0]);}`,
+ match: /(?<=void 0:)\i.getBadges\(\)/,
+ replace: "Vencord.Api.Badges._getBadges(arguments[0]).concat($&??[])",
}
},
/* Patch the badge list component on user profiles */
@@ -69,13 +69,18 @@ export default definePlugin({
find: "Messages.PROFILE_USER_BADGES,role:",
replacement: [
{
- match: /src:(\i)\[(\i)\.key\],/g,
- // <img src={badge.image ?? imageMap[badge.key]} {...badge.props} />
- replace: (_, imageMap, badge) => `src: ${badge}.image ?? ${imageMap}[${badge}.key], ...${badge}.props,`
+ // alt: "", aria-hidden: false, src: originalSrc
+ match: /alt:" ","aria-hidden":!0,src:(?=.{0,10}\b(\i)\.(?:icon|key))/g,
+ // ...badge.props, ..., src: badge.image ?? ...
+ replace: "...$1.props,$& $1.image??"
},
{
match: /children:function(?<=(\i)\.(?:tooltip|description),spacing:\d.+?)/g,
replace: "children:$1.component ? () => $self.renderBadgeComponent($1) : function"
+ },
+ {
+ match: /onClick:function(?=.{0,200}href:(\i)\.link)/,
+ replace: "onClick:$1.onClick??function"
}
]
}
@@ -95,15 +100,15 @@ export default definePlugin({
return;
}
for (const line of lines) {
- const [id, tooltip, image] = line.split(",");
- DonorBadges[id] = { image, tooltip };
+ const [id, description, image] = line.split(",");
+ DonorBadges[id] = { image, description };
}
},
- addDonorBadge(badges: ProfileBadge[], userId: string) {
+ getDonorBadge(userId: string) {
const badge = DonorBadges[userId];
if (badge) {
- badges.unshift({
+ return {
...badge,
position: BadgePosition.START,
props: {
@@ -167,7 +172,7 @@ export default definePlugin({
</ErrorBoundary>
));
},
- });
+ };
}
}
});