diff --git a/src/plugins/quickMention.tsx b/src/plugins/quickMention.tsx new file mode 100644 index 0000000..0f8410b --- /dev/null +++ b/src/plugins/quickMention.tsx @@ -0,0 +1,68 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import { Devs } from "../utils/constants"; +import { lazyWebpack } from "../utils/misc"; +import definePlugin from "../utils/types"; + +const ComponentDispatch = lazyWebpack(m => m.emitter?._events?.INSERT_TEXT); + +export default definePlugin({ + name: "QuickMention", + authors: [Devs.kemo], + description: "Adds a quick mention button to the message actions bar", + + patches: [ + { + find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL", + replacement: { + match: /(null,)(.{1,3}&&!.{1,3}\?(.{1,3})\(\{key:"reply",label:.{1,10}\.Messages\.MESSAGE_ACTION_REPLY,icon:.{1,10},channel:(.+?),message:(.+?),onClick:.+?\}\))/, + replace: (m, post, og, functionName, channelVar, messageVar) => { + + const functionSig = + `${functionName}({ + key: "QuickMention", + label: "Mention", + icon: Vencord.Plugins.plugins.QuickMention.Icon, + channel: ${channelVar}, + message: ${messageVar}, + onClick: ()=> Vencord.Plugins.plugins.QuickMention.onClick(${messageVar}) + })`; + + return `${post}${functionSig},${og}`; + } + } + } + ], + + Icon: () => ( + + + + ), + + onClick: (message: any) => ComponentDispatch.dispatchToLastSubscribed("INSERT_TEXT", { rawText: `<@${message.author.id}> ` }) +});