diff options
author | Dea <dea-banana@riseup.net> | 2023-10-02 23:53:14 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-03 01:53:14 +0200 |
commit | 9891791fa76d25db5f312622b1a7d34a6c2734b8 (patch) | |
tree | cd0856042cb345f0f424a3677c8c7685ca42d4e0 | |
parent | 8dd5eeead2f4f48ec7dfa3dd812475e97b322146 (diff) | |
download | Vencord-9891791fa76d25db5f312622b1a7d34a6c2734b8.tar.gz Vencord-9891791fa76d25db5f312622b1a7d34a6c2734b8.tar.bz2 Vencord-9891791fa76d25db5f312622b1a7d34a6c2734b8.zip |
feat(plugin): onePingPerDM (#1757)
Co-authored-by: V <vendicated@riseup.net>
-rw-r--r-- | src/plugins/onePingPerDM/README.md | 7 | ||||
-rw-r--r-- | src/plugins/onePingPerDM/index.ts | 39 | ||||
-rw-r--r-- | src/utils/constants.ts | 6 |
3 files changed, 51 insertions, 1 deletions
diff --git a/src/plugins/onePingPerDM/README.md b/src/plugins/onePingPerDM/README.md new file mode 100644 index 0000000..43f89b7 --- /dev/null +++ b/src/plugins/onePingPerDM/README.md @@ -0,0 +1,7 @@ +# OnePingPerDM +If unread messages are sent by a user in DMs multiple times, you'll only receive one audio ping. Read the messages to reset the limit + +## Purpose +- Prevents ping audio spam in DMs +- Be able to distinguish more than one ping as multiple users +- Be less annoyed while gaming diff --git a/src/plugins/onePingPerDM/index.ts b/src/plugins/onePingPerDM/index.ts new file mode 100644 index 0000000..47502eb --- /dev/null +++ b/src/plugins/onePingPerDM/index.ts @@ -0,0 +1,39 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; +import { ChannelStore, ReadStateStore } from "@webpack/common"; +import { Message } from "discord-types/general"; + +const enum ChannelType { + DM = 1, + GROUP_DM = 3 +} + +export default definePlugin({ + name: "OnePingPerDM", + description: "If unread messages are sent by a user in DMs multiple times, you'll only receive one audio ping. Read the messages to reset the limit", + authors: [Devs.ProffDea], + patches: [{ + find: ".getDesktopType()===", + replacement: [{ + match: /if\((\i\.\i\.getDesktopType\(\)===\i\.\i\.NEVER)\){/, + replace: "if($1){if(!$self.isPrivateChannelRead(arguments[0]?.message))return;" + }, + { + match: /sound:(\i\?\i:void 0,volume:\i,onClick:)/, + replace: "sound:!$self.isPrivateChannelRead(arguments[0]?.message)?undefined:$1" + }] + }], + isPrivateChannelRead(message: Message) { + const channelType = ChannelStore.getChannel(message.channel_id)?.type; + if (channelType !== ChannelType.DM && channelType !== ChannelType.GROUP_DM) { + return false; + } + return ReadStateStore.getOldestUnreadMessageId(message.channel_id) === message.id; + }, +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 7264c40..e80298d 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -374,7 +374,11 @@ export const Devs = /* #__PURE__*/ Object.freeze({ archeruwu: { name: "archer_uwu", id: 160068695383736320n - } + }, + ProffDea: { + name: "ProffDea", + id: 609329952180928513n + }, } satisfies Record<string, Dev>); // iife so #__PURE__ works correctly |