mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-25 07:48:32 +00:00
Removed DataStore shenanigans, this change means that bypasses can be saved to the cloud settings!
This commit is contained in:
parent
ce99871a4d
commit
e1b75bdb57
1 changed files with 13 additions and 35 deletions
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { type NavContextMenuPatchCallback } from "@api/ContextMenu";
|
import { type NavContextMenuPatchCallback } from "@api/ContextMenu";
|
||||||
import { DataStore, Notifications } from "@api/index";
|
import { Notifications } from "@api/index";
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
|
@ -13,7 +13,6 @@ import { ChannelStore, Menu, MessageStore, NavigationRouter, PresenceStore, Priv
|
||||||
import { type Message } from "discord-types/general";
|
import { type Message } from "discord-types/general";
|
||||||
|
|
||||||
interface IMessageCreate {
|
interface IMessageCreate {
|
||||||
optimistic: boolean;
|
|
||||||
channelId: string;
|
channelId: string;
|
||||||
guildId: string;
|
guildId: string;
|
||||||
message: Message;
|
message: Message;
|
||||||
|
@ -33,7 +32,7 @@ function ContextCallback(name: "guild" | "user" | "channel"): NavContextMenuPatc
|
||||||
return (children, props) => {
|
return (children, props) => {
|
||||||
const type = props[name];
|
const type = props[name];
|
||||||
if (!type) return;
|
if (!type) return;
|
||||||
const enabled = bypasses[`${name}s`].includes(type.id);
|
const enabled = settings.store[`${name}s`].split(", ").includes(type.id);
|
||||||
if (name === "user" && type.id === UserStore.getCurrentUser().id) return;
|
if (name === "user" && type.id === UserStore.getCurrentUser().id) return;
|
||||||
children.splice(-1, 0, (
|
children.splice(-1, 0, (
|
||||||
<Menu.MenuGroup>
|
<Menu.MenuGroup>
|
||||||
|
@ -42,16 +41,10 @@ function ContextCallback(name: "guild" | "user" | "channel"): NavContextMenuPatc
|
||||||
label={`${enabled ? "Remove" : "Add"} DND Bypass`}
|
label={`${enabled ? "Remove" : "Add"} DND Bypass`}
|
||||||
icon={() => icon(enabled)}
|
icon={() => icon(enabled)}
|
||||||
action={() => {
|
action={() => {
|
||||||
if (enabled) bypasses[`${name}s`] = bypasses[`${name}s`].filter(id => id !== type.id);
|
let bypasses: string[] = settings.store[`${name}s`].split(", ");
|
||||||
else bypasses[`${name}s`].push(type.id);
|
if (enabled) bypasses = bypasses.filter(id => id !== type.id);
|
||||||
|
else bypasses.push(type.id);
|
||||||
DataStore.set("bypassdnd", bypasses)
|
settings.store[`${name}s`] = bypasses.join(", ");
|
||||||
.then(() => {
|
|
||||||
settings.store[`${name}s`] = bypasses[`${name}s`].join(", ");
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Menu.MenuGroup>
|
</Menu.MenuGroup>
|
||||||
|
@ -59,14 +52,6 @@ function ContextCallback(name: "guild" | "user" | "channel"): NavContextMenuPatc
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Bypasses {
|
|
||||||
guilds: string[];
|
|
||||||
channels: string[];
|
|
||||||
users: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
let bypasses: Bypasses;
|
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
guilds: {
|
guilds: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
|
@ -74,8 +59,7 @@ const settings = definePluginSettings({
|
||||||
default: "",
|
default: "",
|
||||||
placeholder: "Separate with commas",
|
placeholder: "Separate with commas",
|
||||||
onChange: async function (value) {
|
onChange: async function (value) {
|
||||||
bypasses.guilds = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "");
|
settings.store.guilds = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "").join(", ");
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
channels: {
|
channels: {
|
||||||
|
@ -84,8 +68,7 @@ const settings = definePluginSettings({
|
||||||
default: "",
|
default: "",
|
||||||
placeholder: "Separate with commas",
|
placeholder: "Separate with commas",
|
||||||
onChange: async function (value) {
|
onChange: async function (value) {
|
||||||
bypasses.channels = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "");
|
settings.store.channels = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "").join(", ");
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
users: {
|
users: {
|
||||||
|
@ -94,8 +77,7 @@ const settings = definePluginSettings({
|
||||||
default: "",
|
default: "",
|
||||||
placeholder: "Separate with commas",
|
placeholder: "Separate with commas",
|
||||||
onChange: async function (value) {
|
onChange: async function (value) {
|
||||||
bypasses.users = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "");
|
settings.store.users = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "").join(", ");
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
allowOutsideOfDms: {
|
allowOutsideOfDms: {
|
||||||
|
@ -120,17 +102,17 @@ export default definePlugin({
|
||||||
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.",
|
||||||
authors: [Devs.Inbestigator],
|
authors: [Devs.Inbestigator],
|
||||||
flux: {
|
flux: {
|
||||||
async MESSAGE_CREATE({ optimistic, message, guildId, channelId }: IMessageCreate) {
|
async MESSAGE_CREATE({ message, guildId, channelId }: IMessageCreate) {
|
||||||
try {
|
try {
|
||||||
const currentUser = UserStore.getCurrentUser();
|
const currentUser = UserStore.getCurrentUser();
|
||||||
const userStatus = await PresenceStore.getStatus(currentUser.id);
|
const userStatus = await PresenceStore.getStatus(currentUser.id);
|
||||||
if (optimistic || message.state === "SENDING" || message.content === "" || message.author.id === currentUser.id || userStatus !== "dnd") {
|
if (message.state === "SENDING" || message.content === "" || message.author.id === currentUser.id || userStatus !== "dnd") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const mentioned = MessageStore.getMessage(channelId, message.id)?.mentioned;
|
const mentioned = MessageStore.getMessage(channelId, message.id)?.mentioned;
|
||||||
if ((bypasses.guilds.includes(guildId) || bypasses.channels.includes(channelId)) && mentioned) {
|
if ((settings.store.guilds.split(", ").includes(guildId) || settings.store.channels.split(", ").includes(channelId)) && mentioned) {
|
||||||
await showNotification(message, guildId);
|
await showNotification(message, guildId);
|
||||||
} else if (bypasses.users.includes(message.author.id)) {
|
} else if (settings.store.users.split(", ").includes(message.author.id)) {
|
||||||
const userChannelId = await PrivateChannelsStore.getOrEnsurePrivateChannel(message.author.id);
|
const userChannelId = await PrivateChannelsStore.getOrEnsurePrivateChannel(message.author.id);
|
||||||
if (channelId === userChannelId || (mentioned && settings.store.allowOutsideOfDms === true)) {
|
if (channelId === userChannelId || (mentioned && settings.store.allowOutsideOfDms === true)) {
|
||||||
await showNotification(message, guildId);
|
await showNotification(message, guildId);
|
||||||
|
@ -146,9 +128,5 @@ export default definePlugin({
|
||||||
"guild-context": ContextCallback("guild"),
|
"guild-context": ContextCallback("guild"),
|
||||||
"channel-context": ContextCallback("channel"),
|
"channel-context": ContextCallback("channel"),
|
||||||
"user-context": ContextCallback("user"),
|
"user-context": ContextCallback("user"),
|
||||||
},
|
|
||||||
async start() {
|
|
||||||
bypasses = (await DataStore.get("bypassdnd")) ?? { guilds: [], channels: [], users: [] };
|
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue