mirror of
https://github.com/Vendicated/Vencord.git
synced 2024-09-20 06:30:35 +00:00
Compare commits
8 commits
c929fd72dd
...
c2d22c5f2e
Author | SHA1 | Date | |
---|---|---|---|
|
c2d22c5f2e | ||
|
b875ebf92d | ||
|
565ad7c98c | ||
|
dff95acdc7 | ||
|
79ecbe9bcf | ||
|
2e454846ab | ||
|
69d77598bf | ||
|
3c6e570033 |
4 changed files with 138 additions and 27 deletions
|
@ -4,14 +4,18 @@
|
|||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { findGroupChildrenByChildId } from "@api/ContextMenu";
|
||||
import { definePluginSettings } from "@api/Settings";
|
||||
import { Devs } from "@utils/constants";
|
||||
import { copyWithToast } from "@utils/misc";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
import { Menu } from "@webpack/common";
|
||||
import { Message } from "discord-types/general";
|
||||
import { ReactElement } from "react";
|
||||
|
||||
const { convertNameToSurrogate } = findByPropsLazy("convertNameToSurrogate");
|
||||
const { convertNameToSurrogate, hasSurrogates, convertSurrogateToName } =
|
||||
findByPropsLazy("convertNameToSurrogate");
|
||||
|
||||
interface Emoji {
|
||||
type: string;
|
||||
|
@ -37,39 +41,141 @@ function getEmojiMarkdown(target: Target, copyUnicode: boolean): string {
|
|||
/https:\/\/cdn\.discordapp\.com\/emojis\/\d+\.(\w+)/
|
||||
)?.[1];
|
||||
|
||||
return `<${extension === "gif" ? "a" : ""}:${emojiName.replace(/~\d+$/, "")}:${emojiId}>`;
|
||||
return `<${extension === "gif" ? "a" : ""}:${emojiName.replace(
|
||||
/~\d+$/,
|
||||
""
|
||||
)}:${emojiId}>`;
|
||||
}
|
||||
|
||||
const patchExpressionPickerContextMenu = (
|
||||
children: Array<ReactElement | null>,
|
||||
{ target }: { target: Target }
|
||||
) => {
|
||||
if (target.dataset.type !== "emoji") return;
|
||||
|
||||
children.push(
|
||||
<Menu.MenuItem
|
||||
id="vc-copy-emoji-markdown"
|
||||
label="Copy Emoji Markdown"
|
||||
action={() => {
|
||||
copyWithToast(
|
||||
getEmojiMarkdown(target, settings.store.copyUnicode),
|
||||
"Success! Copied emoji markdown."
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const addCopyButton = (
|
||||
children: Array<ReactElement | null>,
|
||||
emojiMarkdown: string
|
||||
) => {
|
||||
findGroupChildrenByChildId("copy-link", children)?.push(
|
||||
<Menu.MenuItem
|
||||
id="vc-copy-emoji-markdown"
|
||||
label="Copy Emoji Markdown"
|
||||
action={() => {
|
||||
copyWithToast(emojiMarkdown, "Success! Copied emoji markdown.");
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const patchMessageContextMenu = (
|
||||
children: Array<ReactElement | null>,
|
||||
props: {
|
||||
favoriteableId: string | null;
|
||||
favoriteableName: string | null;
|
||||
favoriteableType: string | null;
|
||||
message: Message;
|
||||
} | null
|
||||
) => {
|
||||
if (!props) return;
|
||||
|
||||
if (props.favoriteableType !== "emoji") return;
|
||||
|
||||
const emojiName = props.favoriteableName;
|
||||
|
||||
if (hasSurrogates(emojiName)) {
|
||||
addCopyButton(
|
||||
children,
|
||||
settings.store.copyUnicode
|
||||
? emojiName
|
||||
: convertSurrogateToName(emojiName)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const emojiId = props.favoriteableId;
|
||||
|
||||
if (!emojiId) {
|
||||
if (emojiName) {
|
||||
const emojiMarkdown = settings.store.copyUnicode
|
||||
? convertNameToSurrogate(emojiName.replace(/(^:|:$)/g, ""))
|
||||
: emojiName;
|
||||
|
||||
addCopyButton(
|
||||
children,
|
||||
emojiMarkdown !== "" ? emojiMarkdown : emojiName
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const messageEmojiMarkdown = props.message.content.match(
|
||||
RegExp(`(<a?:\\S+:${emojiId}>)`)
|
||||
)?.[1];
|
||||
|
||||
if (messageEmojiMarkdown) {
|
||||
addCopyButton(children, messageEmojiMarkdown.replace(/~\d+/, ""));
|
||||
return;
|
||||
}
|
||||
|
||||
const reactionEmojiObject = props.message.reactions.find(
|
||||
({ emoji: { id } }) => id === emojiId
|
||||
)?.emoji;
|
||||
|
||||
if (!reactionEmojiObject) return;
|
||||
|
||||
const reactionEmojiName = reactionEmojiObject.name;
|
||||
|
||||
if (hasSurrogates(reactionEmojiName)) {
|
||||
addCopyButton(
|
||||
children,
|
||||
settings.store.copyUnicode
|
||||
? reactionEmojiName
|
||||
: convertSurrogateToName(reactionEmojiName)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
addCopyButton(
|
||||
children,
|
||||
`<${
|
||||
reactionEmojiObject.animated ? "a" : ""
|
||||
}:${reactionEmojiName.replace(/~\d+$/, "")}:${emojiId}>`
|
||||
);
|
||||
};
|
||||
|
||||
const settings = definePluginSettings({
|
||||
copyUnicode: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Copy the raw unicode character instead of :name: for default emojis (👽)",
|
||||
description:
|
||||
"Copy the raw unicode character instead of :name: for default emojis (👽)",
|
||||
default: true,
|
||||
},
|
||||
});
|
||||
|
||||
export default definePlugin({
|
||||
name: "CopyEmojiMarkdown",
|
||||
description: "Allows you to copy emojis as formatted string (<:blobcatcozy:1026533070955872337>)",
|
||||
description:
|
||||
"Allows you to copy emojis as formatted string (<:blobcatcozy:1026533070955872337>)",
|
||||
authors: [Devs.HappyEnderman, Devs.Vishnya],
|
||||
settings,
|
||||
|
||||
contextMenus: {
|
||||
"expression-picker"(children, { target }: { target: Target }) {
|
||||
if (target.dataset.type !== "emoji") return;
|
||||
|
||||
children.push(
|
||||
<Menu.MenuItem
|
||||
id="vc-copy-emoji-markdown"
|
||||
label="Copy Emoji Markdown"
|
||||
action={() => {
|
||||
copyWithToast(
|
||||
getEmojiMarkdown(target, settings.store.copyUnicode),
|
||||
"Success! Copied emoji markdown."
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
"expression-picker": patchExpressionPickerContextMenu,
|
||||
"message": patchMessageContextMenu,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -103,7 +103,7 @@ function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
|
|||
<UserSummaryItem
|
||||
users={users}
|
||||
renderIcon={false}
|
||||
max={7}
|
||||
max={14}
|
||||
size={18}
|
||||
/>
|
||||
</div>
|
||||
|
@ -159,6 +159,7 @@ export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChanne
|
|||
<Tooltip
|
||||
text={<VoiceChannelTooltip channel={channel} />}
|
||||
tooltipClassName={cl("tooltip-container")}
|
||||
tooltipContentClassName={cl("tooltip-content")}
|
||||
>
|
||||
{props =>
|
||||
isLocked ?
|
||||
|
|
|
@ -32,7 +32,7 @@ const settings = definePluginSettings({
|
|||
default: true,
|
||||
restartNeeded: true
|
||||
},
|
||||
showInVoiceMemberList: {
|
||||
showInMemberList: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Show a user's Voice Channel indicator in the member and DMs list",
|
||||
default: true,
|
||||
|
@ -82,12 +82,12 @@ export default definePlugin({
|
|||
match: /\.subtext,children:.+?}\)\]}\)(?=])/,
|
||||
replace: "$&,$self.VoiceChannelIndicator({userId:arguments[0]?.user?.id})"
|
||||
},
|
||||
predicate: () => settings.store.showInVoiceMemberList
|
||||
predicate: () => settings.store.showInMemberList
|
||||
}
|
||||
],
|
||||
|
||||
start() {
|
||||
if (settings.store.showInVoiceMemberList) {
|
||||
if (settings.store.showInMemberList) {
|
||||
addDecorator("UserVoiceShow", ({ user }) => user == null ? null : <VoiceChannelIndicator userId={user.id} />);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -15,7 +15,13 @@
|
|||
}
|
||||
|
||||
.vc-uvs-tooltip-container {
|
||||
max-width: 200px;
|
||||
max-width: 300px;
|
||||
}
|
||||
|
||||
.vc-uvs-tooltip-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.vc-uvs-guild-name {
|
||||
|
@ -31,7 +37,5 @@
|
|||
|
||||
.vc-uvs-vc-members {
|
||||
display: flex;
|
||||
margin: 8px 0;
|
||||
flex-direction: row;
|
||||
gap: 6px;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue