From c4a3d25d37697282dce756d9addc36c23ba1f2ce Mon Sep 17 00:00:00 2001 From: Amsyar Rasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Sun, 9 Apr 2023 12:55:04 +0800 Subject: [PATCH] feat(NoAutoReplyMention): Inverse shift reply behaviour (#839) Co-authored-by: V --- src/plugins/noReplyMention.tsx | 54 +++++++++++++++++----------------- src/plugins/quickReply.ts | 40 ++++++++++++++++++++++--- src/utils/constants.ts | 4 +++ 3 files changed, 67 insertions(+), 31 deletions(-) diff --git a/src/plugins/noReplyMention.tsx b/src/plugins/noReplyMention.tsx index 2e975889..1351ec46 100644 --- a/src/plugins/noReplyMention.tsx +++ b/src/plugins/noReplyMention.tsx @@ -16,43 +16,43 @@ * along with this program. If not, see . */ -import { Settings } from "@api/settings"; +import { definePluginSettings } from "@api/settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; +import type { Message } from "discord-types/general"; -interface Reply { - message: { - author: { - id: string; - }; - }; -} +const settings = definePluginSettings({ + exemptList: { + description: + "List of users to exempt from this plugin (separated by commas or spaces)", + type: OptionType.STRING, + default: "1234567890123445,1234567890123445", + }, + inverseShiftReply: { + description: "Invert Discord's shift replying behaviour (enable to make shift reply mention user)", + type: OptionType.BOOLEAN, + default: false, + } +}); export default definePlugin({ name: "NoReplyMention", description: "Disables reply pings by default", - authors: [Devs.DustyAngel47, Devs.axyie], - options: { - exemptList: { - description: - "List of users to exempt from this plugin (separated by commas)", - type: OptionType.STRING, - default: "1234567890123445,1234567890123445", - }, - }, - shouldMention(reply: Reply) { - return Settings.plugins.NoReplyMention.exemptList.includes( - reply.message.author.id - ); + authors: [Devs.DustyAngel47, Devs.axyie, Devs.pylix], + settings, + + shouldMention(message: Message, isHoldingShift: boolean) { + const isExempt = settings.store.exemptList.includes(message.author.id); + return settings.store.inverseShiftReply ? isHoldingShift !== isExempt : !isHoldingShift && isExempt; }, + patches: [ { - find: "CREATE_PENDING_REPLY:function", + find: ",\"Message\")}function", replacement: { - match: /CREATE_PENDING_REPLY:function\((.{1,2})\){/, - replace: - "CREATE_PENDING_REPLY:function($1){$1.shouldMention=$self.shouldMention($1);", - }, - }, + match: /:(\i),shouldMention:!(\i)\.shiftKey/, + replace: ":$1,shouldMention:$self.shouldMention($1,$2.shiftKey)" + } + } ], }); diff --git a/src/plugins/quickReply.ts b/src/plugins/quickReply.ts index 984db188..d059b332 100644 --- a/src/plugins/quickReply.ts +++ b/src/plugins/quickReply.ts @@ -16,9 +16,9 @@ * along with this program. If not, see . */ -import { migratePluginSettings } from "@api/settings"; +import { definePluginSettings, migratePluginSettings, Settings } from "@api/settings"; import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; +import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy } from "@webpack"; import { ChannelStore, FluxDispatcher as Dispatcher, MessageStore, SelectedChannelStore, UserStore } from "@webpack/common"; import { Message } from "discord-types/general"; @@ -31,10 +31,33 @@ let editIdx = -1; migratePluginSettings("QuickReply", "InteractionKeybinds"); +const enum MentionOptions { + DISABLED, + ENABLED, + NO_REPLY_MENTION_PLUGIN +} + +const settings = definePluginSettings({ + shouldMention: { + type: OptionType.SELECT, + description: "Ping reply by default", + options: [ + { + label: "Follow NoReplyMention", + value: MentionOptions.NO_REPLY_MENTION_PLUGIN, + default: true + }, + { label: "Enabled", value: MentionOptions.ENABLED }, + { label: "Disabled", value: MentionOptions.DISABLED }, + ] + } +}); + export default definePlugin({ name: "QuickReply", - authors: [Devs.obscurity, Devs.Ven], + authors: [Devs.obscurity, Devs.Ven, Devs.pylix], description: "Reply to (ctrl + up/down) and edit (ctrl + shift + up/down) messages via keybinds", + settings, start() { Dispatcher.subscribe("DELETE_PENDING_REPLY", onDeletePendingReply); @@ -137,6 +160,14 @@ function getNextMessage(isUp: boolean, isReply: boolean) { return i === - 1 ? undefined : messages[messages.length - i - 1]; } +function shouldMention() { + switch (settings.store.shouldMention) { + case MentionOptions.NO_REPLY_MENTION_PLUGIN: return !Settings.plugins.NoReplyMention.enabled; + case MentionOptions.DISABLED: return false; + default: return true; + } +} + // handle next/prev reply function nextReply(isUp: boolean) { const message = getNextMessage(isUp, true); @@ -149,11 +180,12 @@ function nextReply(isUp: boolean) { const channel = ChannelStore.getChannel(message.channel_id); const meId = UserStore.getCurrentUser().id; + Dispatcher.dispatch({ type: "CREATE_PENDING_REPLY", channel, message, - shouldMention: true, + shouldMention: shouldMention(), showMentionToggle: channel.guild_id !== null && message.author.id !== meId, _isQuickReply: true }); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index edbd76d3..a5949932 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -253,5 +253,9 @@ export const Devs = /* #__PURE__*/ Object.freeze({ AutumnVN: { name: "AutumnVN", id: 393694671383166998n + }, + pylix: { + name: "pylix", + id: 492949202121261067n } });