mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 23:38:32 +00:00
Fixed all Lint issues, formatted script
This commit is contained in:
parent
733de54d01
commit
68412b9879
1 changed files with 65 additions and 42 deletions
|
@ -1,10 +1,17 @@
|
||||||
import { NavContextMenuPatchCallback, addContextMenuPatch, removeContextMenuPatch } from "@api/ContextMenu";
|
/*
|
||||||
import { definePluginSettings } from "@api/Settings";
|
* Vencord, a Discord client mod
|
||||||
|
* Copyright (c) 2024 Vendicated and contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { addContextMenuPatch, type NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu";
|
||||||
import { DataStore, Notifications } from "@api/index";
|
import { DataStore, Notifications } from "@api/index";
|
||||||
|
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";
|
||||||
import { ChannelStore, Menu, PresenceStore, PrivateChannelsStore, UserStore } from "@webpack/common";
|
import { ChannelStore, Menu, PresenceStore, PrivateChannelsStore, UserStore } from "@webpack/common";
|
||||||
import { Channel, Guild, Message, User } from "discord-types/general";
|
import { type Channel, type Guild, type Message, type User } from "discord-types/general";
|
||||||
|
|
||||||
interface ContextProps {
|
interface ContextProps {
|
||||||
channel: Channel;
|
channel: Channel;
|
||||||
user: User;
|
user: User;
|
||||||
|
@ -21,64 +28,80 @@ interface IMessageCreate {
|
||||||
}
|
}
|
||||||
|
|
||||||
const GuildContext: NavContextMenuPatchCallback = (children, { guild }: ContextProps) => () => {
|
const GuildContext: NavContextMenuPatchCallback = (children, { guild }: ContextProps) => () => {
|
||||||
if (!guild) return;
|
|
||||||
children.splice(-1, 0, (
|
children.splice(-1, 0, (
|
||||||
<Menu.MenuGroup>
|
<Menu.MenuGroup>
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
id="dnd-guild-bypass"
|
id="dnd-guild-bypass"
|
||||||
label={`${bypasses["guilds"].includes(guild.id) ? "Remove" : "Add"} DND Bypass`}
|
label={`${bypasses.guilds.includes(guild.id) ? "Remove" : "Add"} DND Bypass`}
|
||||||
action={async () => {
|
action={() => {
|
||||||
if (bypasses["guilds"].includes(guild.id)) bypasses["guilds"] = await bypasses["guilds"].filter(id => id !== guild.id);
|
if (bypasses.guilds.includes(guild.id)) bypasses.guilds = bypasses.guilds.filter(id => id !== guild.id);
|
||||||
else bypasses["guilds"].push(guild.id);
|
else bypasses.guilds.push(guild.id);
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
DataStore.set("bypassdnd", bypasses)
|
||||||
settings.store.guilds = (bypasses["guilds"].join(', '));
|
.then(() => {
|
||||||
|
settings.store.guilds = bypasses.guilds.join(", ");
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</Menu.MenuGroup>
|
</Menu.MenuGroup>
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
const ChannelContext: NavContextMenuPatchCallback = (children, { channel }: ContextProps) => () => {
|
const ChannelContext: NavContextMenuPatchCallback = (children, { channel }: ContextProps) => () => {
|
||||||
if (!channel) return;
|
|
||||||
children.splice(-1, 0, (
|
children.splice(-1, 0, (
|
||||||
<Menu.MenuGroup>
|
<Menu.MenuGroup>
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
id="dnd-channel-bypass"
|
id="dnd-channel-bypass"
|
||||||
label={`${bypasses["channels"].includes(channel.id) ? "Remove" : "Add"} DND Bypass`}
|
label={`${bypasses.channels.includes(channel.id) ? "Remove" : "Add"} DND Bypass`}
|
||||||
action={async () => {
|
action={() => {
|
||||||
if (bypasses["channels"].includes(channel.id)) bypasses["channels"] = await bypasses["channels"].filter(id => id !== channel.id);
|
if (bypasses.channels.includes(channel.id)) bypasses.channels = bypasses.channels.filter(id => id !== channel.id);
|
||||||
else bypasses["channels"].push(channel.id);
|
else bypasses.channels.push(channel.id);
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
|
||||||
settings.store.channels = (bypasses["channels"].join(', '));
|
DataStore.set("bypassdnd", bypasses)
|
||||||
|
.then(() => {
|
||||||
|
settings.store.channels = bypasses.channels.join(", ");
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</Menu.MenuGroup>
|
</Menu.MenuGroup>
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
const UserContext: NavContextMenuPatchCallback = (children, { user }: ContextProps) => () => {
|
const UserContext: NavContextMenuPatchCallback = (children, { user }: ContextProps) => () => {
|
||||||
if (!user) return;
|
|
||||||
children.splice(-1, 0, (
|
children.splice(-1, 0, (
|
||||||
<Menu.MenuGroup>
|
<Menu.MenuGroup>
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
id="dnd-user-bypass"
|
id="dnd-user-bypass"
|
||||||
label={`${bypasses["users"].includes(user.id) ? "Remove" : "Add"} DND Bypass`}
|
label={`${bypasses.users.includes(user.id) ? "Remove" : "Add"} DND Bypass`}
|
||||||
action={async () => {
|
action={() => {
|
||||||
if (bypasses["users"].includes(user.id)) bypasses["users"] = await bypasses["users"].filter(id => id !== user.id);
|
if (bypasses.users.includes(user.id)) bypasses.users = bypasses.users.filter(id => id !== user.id);
|
||||||
else bypasses["users"].push(user.id);
|
else bypasses.users.push(user.id);
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
|
||||||
settings.store.users = (bypasses["users"].join(', '));
|
DataStore.set("bypassdnd", bypasses)
|
||||||
|
.then(() => {
|
||||||
|
settings.store.users = bypasses.users.join(", ");
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Menu.MenuGroup>
|
</Menu.MenuGroup>
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
type Bypasses = {
|
interface Bypasses {
|
||||||
guilds: string[];
|
guilds: string[];
|
||||||
channels: string[];
|
channels: string[];
|
||||||
users: string[];
|
users: string[];
|
||||||
};
|
}
|
||||||
|
|
||||||
let bypasses: Bypasses;
|
let bypasses: Bypasses;
|
||||||
|
|
||||||
|
@ -89,9 +112,9 @@ 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() !== '');
|
bypasses.guilds = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "");
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
await DataStore.set("bypassdnd", bypasses);
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
channels: {
|
channels: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
|
@ -99,9 +122,9 @@ 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() !== '');
|
bypasses.channels = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "");
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
await DataStore.set("bypassdnd", bypasses);
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
users: {
|
users: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
|
@ -109,29 +132,29 @@ 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() !== '');
|
bypasses.users = value.replace(/\s/g, "").split(",").filter(id => id.trim() !== "");
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
await DataStore.set("bypassdnd", bypasses);
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
allowOutsideOfDms: {
|
allowOutsideOfDms: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
description: "Allow selected users to bypass DND outside of DMs too (acts like a channel/guild bypass, but it's for all messages sent by the selected users)",
|
description: "Allow selected users to bypass DND outside of DMs too (acts like a channel/guild bypass, but it's for all messages sent by the selected users)"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function showUserNotification(message: Message) {
|
async function showUserNotification(message: Message): Promise<void> {
|
||||||
await Notifications.showNotification({
|
await Notifications.showNotification({
|
||||||
title: `${message.author.globalName ?? message.author.username} sent a message in a DM`,
|
title: `${message.author.globalName ?? message.author.username} sent a message in a DM`,
|
||||||
body: message.content,
|
body: message.content,
|
||||||
icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false),
|
icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function showChannelNotification(message: Message) {
|
async function showChannelNotification(message: Message): Promise<void> {
|
||||||
await Notifications.showNotification({
|
await Notifications.showNotification({
|
||||||
title: `${message.author.globalName ?? message.author.username} sent a message in ${ChannelStore.getChannel(message.channel_id).name}`,
|
title: `${message.author.globalName ?? message.author.username} sent a message in ${ChannelStore.getChannel(message.channel_id)?.name}`,
|
||||||
body: message.content,
|
body: message.content,
|
||||||
icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false),
|
icon: UserStore.getUser(message.author.id).getAvatarURL(undefined, undefined, false)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,10 +167,10 @@ export default definePlugin({
|
||||||
try {
|
try {
|
||||||
if (optimistic || type !== "MESSAGE_CREATE") return;
|
if (optimistic || type !== "MESSAGE_CREATE") return;
|
||||||
if (message.state === "SENDING") return;
|
if (message.state === "SENDING") return;
|
||||||
if (!message.content) return;
|
if (message.content === "") return;
|
||||||
const currentUser = UserStore.getCurrentUser();
|
const currentUser = UserStore.getCurrentUser();
|
||||||
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 showChannelNotification(message);
|
await showChannelNotification(message);
|
||||||
return;
|
return;
|
||||||
|
@ -155,7 +178,7 @@ export default definePlugin({
|
||||||
if (bypasses.users.includes(message.author.id)) {
|
if (bypasses.users.includes(message.author.id)) {
|
||||||
if (channelId === await PrivateChannelsStore.getOrEnsurePrivateChannel(message.author.id)) {
|
if (channelId === await PrivateChannelsStore.getOrEnsurePrivateChannel(message.author.id)) {
|
||||||
await showUserNotification(message);
|
await showUserNotification(message);
|
||||||
} else if ((message.content.includes(`<@${currentUser.id}>`) || message.mentions.some(mention => mention.id === currentUser.id)) && settings.store.allowOutsideOfDms) {
|
} else if ((message.content.includes(`<@${currentUser.id}>`) || message.mentions.some(mention => mention.id === currentUser.id)) && (settings.store.allowOutsideOfDms === true)) {
|
||||||
await showChannelNotification(message);
|
await showChannelNotification(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +192,7 @@ export default definePlugin({
|
||||||
addContextMenuPatch("guild-context", GuildContext);
|
addContextMenuPatch("guild-context", GuildContext);
|
||||||
addContextMenuPatch("channel-context", ChannelContext);
|
addContextMenuPatch("channel-context", ChannelContext);
|
||||||
addContextMenuPatch("user-context", UserContext);
|
addContextMenuPatch("user-context", UserContext);
|
||||||
bypasses = await DataStore.get("bypassdnd") ?? { guilds: [], channels: [], users: [] };
|
bypasses = (await DataStore.get("bypassdnd")) ?? { guilds: [], channels: [], users: [] };
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
await DataStore.set("bypassdnd", bypasses);
|
||||||
},
|
},
|
||||||
stop() {
|
stop() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue