From 76b5b1e8699c0120c39c41fa3c7a75b99792d051 Mon Sep 17 00:00:00 2001 From: Inbestigator <119569726+Inbestigator@users.noreply.github.com> Date: Wed, 6 Mar 2024 08:03:45 -0800 Subject: [PATCH] Delete original bypassdnd directory --- src/plugins/bypassdnd/index.tsx | 154 -------------------------------- 1 file changed, 154 deletions(-) delete mode 100644 src/plugins/bypassdnd/index.tsx diff --git a/src/plugins/bypassdnd/index.tsx b/src/plugins/bypassdnd/index.tsx deleted file mode 100644 index c076ad135..000000000 --- a/src/plugins/bypassdnd/index.tsx +++ /dev/null @@ -1,154 +0,0 @@ -import { NavContextMenuPatchCallback, addContextMenuPatch, removeContextMenuPatch } from "@api/ContextMenu"; -import { definePluginSettings } from "@api/Settings"; -import { DataStore, Notifications } from "@api/index"; -import { Devs } from "@utils/constants"; -import definePlugin, { OptionType } from "@utils/types"; -import { ChannelStore, Menu, PresenceStore, PrivateChannelsStore, UserStore } from "@webpack/common"; -import { Channel, Guild, Message, User } from "discord-types/general"; -interface ContextProps { - channel: Channel; - user: User; - guild: Guild; -} - -interface IMessageCreate { - type: "MESSAGE_CREATE"; - optimistic: boolean; - isPushNotification: boolean; - channelId: string; - guildId: string; - message: Message; -} - -const GuildContext: NavContextMenuPatchCallback = (children, { guild }: ContextProps) => () => { - if (!guild) return; - children.splice(-1, 0, ( - - { - if (bypasses["guilds"].includes(guild.id)) bypasses["guilds"] = await bypasses["guilds"].filter(id => id !== guild.id); - else bypasses["guilds"].push(guild.id); - await DataStore.set("bypassdnd", bypasses); - settings.store.guilds = (bypasses["guilds"].join(', ')); - }} - /> - - )); -}; - -const ChannelContext: NavContextMenuPatchCallback = (children, { channel }: ContextProps) => () => { - if (!channel) return; - children.splice(-1, 0, ( - - { - if (bypasses["channels"].includes(channel.id)) bypasses["channels"] = await bypasses["channels"].filter(id => id !== channel.id); - else bypasses["channels"].push(channel.id); - await DataStore.set("bypassdnd", bypasses); - settings.store.channels = (bypasses["channels"].join(', ')); - }} - /> - - )); -}; - -const UserContext: NavContextMenuPatchCallback = (children, { user }: ContextProps) => () => { - if (!user) return; - children.splice(-1, 0, ( - - { - if (bypasses["users"].includes(user.id)) bypasses["users"] = await bypasses["users"].filter(id => id !== user.id); - else bypasses["users"].push(user.id); - await DataStore.set("bypassdnd", bypasses); - settings.store.users = (bypasses["users"].join(', ')); - }} - /> - - )); -}; - -let bypasses; - -const settings = definePluginSettings({ - guilds: { - type: OptionType.STRING, - description: "Guilds to let bypass (notified when pinged anywhere in guild)", - default: "", - placeholder: "Separate with commas", - onChange: async function (value) { - bypasses["guild"] = value.replace(/\s/g, '').split(',').filter(id => id.trim() !== ''); - await DataStore.set("bypassdnd", bypasses); - }, - }, - channels: { - type: OptionType.STRING, - description: "Channels to let bypass (notified when pinged in that channel)", - default: "", - placeholder: "Separate with commas", - onChange: async function (value) { - bypasses["channels"] = value.replace(/\s/g, '').split(',').filter(id => id.trim() !== ''); - await DataStore.set("bypassdnd", bypasses); - }, - }, - users: { - type: OptionType.STRING, - description: "Users to let bypass (notified for all messages)", - default: "", - placeholder: "Separate with commas", - onChange: async function (value) { - bypasses["users"] = value.replace(/\s/g, '').split(',').filter(id => id.trim() !== ''); - await DataStore.set("bypassdnd", bypasses); - }, - } -}); - -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.", - authors: [Devs.Inbestigator], - flux: { - async MESSAGE_CREATE({ optimistic, type, message, guildId, channelId }: IMessageCreate) { - if (optimistic || type !== "MESSAGE_CREATE") return; - if (message.state === "SENDING") return; - if (!message.content) return; - const currentUser = UserStore.getCurrentUser(); - 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), - }); - 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), - }); - } - } - }, - settings, - async start() { - addContextMenuPatch("guild-context", GuildContext); - addContextMenuPatch("channel-context", ChannelContext); - addContextMenuPatch("user-context", UserContext); - bypasses = await DataStore.get("bypassdnd") ?? { guilds: [], channels: [], users: [] }; - await DataStore.set("bypassdnd", bypasses); - }, - stop() { - removeContextMenuPatch("guild-context", GuildContext); - removeContextMenuPatch("channel-context", ChannelContext); - removeContextMenuPatch("user-context", UserContext); - } -});