mirror of
https://github.com/Vendicated/Vencord.git
synced 2024-09-20 06:30:35 +00:00
Compare commits
8 commits
c2d22c5f2e
...
c929fd72dd
Author | SHA1 | Date | |
---|---|---|---|
|
c929fd72dd | ||
|
a015cf96f6 | ||
|
565ad7c98c | ||
|
dff95acdc7 | ||
|
79ecbe9bcf | ||
|
2e454846ab | ||
|
69d77598bf | ||
|
3c6e570033 |
4 changed files with 154 additions and 49 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,25 +41,16 @@ 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 settings = definePluginSettings({
|
||||
copyUnicode: {
|
||||
type: OptionType.BOOLEAN,
|
||||
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>)",
|
||||
authors: [Devs.HappyEnderman, Devs.Vishnya],
|
||||
settings,
|
||||
|
||||
contextMenus: {
|
||||
"expression-picker"(children, { target }: { target: Target }) {
|
||||
const patchExpressionPickerContextMenu = (
|
||||
children: Array<ReactElement | null>,
|
||||
{ target }: { target: Target }
|
||||
) => {
|
||||
if (target.dataset.type !== "emoji") return;
|
||||
|
||||
children.push(
|
||||
|
@ -70,6 +65,117 @@ export default definePlugin({
|
|||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
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 (👽)",
|
||||
default: true,
|
||||
},
|
||||
});
|
||||
|
||||
export default definePlugin({
|
||||
name: "CopyEmojiMarkdown",
|
||||
description:
|
||||
"Allows you to copy emojis as formatted string (<:blobcatcozy:1026533070955872337>)",
|
||||
authors: [Devs.HappyEnderman, Devs.Vishnya],
|
||||
settings,
|
||||
|
||||
contextMenus: {
|
||||
"expression-picker": patchExpressionPickerContextMenu,
|
||||
"message": patchMessageContextMenu,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -8,7 +8,7 @@ import { classNameFactory } from "@api/Styles";
|
|||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { classes } from "@utils/misc";
|
||||
import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
|
||||
import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, showToast, Text, Toasts, Tooltip, useCallback, useMemo, UserStore, useStateFromStores } from "@webpack/common";
|
||||
import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, React, showToast, Text, Toasts, Tooltip, useMemo, UserStore, useStateFromStores } from "@webpack/common";
|
||||
import { Channel } from "discord-types/general";
|
||||
|
||||
const cl = classNameFactory("vc-uvs-");
|
||||
|
@ -17,7 +17,7 @@ const { selectVoiceChannel } = findByPropsLazy("selectChannel", "selectVoiceChan
|
|||
const VoiceStateStore = findStoreLazy("VoiceStateStore");
|
||||
const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers");
|
||||
|
||||
interface IconProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
interface IconProps extends React.ComponentPropsWithoutRef<"div"> {
|
||||
size?: number;
|
||||
}
|
||||
|
||||
|
@ -71,23 +71,18 @@ interface VoiceChannelTooltipProps {
|
|||
|
||||
function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
|
||||
const voiceStates = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStatesForChannel(channel.id));
|
||||
|
||||
const users = useMemo(
|
||||
() => Object.values<any>(voiceStates).map(voiceState => UserStore.getUser(voiceState.userId)).filter(user => user != null),
|
||||
[voiceStates]
|
||||
);
|
||||
|
||||
const guild = useMemo(
|
||||
() => channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId()),
|
||||
[channel]
|
||||
);
|
||||
|
||||
const guildIcon = useMemo(() => {
|
||||
return guild?.icon == null ? undefined : IconUtils.getGuildIconURL({
|
||||
const guild = channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId());
|
||||
const guildIcon = guild?.icon == null ? undefined : IconUtils.getGuildIconURL({
|
||||
id: guild.id,
|
||||
icon: guild.icon,
|
||||
size: 30
|
||||
});
|
||||
}, [guild]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -103,7 +98,7 @@ function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
|
|||
<UserSummaryItem
|
||||
users={users}
|
||||
renderIcon={false}
|
||||
max={7}
|
||||
max={13}
|
||||
size={18}
|
||||
/>
|
||||
</div>
|
||||
|
@ -119,11 +114,14 @@ const clickTimers = {} as Record<string, any>;
|
|||
|
||||
export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChannelIndicatorProps) => {
|
||||
const channelId = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStateForUser(userId)?.channelId as string | undefined);
|
||||
const channel = useMemo(() => channelId == null ? undefined : ChannelStore.getChannel(channelId), [channelId]);
|
||||
|
||||
const onClick = useCallback((e: React.MouseEvent) => {
|
||||
const channel = channelId == null ? undefined : ChannelStore.getChannel(channelId);
|
||||
if (channel == null) return null;
|
||||
|
||||
function onClick(e: React.MouseEvent) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
if (channel == null || channelId == null) return;
|
||||
|
||||
if (!PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel)) {
|
||||
|
@ -147,18 +145,15 @@ export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChanne
|
|||
delete clickTimers[channelId];
|
||||
}, 250);
|
||||
}
|
||||
}, [channelId]);
|
||||
}
|
||||
|
||||
const isLocked = useMemo(() => {
|
||||
return !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel);
|
||||
}, [channelId]);
|
||||
|
||||
if (channel == null) return null;
|
||||
const isLocked = !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel);
|
||||
|
||||
return (
|
||||
<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