mirror of
https://github.com/Vendicated/Vencord.git
synced 2024-09-20 06:30:35 +00:00
Merge a88db90860
into 6cce8a8bc4
This commit is contained in:
commit
95fb0e114b
1 changed files with 55 additions and 6 deletions
|
@ -25,11 +25,16 @@ import { ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/moda
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
import { findByCodeLazy, findStoreLazy } from "@webpack";
|
import { findByCodeLazy, findStoreLazy } from "@webpack";
|
||||||
import { Constants, EmojiStore, FluxDispatcher, Forms, GuildStore, Menu, PermissionsBits, PermissionStore, React, RestAPI, Toasts, Tooltip, UserStore } from "@webpack/common";
|
import { Constants, EmojiStore, FluxDispatcher, Forms, GuildStore, Menu, PermissionsBits, PermissionStore, React, RestAPI, Toasts, Tooltip, UserStore } from "@webpack/common";
|
||||||
|
import { Channel } from "discord-types/general";
|
||||||
import { Promisable } from "type-fest";
|
import { Promisable } from "type-fest";
|
||||||
|
|
||||||
const StickersStore = findStoreLazy("StickersStore");
|
const StickersStore = findStoreLazy("StickersStore");
|
||||||
const uploadEmoji = findByCodeLazy(".GUILD_EMOJIS(", "EMOJI_UPLOAD_START");
|
const uploadEmoji = findByCodeLazy(".GUILD_EMOJIS(", "EMOJI_UPLOAD_START");
|
||||||
|
|
||||||
|
const ChannelStatusStore: {
|
||||||
|
getChannelStatus(c: Channel): string;
|
||||||
|
} = findStoreLazy("ChannelStatusStore");
|
||||||
|
|
||||||
interface Sticker {
|
interface Sticker {
|
||||||
t: "Sticker";
|
t: "Sticker";
|
||||||
description: string;
|
description: string;
|
||||||
|
@ -272,12 +277,12 @@ function CloneModal({ data }: { data: Sticker | Emoji; }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildMenuItem(type: "Emoji" | "Sticker", fetchData: () => Promisable<Omit<Sticker | Emoji, "t">>) {
|
function buildMenuItem(type: "Emoji" | "Sticker", fetchData: () => Promisable<Omit<Sticker | Emoji, "t">>, label?: string) {
|
||||||
return (
|
return (
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
id="emote-cloner"
|
id={`emote-cloner${label ?? ""}`}
|
||||||
key="emote-cloner"
|
key="emote-cloner"
|
||||||
label={`Clone ${type}`}
|
label={label ?? `Clone ${type}`}
|
||||||
action={() =>
|
action={() =>
|
||||||
openModalLazy(async () => {
|
openModalLazy(async () => {
|
||||||
const res = await fetchData();
|
const res = await fetchData();
|
||||||
|
@ -360,13 +365,57 @@ const expressionPickerPatch: NavContextMenuPatchCallback = (children, props: { t
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const emojiRegex = /https:\/\/cdn\.discordapp\.com\/emojis\/(\d+)\.([a-zA-Z]{3,4}).*/;
|
||||||
|
const imageContextPatch: NavContextMenuPatchCallback = (children, props: {
|
||||||
|
src: string;
|
||||||
|
}) => {
|
||||||
|
// this context menu is called on normal images, as well as stock emojis.
|
||||||
|
const matches = [...props.src.match(emojiRegex) ?? []];
|
||||||
|
if (matches.length === 0) return;
|
||||||
|
children.push(buildMenuItem("Emoji", () => ({
|
||||||
|
id: matches[1],
|
||||||
|
isAnimated: (matches[2] === "gif"),
|
||||||
|
name: "ProfileEmoji"
|
||||||
|
})));
|
||||||
|
};
|
||||||
|
|
||||||
|
const emojiMatchRegex = /<(a?):(\w+):(\d{19})>/g;
|
||||||
|
const channelContextStatusPatch: NavContextMenuPatchCallback = (children, props: {
|
||||||
|
channel: Channel;
|
||||||
|
}) => {
|
||||||
|
const status = ChannelStatusStore.getChannelStatus(props.channel);
|
||||||
|
|
||||||
|
if (!status) return;
|
||||||
|
|
||||||
|
const emojis = [...status.matchAll(emojiMatchRegex)];
|
||||||
|
if (emojis.length === 0) return;
|
||||||
|
console.log(emojis);
|
||||||
|
children.push((
|
||||||
|
<Menu.MenuItem id="vc-emoteCloner-item" label="Clone Emoji">
|
||||||
|
{
|
||||||
|
emojis.map(([_, animated, name, id]) => (
|
||||||
|
buildMenuItem("Emoji", () => ({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
isAnimated: !!animated,
|
||||||
|
}),
|
||||||
|
`Clone ${name}`
|
||||||
|
)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</Menu.MenuItem>
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "EmoteCloner",
|
name: "EmoteCloner",
|
||||||
description: "Allows you to clone Emotes & Stickers to your own server (right click them)",
|
description: "Allows you to clone Emotes & Stickers to your own server (right click them)",
|
||||||
tags: ["StickerCloner"],
|
tags: ["StickerCloner"],
|
||||||
authors: [Devs.Ven, Devs.Nuckyz],
|
authors: [Devs.Ven, Devs.Nuckyz, Devs.sadan],
|
||||||
contextMenus: {
|
contextMenus: {
|
||||||
"message": messageContextMenuPatch,
|
"message": messageContextMenuPatch,
|
||||||
"expression-picker": expressionPickerPatch
|
"expression-picker": expressionPickerPatch,
|
||||||
}
|
"image-context": imageContextPatch,
|
||||||
|
"channel-context": channelContextStatusPatch
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue