mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-28 16:04:24 -04:00
Rework PronounDB -> UserMessagesPronouns
This commit is contained in:
parent
4e89352758
commit
58c3032bb2
10 changed files with 126 additions and 418 deletions
72
src/plugins/userMessagesPronouns/PronounsChatComponent.tsx
Normal file
72
src/plugins/userMessagesPronouns/PronounsChatComponent.tsx
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2022 Vendicated and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { getUserSettingLazy } from "@api/UserSettings";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { classes } from "@utils/misc";
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
import { i18n, Tooltip, UserStore } from "@webpack/common";
|
||||
import { Message } from "discord-types/general";
|
||||
|
||||
import { settings } from "./settings";
|
||||
import { useFormattedPronouns } from "./utils";
|
||||
|
||||
const styles: Record<string, string> = findByPropsLazy("timestampInline");
|
||||
const MessageDisplayCompact = getUserSettingLazy("textAndImages", "messageDisplayCompact")!;
|
||||
|
||||
const AUTO_MODERATION_ACTION = 24;
|
||||
|
||||
function shouldShow(message: Message): boolean {
|
||||
if (message.author.bot || message.author.system || message.type === AUTO_MODERATION_ACTION)
|
||||
return false;
|
||||
if (!settings.store.showSelf && message.author.id === UserStore.getCurrentUser().id)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function PronounsChatComponent({ message }: { message: Message; }) {
|
||||
const pronouns = useFormattedPronouns(message.author.id);
|
||||
|
||||
return pronouns && (
|
||||
<Tooltip text={i18n.Messages.USER_PROFILE_PRONOUNS}>
|
||||
{tooltipProps => (
|
||||
<span
|
||||
{...tooltipProps}
|
||||
className={classes(styles.timestampInline, styles.timestamp)}
|
||||
>• {pronouns}</span>
|
||||
)}
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
export const PronounsChatComponentWrapper = ErrorBoundary.wrap(({ message }: { message: Message; }) => {
|
||||
return shouldShow(message)
|
||||
? <PronounsChatComponent message={message} />
|
||||
: null;
|
||||
}, { noop: true });
|
||||
|
||||
export const CompactPronounsChatComponentWrapper = ErrorBoundary.wrap(({ message }: { message: Message; }) => {
|
||||
const compact = MessageDisplayCompact.useSetting();
|
||||
|
||||
if (!compact || !shouldShow(message)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <PronounsChatComponent message={message} />;
|
||||
}, { noop: true });
|
5
src/plugins/userMessagesPronouns/README.md
Normal file
5
src/plugins/userMessagesPronouns/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
User Messages Pronouns
|
||||
|
||||
Adds pronouns to chat user messages
|
||||
|
||||

|
54
src/plugins/userMessagesPronouns/index.ts
Normal file
54
src/plugins/userMessagesPronouns/index.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2022 Vendicated and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { migratePluginSettings } from "@api/Settings";
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin from "@utils/types";
|
||||
|
||||
import { CompactPronounsChatComponentWrapper, PronounsChatComponentWrapper } from "./PronounsChatComponent";
|
||||
import { settings } from "./settings";
|
||||
|
||||
migratePluginSettings("UserMessagesPronouns", "PronounDB");
|
||||
export default definePlugin({
|
||||
name: "UserMessagesPronouns",
|
||||
authors: [Devs.Tyman, Devs.TheKodeToad, Devs.Ven, Devs.Elvyra],
|
||||
description: "Adds pronouns to chat user messages",
|
||||
settings,
|
||||
|
||||
patches: [
|
||||
{
|
||||
find: "showCommunicationDisabledStyles",
|
||||
replacement: {
|
||||
// Add next to timestamp (normal mode)
|
||||
match: /(?<=return\s*\(0,\i\.jsxs?\)\(.+!\i&&)(\(0,\i.jsxs?\)\(.+?\{.+?\}\))/,
|
||||
replace: "[$1, $self.PronounsChatComponentWrapper(arguments[0])]"
|
||||
}
|
||||
},
|
||||
{
|
||||
find: '="SYSTEM_TAG"',
|
||||
replacement: {
|
||||
// Add next to username (compact mode)
|
||||
match: /className:\i\(\)\(\i\.className(?:,\i\.clickable)?,\i\)}\),(?=\i)/g,
|
||||
replace: "$&$self.CompactPronounsChatComponentWrapper(arguments[0]),"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
PronounsChatComponentWrapper,
|
||||
CompactPronounsChatComponentWrapper,
|
||||
});
|
48
src/plugins/userMessagesPronouns/settings.ts
Normal file
48
src/plugins/userMessagesPronouns/settings.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2023 Vendicated and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
import { OptionType } from "@utils/types";
|
||||
|
||||
export const enum PronounsFormat {
|
||||
Lowercase = "LOWERCASE",
|
||||
Capitalized = "CAPITALIZED"
|
||||
}
|
||||
|
||||
export const settings = definePluginSettings({
|
||||
pronounsFormat: {
|
||||
type: OptionType.SELECT,
|
||||
description: "The format for pronouns to appear in chat",
|
||||
options: [
|
||||
{
|
||||
label: "Lowercase",
|
||||
value: PronounsFormat.Lowercase,
|
||||
default: true
|
||||
},
|
||||
{
|
||||
label: "Capitalized",
|
||||
value: PronounsFormat.Capitalized
|
||||
}
|
||||
]
|
||||
},
|
||||
showSelf: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Enable or disable showing pronouns for yourself",
|
||||
default: true
|
||||
}
|
||||
});
|
35
src/plugins/userMessagesPronouns/utils.ts
Normal file
35
src/plugins/userMessagesPronouns/utils.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Vencord, a modification for Discord's desktop app
|
||||
* Copyright (c) 2022 Vendicated and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { getCurrentChannel } from "@utils/discord";
|
||||
import { UserProfileStore, useStateFromStores } from "@webpack/common";
|
||||
|
||||
import { PronounsFormat, settings } from "./settings";
|
||||
|
||||
function useDiscordPronouns(id: string, useGlobalProfile: boolean = false): string | undefined {
|
||||
const globalPronouns: string | undefined = useStateFromStores([UserProfileStore], () => UserProfileStore.getUserProfile(id)?.pronouns);
|
||||
const guildPronouns: string | undefined = useStateFromStores([UserProfileStore], () => UserProfileStore.getGuildMemberProfile(id, getCurrentChannel()?.getGuildId())?.pronouns);
|
||||
|
||||
if (useGlobalProfile) return globalPronouns;
|
||||
return guildPronouns || globalPronouns;
|
||||
}
|
||||
|
||||
export function useFormattedPronouns(id: string, useGlobalProfile: boolean = false) {
|
||||
const pronouns = useDiscordPronouns(id, useGlobalProfile)?.trim().replace(/\n+/g, "");
|
||||
return settings.store.pronounsFormat === PronounsFormat.Lowercase ? pronouns?.toLowerCase() : pronouns;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue