diff options
author | Amsyar Rasyiq <82711525+amsyarasyiq@users.noreply.github.com> | 2023-04-09 12:55:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-09 06:55:04 +0200 |
commit | c4a3d25d37697282dce756d9addc36c23ba1f2ce (patch) | |
tree | c2d404fac3c07f83e81268c44fb0dd95b105a89e /src/plugins | |
parent | 613fa9a57b1fe7985e526a9c7281b9188f535463 (diff) | |
download | Vencord-c4a3d25d37697282dce756d9addc36c23ba1f2ce.tar.gz Vencord-c4a3d25d37697282dce756d9addc36c23ba1f2ce.tar.bz2 Vencord-c4a3d25d37697282dce756d9addc36c23ba1f2ce.zip |
feat(NoAutoReplyMention): Inverse shift reply behaviour (#839)
Co-authored-by: V <vendicated@riseup.net>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/noReplyMention.tsx | 54 | ||||
-rw-r--r-- | src/plugins/quickReply.ts | 40 |
2 files changed, 63 insertions, 31 deletions
diff --git a/src/plugins/noReplyMention.tsx b/src/plugins/noReplyMention.tsx index 2e97588..1351ec4 100644 --- a/src/plugins/noReplyMention.tsx +++ b/src/plugins/noReplyMention.tsx @@ -16,43 +16,43 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -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 984db18..d059b33 100644 --- a/src/plugins/quickReply.ts +++ b/src/plugins/quickReply.ts @@ -16,9 +16,9 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -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 }); |