From e5e8b9ba0143608752577dc277ab5d340c99382a Mon Sep 17 00:00:00 2001 From: vishnyanetchereshnya <151846235+vishnyanetchereshnya@users.noreply.github.com> Date: Thu, 6 Jun 2024 02:40:02 +0300 Subject: [PATCH] new plugin CopyEmojiMarkdown ~ more easily copy emoji formatting (#2266) Co-authored-by: Happy enderman <66224387+happyendermangit@users.noreply.github.com> Co-authored-by: vee --- src/plugins/copyEmojiMarkdown/README.md | 5 ++ src/plugins/copyEmojiMarkdown/index.tsx | 75 +++++++++++++++++++++++++ src/utils/constants.ts | 8 +++ 3 files changed, 88 insertions(+) create mode 100644 src/plugins/copyEmojiMarkdown/README.md create mode 100644 src/plugins/copyEmojiMarkdown/index.tsx diff --git a/src/plugins/copyEmojiMarkdown/README.md b/src/plugins/copyEmojiMarkdown/README.md new file mode 100644 index 00000000..9e62e663 --- /dev/null +++ b/src/plugins/copyEmojiMarkdown/README.md @@ -0,0 +1,5 @@ +# CopyEmojiMarkdown + +Allows you to copy emojis as formatted string. Custom emojis will be copied as `<:trolley:1024751352028602449>`, default emojis as `🛒` + +![](https://github.com/Vendicated/Vencord/assets/45497981/417f345a-7031-4fe7-8e42-e238870cd547) diff --git a/src/plugins/copyEmojiMarkdown/index.tsx b/src/plugins/copyEmojiMarkdown/index.tsx new file mode 100644 index 00000000..a9c018a9 --- /dev/null +++ b/src/plugins/copyEmojiMarkdown/index.tsx @@ -0,0 +1,75 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +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"; + +const { convertNameToSurrogate } = findByPropsLazy("convertNameToSurrogate"); + +interface Emoji { + type: string; + id: string; + name: string; +} + +interface Target { + dataset: Emoji; + firstChild: HTMLImageElement; +} + +function getEmojiMarkdown(target: Target, copyUnicode: boolean): string { + const { id: emojiId, name: emojiName } = target.dataset; + + if (!emojiId) { + return copyUnicode + ? convertNameToSurrogate(emojiName) + : `:${emojiName}:`; + } + + const extension = target?.firstChild.src.match( + /https:\/\/cdn\.discordapp\.com\/emojis\/\d+\.(\w+)/ + )?.[1]; + + 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 }) { + if (target.dataset.type !== "emoji") return; + + children.push( + { + copyWithToast( + getEmojiMarkdown(target, settings.store.copyUnicode), + "Success! Copied emoji markdown." + ); + }} + /> + ); + }, + }, +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 4e342252..7f172395 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -442,6 +442,14 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "Elvyra", id: 708275751816003615n, }, + HappyEnderman: { + name: "Happy enderman", + id: 1083437693347827764n + }, + Vishnya: { + name: "Vishnya", + id: 282541644484575233n + }, Inbestigator: { name: "Inbestigator", id: 761777382041714690n