From 8cd85569e1cc8f12092d99ec4f791b8286b1e882 Mon Sep 17 00:00:00 2001 From: nin0dev Date: Thu, 11 Jul 2024 11:06:30 -0400 Subject: [PATCH] Added local emoji use --- index.tsx | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/index.tsx b/index.tsx index 5182e2e..16fcafa 100644 --- a/index.tsx +++ b/index.tsx @@ -20,9 +20,10 @@ import { addButton, removeButton } from "@api/MessagePopover"; import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; import { classes } from "@utils/misc"; import definePlugin, { OptionType } from "@utils/types"; -import { ChannelStore, RestAPI } from "@webpack/common"; +import { ChannelStore, EmojiStore, RestAPI } from "@webpack/common"; import type { SVGProps } from "react"; // eslint-disable-next-line no-duplicate-imports import { PropsWithChildren } from "react"; @@ -72,24 +73,35 @@ export function Husk(props: IconProps) { export default definePlugin({ name: "Husk", description: "Adds Husk button (check settings to change used emoji)", - authors: [{ - name: "nina", - id: 886685857560539176n - }], + authors: [Devs.nin0dev], dependencies: ["MessagePopoverAPI"], settings: definePluginSettings({ + findInServer: { + description: "Attempt to find emoji of same name in server before using ID in settings (useful if no nitro)", + type: OptionType.BOOLEAN, + default: true + }, emojiName: { - description: "Default (from Vencord Server): husk", + description: "Emoji name (default (from Vencord Server): husk)", type: OptionType.STRING, default: "husk" }, emojiID: { - description: "Default (from Vencord Server): 1026532993923293184", + description: "Emoji ID (default (from Vencord Server): 1026532993923293184)", type: OptionType.BIGINT, default: 1026532993923293184n } }), - + getEmojiIdThatShouldBeUsed(guildId: string) { + if (!this.settings.store.findInServer || guildId === "") return this.settings.store.emojiID; + let id = ""; + EmojiStore.getGuildEmoji(guildId).forEach(emoji => { + if (emoji.name === this.settings.store.emojiName) { + id = emoji.id; + } + }); + return id !== "" ? id : this.settings.store.emojiID; + }, async start() { addButton("Husk", msg => { return { @@ -98,8 +110,9 @@ export default definePlugin({ message: msg, channel: ChannelStore.getChannel(msg.channel_id), onClick: () => { + const guildId = ChannelStore.getChannel(msg.channel_id).guild_id !== null ? ChannelStore.getChannel(msg.channel_id).guild_id : ""; RestAPI.put({ - url: `/channels/${msg.channel_id}/messages/${msg.id}/reactions/${this.settings.store.emojiName}:${this.settings.store.emojiID}/@me` + url: `/channels/${msg.channel_id}/messages/${msg.id}/reactions/${this.settings.store.emojiName}:${this.getEmojiIdThatShouldBeUsed(guildId)}/@me` } ); }