feat(NoAutoReplyMention): Inverse shift reply behaviour (#839)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Amsyar Rasyiq 2023-04-09 12:55:04 +08:00 committed by GitHub
parent 613fa9a57b
commit c4a3d25d37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 31 deletions

View file

@ -16,43 +16,43 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * 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 { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import type { Message } from "discord-types/general";
interface Reply { const settings = definePluginSettings({
message: { exemptList: {
author: { description:
id: string; "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({ export default definePlugin({
name: "NoReplyMention", name: "NoReplyMention",
description: "Disables reply pings by default", description: "Disables reply pings by default",
authors: [Devs.DustyAngel47, Devs.axyie], authors: [Devs.DustyAngel47, Devs.axyie, Devs.pylix],
options: { settings,
exemptList: {
description: shouldMention(message: Message, isHoldingShift: boolean) {
"List of users to exempt from this plugin (separated by commas)", const isExempt = settings.store.exemptList.includes(message.author.id);
type: OptionType.STRING, return settings.store.inverseShiftReply ? isHoldingShift !== isExempt : !isHoldingShift && isExempt;
default: "1234567890123445,1234567890123445",
},
},
shouldMention(reply: Reply) {
return Settings.plugins.NoReplyMention.exemptList.includes(
reply.message.author.id
);
}, },
patches: [ patches: [
{ {
find: "CREATE_PENDING_REPLY:function", find: ",\"Message\")}function",
replacement: { replacement: {
match: /CREATE_PENDING_REPLY:function\((.{1,2})\){/, match: /:(\i),shouldMention:!(\i)\.shiftKey/,
replace: replace: ":$1,shouldMention:$self.shouldMention($1,$2.shiftKey)"
"CREATE_PENDING_REPLY:function($1){$1.shouldMention=$self.shouldMention($1);", }
}, }
},
], ],
}); });

View file

@ -16,9 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * 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 { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack"; import { findByPropsLazy } from "@webpack";
import { ChannelStore, FluxDispatcher as Dispatcher, MessageStore, SelectedChannelStore, UserStore } from "@webpack/common"; import { ChannelStore, FluxDispatcher as Dispatcher, MessageStore, SelectedChannelStore, UserStore } from "@webpack/common";
import { Message } from "discord-types/general"; import { Message } from "discord-types/general";
@ -31,10 +31,33 @@ let editIdx = -1;
migratePluginSettings("QuickReply", "InteractionKeybinds"); 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({ export default definePlugin({
name: "QuickReply", 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", description: "Reply to (ctrl + up/down) and edit (ctrl + shift + up/down) messages via keybinds",
settings,
start() { start() {
Dispatcher.subscribe("DELETE_PENDING_REPLY", onDeletePendingReply); 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]; 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 // handle next/prev reply
function nextReply(isUp: boolean) { function nextReply(isUp: boolean) {
const message = getNextMessage(isUp, true); const message = getNextMessage(isUp, true);
@ -149,11 +180,12 @@ function nextReply(isUp: boolean) {
const channel = ChannelStore.getChannel(message.channel_id); const channel = ChannelStore.getChannel(message.channel_id);
const meId = UserStore.getCurrentUser().id; const meId = UserStore.getCurrentUser().id;
Dispatcher.dispatch({ Dispatcher.dispatch({
type: "CREATE_PENDING_REPLY", type: "CREATE_PENDING_REPLY",
channel, channel,
message, message,
shouldMention: true, shouldMention: shouldMention(),
showMentionToggle: channel.guild_id !== null && message.author.id !== meId, showMentionToggle: channel.guild_id !== null && message.author.id !== meId,
_isQuickReply: true _isQuickReply: true
}); });

View file

@ -253,5 +253,9 @@ export const Devs = /* #__PURE__*/ Object.freeze({
AutumnVN: { AutumnVN: {
name: "AutumnVN", name: "AutumnVN",
id: 393694671383166998n id: 393694671383166998n
},
pylix: {
name: "pylix",
id: 492949202121261067n
} }
}); });