This commit is contained in:
thororen1234 2024-06-01 14:32:22 -04:00
parent 268e053d68
commit 7da91d94d8
77 changed files with 3175 additions and 1964 deletions

View file

@ -8,14 +8,16 @@ import { addDecoration, removeDecoration } from "@api/MessageDecorations";
import { Devs, EquicordDevs } from "@utils/constants";
import { isEquicordPluginDev, isPluginDev } from "@utils/misc";
import definePlugin from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import badges from "plugins/_api/badges";
const roleIconClassName = findByPropsLazy("roleIcon", "separator").roleIcon;
const RoleIconComponent = findComponentByCodeLazy(".Messages.ROLE_ICON_ALT_TEXT");
import "./styles.css";
import { User } from "discord-types/general";
import badges from "../../plugins/_api/badges";
import settings from "./settings";
let RoleIconComponent: React.ComponentType<any> = () => null;
let roleIconClassName: string;
const discordBadges: readonly [number, string, string][] = Object.freeze([
[0, "Discord Staff", "5e74e9b61934fc1f67c65515d1f7e60d"],
[1, "Partnered Server Owner", "3f9748e53446a137a052f3454e2de41e"],
@ -31,7 +33,8 @@ const discordBadges: readonly [number, string, string][] = Object.freeze([
[18, "Moderator Programs Alumni", "fee1624003e2fee35cb398e125dc479b"]
]);
function CheckBadge({ badge, author }: { badge: string; author: any; }): JSX.Element | null {
function CheckBadge({ badge, author }: { badge: string; author: User; }): JSX.Element | null {
switch (badge) {
case "EquicordDonor":
return (
@ -51,7 +54,7 @@ function CheckBadge({ badge, author }: { badge: string; author: any; }): JSX.Ele
<span style={{ order: settings.store.EquicordContributorPosition }}>
<RoleIconComponent
className={roleIconClassName}
name={"Equicord Contributor"}
name="Equicord Contributor"
size={20}
src={"https://i.imgur.com/UpcDwX0.png"}
/>
@ -60,7 +63,7 @@ function CheckBadge({ badge, author }: { badge: string; author: any; }): JSX.Ele
case "VencordDonor":
return (
<span style={{ order: settings.store.VencordDonorPosition }}>
{badges.getDonorBadges(author.id)?.map((badge: any) => (
{badges.getDonorBadges(author.id)?.map(badge => (
<RoleIconComponent
className={roleIconClassName}
name={badge.description}
@ -75,7 +78,7 @@ function CheckBadge({ badge, author }: { badge: string; author: any; }): JSX.Ele
<span style={{ order: settings.store.VencordContributorPosition }}>
<RoleIconComponent
className={roleIconClassName}
name={"Vencord Contributor"}
name="Vencord Contributor"
size={20}
src={"https://vencord.dev/assets/favicon.png"}
/>
@ -83,8 +86,9 @@ function CheckBadge({ badge, author }: { badge: string; author: any; }): JSX.Ele
) : null;
case "DiscordProfile":
const chatBadges = discordBadges
.filter((badge: any) => (author.flags || author.publicFlags) & (1 << badge[0]))
.map((badge: any) => (
.filter(badge => (author.flags || author.publicFlags) & (1 << badge[0]))
.map(badge => (
<RoleIconComponent
className={roleIconClassName}
name={badge[1]}
@ -98,7 +102,7 @@ function CheckBadge({ badge, author }: { badge: string; author: any; }): JSX.Ele
</span>
) : null;
case "DiscordNitro":
return author.premiumType > 0 ? (
return (author?.premiumType ?? 0) > 0 ? (
<span style={{ order: settings.store.DiscordNitroPosition }}>
<RoleIconComponent
className={roleIconClassName}
@ -116,9 +120,10 @@ function CheckBadge({ badge, author }: { badge: string; author: any; }): JSX.Ele
}
}
function ChatBadges({ author }: any) {
function ChatBadges({ author }: { author: User; }) {
return (
<span style={{ display: "inline-flex", marginLeft: 2, verticalAlign: "top" }}>
<span className="vc-sbic-badge-row">
{settings.store.showEquicordDonor && <CheckBadge badge={"EquicordDonor"} author={author} />}
{settings.store.showEquicordContributor && <CheckBadge badge={"EquicordContributer"} author={author} />}
{settings.store.showVencordDonor && <CheckBadge badge={"VencordDonor"} author={author} />}
@ -134,22 +139,9 @@ export default definePlugin({
authors: [Devs.Inbestigator, EquicordDevs.KrystalSkull],
description: "Shows the message author's badges beside their name in chat.",
dependencies: ["MessageDecorationsAPI"],
patches: [
{
find: "Messages.ROLE_ICON_ALT_TEXT",
replacement: {
match: /function\s+\w+?\(\w+?\)\s*{let\s+\w+?,\s*{className:.+}\)}/,
replace: "$self.RoleIconComponent=$&;$&",
}
}
],
settings,
set RoleIconComponent(component: any) {
RoleIconComponent = component;
},
start: () => {
roleIconClassName = findByPropsLazy("roleIcon", "separator").roleIcon;
addDecoration("vc-show-badges-in-chat", props => <ChatBadges author={props.message?.author} />);
addDecoration("vc-show-badges-in-chat", props => props.message?.author ? <ChatBadges author={props.message.author} /> : null);
},
stop: () => {
removeDecoration("vc-show-badges-in-chat");

View file

@ -4,8 +4,6 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import "./styles.css";
import { definePluginSettings } from "@api/Settings";
import { OptionType } from "@utils/types";
import { Text, useEffect, UserStore, useState } from "@webpack/common";
@ -37,7 +35,7 @@ const settings = definePluginSettings({
},
showVencordDonor: {
type: OptionType.BOOLEAN,
description: "Enable to show Vencord Donor badges in chat.",
description: "Enable to show Vencord donor badges in chat.",
hidden: true,
default: true
},
@ -49,7 +47,7 @@ const settings = definePluginSettings({
},
showVencordContributor: {
type: OptionType.BOOLEAN,
description: "Enable to show Vencord Contributor badges in chat.",
description: "Enable to show Vencord contributor badges in chat.",
hidden: true,
default: true
},
@ -171,22 +169,21 @@ const BadgeSettings = () => {
return (
<>
<Text>Drag the badges to reorder them, you can click to enable/disable a specific badge type.</Text>
<div className="badge-settings">
<img style={{ width: "55px", height: "55px", borderRadius: "50%", marginRight: "15px" }} src={UserStore.getCurrentUser().getAvatarURL()}></img>
<Text style={{ fontSize: "22px", color: "white", marginRight: "7.5px" }}>{(UserStore.getCurrentUser() as any).globalName}</Text>
<div className="vc-sbic-badge-settings">
<img className="vc-sbic-settings-avatar" src={UserStore.getCurrentUser().getAvatarURL()}></img>
<Text className="vc-sbic-settings-username">{(UserStore.getCurrentUser() as any).globalName}</Text>
{images
.sort((a, b) => a.position - b.position)
.map((image, index) => (
<div
key={image.key}
className={`image-container ${!image.shown ? "disabled" : ""}`}
className={`vc-sbic-image-container ${!image.shown ? "vc-sbic-disabled" : ""}`}
onDragOver={e => handleDragOver(e)}
onDrop={e => handleDrop(e, index)}
onClick={() => toggleDisable(index)}
>
<img
src={image.src}
alt={image.title}
draggable={image.shown}
onDragStart={e => handleDragStart(e, index)}
title={image.title}

View file

@ -1,21 +1,40 @@
.badge-settings {
.vc-sbic-badge-settings {
display: flex;
gap: 5px;
flex-direction: row;
}
.image-container {
.vc-sbic-image-container {
position: relative;
transition: 0.15s;
}
.image-container img {
.vc-sbic-image-container img {
width: 25px;
height: 25px;
cursor: pointer;
}
.disabled {
.vc-sbic-disabled {
opacity: 0.5;
scale: 0.95;
}
.vc-sbic-settings-avatar {
width: 50px;
height: 50px;
border-radius: 50%;
margin-right: 12px;
}
.vc-sbic-settings-username {
font-size: 22px;
color: white;
margin-right: 5px;
}
.vc-sbic-badge-row {
display: inline-flex;
margin-left: 2;
vertical-align: top;
}