Compare commits

...

8 commits

Author SHA1 Message Date
vishnyanetchereshnya
c2d22c5f2e
Merge 565ad7c98c into b875ebf92d 2024-09-19 12:14:22 +00:00
Nuckyz
b875ebf92d
UserVoiceShow: Fix setting name
Some checks are pending
Sync to Codeberg / codeberg (push) Waiting to run
test / test (push) Waiting to run
2024-09-19 08:48:56 -03:00
vishnyanetchereshnya
565ad7c98c
Merge branch 'dev' into CopyEmojiMarkdown 2024-06-13 18:48:43 +03:00
vishnyanetchereshnya
dff95acdc7
Merge branch 'dev' into CopyEmojiMarkdown 2024-06-12 16:42:52 +03:00
vishnyanetchereshnya
79ecbe9bcf
Merge branch 'dev' into CopyEmojiMarkdown 2024-06-12 01:16:00 +03:00
vishnyanetchereshnya
2e454846ab
Merge branch 'dev' into CopyEmojiMarkdown 2024-06-09 20:24:59 +03:00
vishnyanetchereshnya
69d77598bf
bugfix 2024-06-09 20:17:06 +03:00
vishnyanetchereshnya
3c6e570033
added feature to copy emojies from messages and message reactions 2024-06-09 20:13:01 +03:00
4 changed files with 138 additions and 27 deletions

View file

@ -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,
},
});

View file

@ -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 ?

View file

@ -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} />);
}
},

View file

@ -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;
}