From a7d9fdb1bfe42ac0abf488d7955cf5887cb1d135 Mon Sep 17 00:00:00 2001 From: AntonMacG Date: Sat, 11 Nov 2023 17:18:53 +0000 Subject: [PATCH] Added README.md Added index.ts Added MrDiamond to Devs --- src/plugins/replyPingControl/README.md | 10 +++++ src/plugins/replyPingControl/index.ts | 59 ++++++++++++++++++++++++++ src/utils/constants.ts | 4 ++ 3 files changed, 73 insertions(+) create mode 100644 src/plugins/replyPingControl/README.md create mode 100644 src/plugins/replyPingControl/index.ts diff --git a/src/plugins/replyPingControl/README.md b/src/plugins/replyPingControl/README.md new file mode 100644 index 000000000..1b28ef630 --- /dev/null +++ b/src/plugins/replyPingControl/README.md @@ -0,0 +1,10 @@ +# ReplyPingControl + +Overrides notification settings for received reply pings to either always notify, or never notify. + +## Settings +- **Enabled**: You will always be notified when someone replies to your messages, regardless of if the sender has reply pings enabled. +- **Disabled (Default)**: You will not receive notification pings for replies, regardless of if the sender has reply pings enabled. + +## License +This project is licensed under the GPL-3.0-or-later License - see file for details. diff --git a/src/plugins/replyPingControl/index.ts b/src/plugins/replyPingControl/index.ts new file mode 100644 index 000000000..67bd4578f --- /dev/null +++ b/src/plugins/replyPingControl/index.ts @@ -0,0 +1,59 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated, Mr Diamond, ant0n and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { MessageStore, UserStore } from "@webpack/common"; + +export const settings = definePluginSettings({ + alwaysPingOnReply: { + type: OptionType.BOOLEAN, + description: "Always get pinged when someone replies to your messages", + default: false, + } +}); + +export default definePlugin({ + name: "ReplyPingControl", + description: "Control whether to always or never get pinged on message replies", + authors: [Devs.ant0n, Devs.MrDiamond], + settings, + + patches: [ + { + find: "_channelMessages", + replacement: { + match: /receiveMessage\((\w+)\)\{/, + replace: "$&$self.modifyMentions($1);" + } + } + ], + + modifyMentions(message) { + const isReplyToCurrentUser = this.isReplyToCurrentUser(message); + if (settings.store.alwaysPingOnReply && isReplyToCurrentUser) { + + if (!message.mentions.some(mention => mention.id === UserStore.getCurrentUser().id)) { + message.mentions.push(this.getCurrentUserMention()); + } + } else if (!settings.store.alwaysPingOnReply && isReplyToCurrentUser) { + + message.mentions = message.mentions.filter(mention => mention.id !== UserStore.getCurrentUser().id); + } + }, + + isReplyToCurrentUser(message) { + if (!message.message_reference) return false; + const repliedMessage = MessageStore.getMessage(message.channel_id, message.message_reference.message_id); + return repliedMessage && repliedMessage.author.id === UserStore.getCurrentUser().id; + }, + + getCurrentUserMention() { + const currentUser = UserStore.getCurrentUser(); + return { id: currentUser.id, username: currentUser.username, discriminator: currentUser.discriminator }; + } +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 3db2e64f8..383c0e30a 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -383,6 +383,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "ant0n", id: 145224646868860928n }, + MrDiamond: { + name: "MrDiamond", + id: 523338295644782592n + } } satisfies Record); // iife so #__PURE__ works correctly