From daee463e2a34ca9c43e08eaf196111cc2eca0205 Mon Sep 17 00:00:00 2001 From: Inbestigator Date: Wed, 6 Mar 2024 08:54:05 -0800 Subject: [PATCH] Let bypass users create notification outside of DM --- src/plugins/bypassDND/index.tsx | 34 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/plugins/bypassDND/index.tsx b/src/plugins/bypassDND/index.tsx index 6b324f692..cdc4b37b0 100644 --- a/src/plugins/bypassDND/index.tsx +++ b/src/plugins/bypassDND/index.tsx @@ -115,6 +115,22 @@ const settings = definePluginSettings({ } }); +async function showUserNotification(message: Message) { + await Notifications.showNotification({ + title: `${message.author.globalName ?? message.author.username} sent a message in a DM`, + body: message.content, + icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false), + }); +} + +async function showChannelNotification(message: Message) { + await Notifications.showNotification({ + title: `${message.author.globalName ?? message.author.username} sent a message in ${ChannelStore.getChannel(message.channel_id).name}`, + body: message.content, + icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false), + }); +} + export default definePlugin({ name: "BypassDND", description: "Still get notifications from specific sources when in do not disturb mode. Right-click on users/channels/guilds to set them to bypass do not disturb mode.", @@ -128,19 +144,15 @@ export default definePlugin({ if (message.author.id === currentUser.id) return; if (await PresenceStore.getStatus(currentUser.id) != 'dnd') return; if ((bypasses.guilds.includes(guildId) || bypasses.channels.includes(channelId)) && (message.content.includes(`<@${currentUser.id}>`) || message.mentions.some(mention => mention.id === currentUser.id))) { - await Notifications.showNotification({ - title: `${message.author.globalName ?? message.author.username} sent a message in ${ChannelStore.getChannel(channelId).name}`, - body: message.content, - icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false), - }); + await showChannelNotification(message); return; } - if (bypasses.users.includes(message.author.id) && channelId === await PrivateChannelsStore.getOrEnsurePrivateChannel(message.author.id)) { - await Notifications.showNotification({ - title: `${message.author.globalName ?? message.author.username} sent a message in a DM`, - body: message.content, - icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false), - }); + if (bypasses.users.includes(message.author.id)) { + if (channelId === await PrivateChannelsStore.getOrEnsurePrivateChannel(message.author.id)) { + await showUserNotification(message); + } else if (message.content.includes(`<@${currentUser.id}>`) || message.mentions.some(mention => mention.id === currentUser.id)) { + await showChannelNotification(message); + } } } },