From e483584effb82e5dc6e1e03da1b3bd04299bba31 Mon Sep 17 00:00:00 2001 From: Inbestigator Date: Sat, 9 Mar 2024 12:57:10 -0800 Subject: [PATCH] Organz (Organization) --- src/plugins/bypassDND/index.tsx | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/plugins/bypassDND/index.tsx b/src/plugins/bypassDND/index.tsx index 823ba707d..bd2edf9ba 100644 --- a/src/plugins/bypassDND/index.tsx +++ b/src/plugins/bypassDND/index.tsx @@ -28,6 +28,21 @@ function icon(enabled?: boolean) { ; } +function processIds(value) { + return value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "").join(", "); +} + +async function showNotification(message: Message, guildId?: string): Promise { + await Notifications.showNotification({ + title: `${message.author.globalName ?? message.author.username} ${guildId ? `sent a message in ${ChannelStore.getChannel(message.channel_id)?.name}` : "sent a message in a DM"}`, + body: message.content, + icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false), + onClick: function () { + NavigationRouter.transitionTo(`/channels/${guildId ?? "@me"}/${message.channel_id}/${message.id}`); + } + }); +} + function ContextCallback(name: "guild" | "user" | "channel"): NavContextMenuPatchCallback { return (children, props) => { const type = props[name]; @@ -58,21 +73,21 @@ const settings = definePluginSettings({ description: "Guilds to let bypass (notified when pinged anywhere in guild)", default: "", placeholder: "Separate with commas", - onChange: value => settings.store.guilds = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "").join(", ") + onChange: value => settings.store.guilds = processIds(value) }, channels: { type: OptionType.STRING, description: "Channels to let bypass (notified when pinged in that channel)", default: "", placeholder: "Separate with commas", - onChange: value => settings.store.channels = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "").join(", ") + onChange: value => settings.store.channels = processIds(value) }, users: { type: OptionType.STRING, description: "Users to let bypass (notified for all messages sent in DMs)", default: "", placeholder: "Separate with commas", - onChange: value => settings.store.users = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "").join(", ") + onChange: value => settings.store.users = processIds(value) }, allowOutsideOfDms: { type: OptionType.BOOLEAN, @@ -80,17 +95,6 @@ const settings = definePluginSettings({ } }); -async function showNotification(message: Message, guildId?: string): Promise { - await Notifications.showNotification({ - title: `${message.author.globalName ?? message.author.username} ${guildId ? `sent a message in ${ChannelStore.getChannel(message.channel_id)?.name}` : "sent a message in a DM"}`, - body: message.content, - icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false), - onClick: function () { - NavigationRouter.transitionTo(`/channels/${guildId ?? "@me"}/${message.channel_id}/${message.id}`); - } - }); -} - 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.",