import { definePluginSettings } from "@api/Settings"; import definePlugin 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; } return preference; }, togglePing( { channelId, shouldMention, }: { channelId: string; shouldMention: boolean; }, replies: Record ) { let reply = replies[channelId]; if (reply === undefined) return; let id = reply.message.author.id; if (settings.store.users === undefined) settings.store.users = {}; 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", }, }, ], });