Let bypass users create notification outside of DM

This commit is contained in:
Inbestigator 2024-03-06 08:54:05 -08:00
parent 58d64f7e77
commit daee463e2a

View file

@ -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({ export default definePlugin({
name: "BypassDND", 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.", 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 (message.author.id === currentUser.id) return;
if (await PresenceStore.getStatus(currentUser.id) != 'dnd') 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))) { 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({ await showChannelNotification(message);
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),
});
return; return;
} }
if (bypasses.users.includes(message.author.id) && channelId === await PrivateChannelsStore.getOrEnsurePrivateChannel(message.author.id)) { if (bypasses.users.includes(message.author.id)) {
await Notifications.showNotification({ if (channelId === await PrivateChannelsStore.getOrEnsurePrivateChannel(message.author.id)) {
title: `${message.author.globalName ?? message.author.username} sent a message in a DM`, await showUserNotification(message);
body: message.content, } else if (message.content.includes(`<@${currentUser.id}>`) || message.mentions.some(mention => mention.id === currentUser.id)) {
icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false), await showChannelNotification(message);
}); }
} }
} }
}, },