diff --git a/src/plugins/onePingPerDM/README.md b/src/plugins/onePingPerDM/README.md new file mode 100644 index 000000000..43f89b72c --- /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 000000000..47502ebe8 --- /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 7264c40d9..e80298d13 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); // iife so #__PURE__ works correctly