feat(NoAutoReplyMention): Inverse shift reply behaviour (#839)
Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
		
							parent
							
								
									613fa9a57b
								
							
						
					
					
						commit
						c4a3d25d37
					
				
					 3 changed files with 67 additions and 31 deletions
				
			
		|  | @ -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)" | ||||
|             } | ||||
|         } | ||||
|     ], | ||||
| }); | ||||
|  |  | |||
|  | @ -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 | ||||
|     }); | ||||
|  |  | |||
|  | @ -253,5 +253,9 @@ export const Devs = /* #__PURE__*/ Object.freeze({ | |||
|     AutumnVN: { | ||||
|         name: "AutumnVN", | ||||
|         id: 393694671383166998n | ||||
|     }, | ||||
|     pylix: { | ||||
|         name: "pylix", | ||||
|         id: 492949202121261067n | ||||
|     } | ||||
| }); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue