Plugin
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
1
import { definePluginSettings } from "@api/Settings";2
import { Devs } from "@utils/constants";3
import definePlugin, { OptionType } from "@utils/types";4
import { MessageJSON } from "@vencord/discord-types";5
import { ChannelType } from "@vencord/discord-types/enums";6
import { ChannelStore, ReadStateStore, UserStore } from "@webpack/common";7
8
const settings = definePluginSettings({9
channelToAffect: {10
type: OptionType.SELECT,11
description: "Select the type of DM for the plugin to affect",12
options: [13
{ label: "Both", value: "both_dms", default: true },14
{ label: "User DMs", value: "user_dm" },15
{ label: "Group DMs", value: "group_dm" },16
]17
},18
allowMentions: {19
type: OptionType.BOOLEAN,20
description: "Receive audio pings for @mentions",21
default: false,22
},23
allowEveryone: {24
type: OptionType.BOOLEAN,25
description: "Receive audio pings for @everyone and @here in group DMs",26
default: false,27
},28
});29
30
export default definePlugin({31
name: "OnePingPerDM",32
description: "If unread messages are sent by a user in DMs multiple times, you039;ll only receive one audio ping. Read the messages to reset the limit",33
tags: ["Notifications", "Customisation"],34
authors: [Devs.ProffDea],35
settings,36
patches: [37
{38
find: ".getDesktopType()===",39
replacement: [40
{41
match: /(\i\.\i\.getDesktopType\(\)===\i\.\i\.NEVER)\)/,42
replace: "$&if(!$self.isPrivateChannelRead(arguments[0]?.message))return;else "43
},44
{45
match: /sound:(\i\?\i:void 0,volume:\i,onClick)/,46
replace: "sound:!$self.isPrivateChannelRead(arguments[0]?.message)?undefined:$1"47
}48
]49
}50
],51
isPrivateChannelRead(message: MessageJSON) {52
const channelType = ChannelStore.getChannel(message.channel_id)?.type;53
if (54
(channelType !== ChannelType.DM && channelType !== ChannelType.GROUP_DM) ||55
(channelType === ChannelType.DM && settings.store.channelToAffect === "group_dm") ||56
(channelType === ChannelType.GROUP_DM && settings.store.channelToAffect === "user_dm") ||57
(settings.store.allowMentions && message.mentions.some(m => m.id === UserStore.getCurrentUser().id)) ||58
(settings.store.allowEveryone && message.mention_everyone)59
) {60
return true;61
}62
return ReadStateStore.getOldestUnreadMessageId(message.channel_id) === message.id;63
},64
});65