From bc226719b4349aa05d23be30016ecfea76d73de8 Mon Sep 17 00:00:00 2001 From: slonkazoid Date: Sun, 15 Dec 2024 17:41:42 +0300 Subject: [PATCH] add rememeberReplyMention --- rememberReplyMention/index.tsx | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 rememberReplyMention/index.tsx diff --git a/rememberReplyMention/index.tsx b/rememberReplyMention/index.tsx new file mode 100644 index 0000000..719cf0c --- /dev/null +++ b/rememberReplyMention/index.tsx @@ -0,0 +1,63 @@ +import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import type { Message } from "discord-types/general"; + +const settings = definePluginSettings({}).withPrivateSettings<{ + users?: Record; +}>(); + +export default definePlugin({ + name: "RememberReplyMention", + description: "Remember whether to ping on reply for each user", + authors: [{ name: "slonkazoid", id: 276363003270791168n }], + settings, + + shouldMention(message: Message, isHoldingShift: boolean) { + if (settings.store.users === undefined) settings.store.users = {}; + let preference = settings.store.users[message.author.id]; + if (typeof preference !== "boolean") { + preference = !isHoldingShift; + settings.store.users[message.author.id] = preference; + } + console.log(message.author.id, preference); + return preference; + }, + + togglePing( + { + channelId, + shouldMention, + }: { + channelId: string; + shouldMention: boolean; + }, + replies: Record + ) { + console.log(arguments); + let reply = replies[channelId]; + if (reply === undefined) return; + let id = reply.message.author.id; + if (settings.store.users === undefined) settings.store.users = {}; + console.log("updated state for", id, shouldMention); + settings.store.users[id] = shouldMention; + }, + + patches: [ + { + find: ',"Message")}function', + replacement: { + match: /:(\i),shouldMention:!(\i)\.shiftKey/, + replace: + ":$1,shouldMention:$self.shouldMention($1,$2.shiftKey)", + }, + }, + { + find: "SET_PENDING_REPLY_SHOULD_MENTION:", + replacement: { + match: /(let{channelId:\i,shouldMention:\i}=(\i);\i in (\i)&&)/, + replace: "$self.togglePing($2, $3);$1", + }, + }, + ], +});