mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-19 03:17:02 -04:00
fix(plugins): PronounDB, ViewIcons, WebhookTags, NoBlockedMessages, BetterGifAltText, MessageAccessories
This commit is contained in:
parent
f3aba3edb0
commit
1176896a1b
10 changed files with 86 additions and 44 deletions
|
@ -20,27 +20,28 @@ import { useAwaiter } from "../../../utils/misc";
|
|||
import { Settings } from "../../../Vencord";
|
||||
import { UserStore } from "../../../webpack/common";
|
||||
import { fetchPronouns, formatPronouns } from "../pronoundbUtils";
|
||||
import { PronounMapping, UserProfileProps } from "../types";
|
||||
import { PronounMapping, UserProfilePronounsProps, UserProfileProps } from "../types";
|
||||
|
||||
export default function PronounsProfileWrapper(props: UserProfileProps, pronounsComponent: JSX.Element) {
|
||||
export default function PronounsProfileWrapper(PronounsComponent: React.ElementType<UserProfilePronounsProps>, props: UserProfilePronounsProps, profileProps: UserProfileProps) {
|
||||
const user = UserStore.getUser(profileProps.userId) ?? {};
|
||||
// Don't bother fetching bot or system users
|
||||
if (props.user.bot || props.user.system) return null;
|
||||
if (user.bot || user.system) return null;
|
||||
// Respect showSelf options
|
||||
if (!Settings.plugins.PronounDB.showSelf && props.user.id === UserStore.getCurrentUser().id) return null;
|
||||
if (!Settings.plugins.PronounDB.showSelf && user.id === UserStore.getCurrentUser().id)
|
||||
return null;
|
||||
|
||||
const [result, , isPending] = useAwaiter(
|
||||
() => fetchPronouns(props.user.id),
|
||||
() => fetchPronouns(user.id),
|
||||
null,
|
||||
e => console.error("Fetching pronouns failed: ", e)
|
||||
);
|
||||
|
||||
// If the promise completed, the result was not "unspecified", and there is a mapping for the code, then return a span with the pronouns
|
||||
// If the promise completed, the result was not "unspecified", and there is a mapping for the code, then render
|
||||
if (!isPending && result && result !== "unspecified" && PronounMapping[result]) {
|
||||
// First child is the header, second is a div with the actual text
|
||||
const [, pronounsBodyComponent] = pronounsComponent.props.children as [JSX.Element, JSX.Element];
|
||||
pronounsBodyComponent.props.children = formatPronouns(result);
|
||||
return pronounsComponent;
|
||||
props.currentPronouns ||= formatPronouns(result);
|
||||
return <PronounsComponent {...props} />;
|
||||
}
|
||||
// Otherwise, return null so nothing else is rendered
|
||||
else return null;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -44,13 +44,28 @@ export default definePlugin({
|
|||
},
|
||||
// Hijack the discord pronouns section (hidden without experiment) and add a wrapper around the text section
|
||||
{
|
||||
find: ".headerTagUsernameNoNickname",
|
||||
find: "currentPronouns:",
|
||||
all: true,
|
||||
replacement: {
|
||||
match: /(?<=""!==(.{1,2})&&).+?children:\1.+?(?=,)/,
|
||||
replace: "Vencord.Plugins.plugins.PronounDB.PronounsProfileWrapper(e, $1)"
|
||||
match: /\(0,.{1,3}\.jsxs?\)\((.{1,10}),(\{[^[}]*currentPronouns:[^}]*(\w)\.pronouns[^}]*\})\)/,
|
||||
replace: (original, PronounComponent, pronounProps, fullProps) => {
|
||||
// UserSettings
|
||||
if (fullProps.includes("onPronounsChange")) return original;
|
||||
|
||||
return `Vencord.Plugins.plugins.PronounDB.PronounsProfileWrapper(${PronounComponent}, ${pronounProps}, ${fullProps})`;
|
||||
}
|
||||
}
|
||||
},
|
||||
// Make pronouns experiment be enabled by default
|
||||
{
|
||||
find: "2022-01_pronouns",
|
||||
replacement: {
|
||||
match: "!1", // false
|
||||
replace: "!0"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
options: {
|
||||
pronounsFormat: {
|
||||
type: OptionType.SELECT,
|
||||
|
|
|
@ -16,15 +16,13 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { User } from "discord-types/general";
|
||||
|
||||
export interface UserProfileProps {
|
||||
customStatus: JSX.Element,
|
||||
displayProfile: {
|
||||
// In the future (if discord ever uses their pronouns system) this taking priority can be a plugin setting
|
||||
pronouns: string;
|
||||
};
|
||||
user: User;
|
||||
userId: string;
|
||||
}
|
||||
|
||||
export interface UserProfilePronounsProps {
|
||||
currentPronouns: string | null;
|
||||
hidePersonalInformation: boolean;
|
||||
}
|
||||
|
||||
export interface PronounsResponse {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue