feat(plugin): onePingPerDM (#1757)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Dea 2023-10-02 23:53:14 +00:00 committed by GitHub
parent 8dd5eeead2
commit 9891791fa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 1 deletions

View file

@ -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

View file

@ -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;
},
});

View file

@ -374,7 +374,11 @@ export const Devs = /* #__PURE__*/ Object.freeze({
archeruwu: { archeruwu: {
name: "archer_uwu", name: "archer_uwu",
id: 160068695383736320n id: 160068695383736320n
} },
ProffDea: {
name: "ProffDea",
id: 609329952180928513n
},
} satisfies Record<string, Dev>); } satisfies Record<string, Dev>);
// iife so #__PURE__ works correctly // iife so #__PURE__ works correctly