remove hang status and add channel statuses

This commit is contained in:
sadan 2024-09-15 21:42:52 -04:00
parent b3bf32abd7
commit 7d70d53083
No known key found for this signature in database

View file

@ -25,11 +25,16 @@ import { ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/moda
import definePlugin from "@utils/types";
import { findByCodeLazy, findStoreLazy } from "@webpack";
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";
const StickersStore = findStoreLazy("StickersStore");
const uploadEmoji = findByCodeLazy(".GUILD_EMOJIS(", "EMOJI_UPLOAD_START");
const ChannelStatusStore: {
getChannelStatus(c: Channel): string;
} = findStoreLazy("ChannelStatusStore");
interface Sticker {
t: "Sticker";
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 (
<Menu.MenuItem
id="emote-cloner"
id={`emote-cloner${label ?? ""}`}
key="emote-cloner"
label={`Clone ${type}`}
label={label ?? `Clone ${type}`}
action={() =>
openModalLazy(async () => {
const res = await fetchData();
@ -362,37 +367,46 @@ 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
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;
if (matches.length === 0) return;
children.push(buildMenuItem("Emoji", () => ({
id: matches[1],
isAnimated: (matches[2] === "gif"),
name: "ProfileEmoji"
})));
};
interface HangStatus {
emoji?: {
// used for unicode emojis and custom emojis
name: string
// used for custom emojis
id?: string,
animated?: boolean
}
}
const vcHangStatusContextPatch: NavContextMenuPatchCallback =(children, props: {
hangStatusActivity?: HangStatus
const emojiMatchRegex = /<(a?):(\w+):(\d{19})>/g;
const channelContextStatusPatch: NavContextMenuPatchCallback = (children, props: {
channel: Channel;
}) => {
if(props.hangStatusActivity?.emoji?.id){
const e = props.hangStatusActivity.emoji as Emoji;
e.isAnimated = props.hangStatusActivity.emoji.animated ?? false;
children.push(buildMenuItem("Emoji", () => {
return e;
}));
}
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({
name: "EmoteCloner",
description: "Allows you to clone Emotes & Stickers to your own server (right click them)",
@ -401,17 +415,7 @@ export default definePlugin({
contextMenus: {
"message": messageContextMenuPatch,
"expression-picker": expressionPickerPatch,
"user-context": vcHangStatusContextPatch,
"image-context": imageContextPatch,
"channel-context": channelContextStatusPatch
},
patches: [
// needed to pass the HangStatus to the context menu
{
find: "canWatchStream",
replacement: {
match: /Menu".*?\.\.\.\i,/,
replace: "$&hangStatusActivity:this.props.hangStatusActivity,"
}
}
],
});