mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 23:38:32 +00:00
Added a caching for the whitelist
This commit is contained in:
parent
c65f3dbbbe
commit
df0a29fc16
1 changed files with 13 additions and 10 deletions
|
@ -10,6 +10,8 @@ import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { MessageStore, showToast, UserStore } from "@webpack/common";
|
import { MessageStore, showToast, UserStore } from "@webpack/common";
|
||||||
import { MessageJSON } from "discord-types/general";
|
import { MessageJSON } from "discord-types/general";
|
||||||
|
|
||||||
|
let cachedWhitelist: string[] = [];
|
||||||
|
|
||||||
export const settings = definePluginSettings({
|
export const settings = definePluginSettings({
|
||||||
alwaysPingOnReply: {
|
alwaysPingOnReply: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
|
@ -21,6 +23,14 @@ export const settings = definePluginSettings({
|
||||||
description: "Comma-separated list of User IDs to always receive reply pings from",
|
description: "Comma-separated list of User IDs to always receive reply pings from",
|
||||||
default: "",
|
default: "",
|
||||||
disabled: () => settings.store.alwaysPingOnReply,
|
disabled: () => settings.store.alwaysPingOnReply,
|
||||||
|
onChange: newValue => {
|
||||||
|
cachedWhitelist = parseWhitelist(newValue);
|
||||||
|
if (!validateWhitelist(newValue)) {
|
||||||
|
showToast("Invalid User ID: One or more User IDs in the whitelist are invalid. Please check your input.");
|
||||||
|
} else {
|
||||||
|
showToast("Whitelist Updated: Reply ping whitelist has been successfully updated.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -47,8 +57,7 @@ export default definePlugin({
|
||||||
if (!repliedMessage || repliedMessage.author.id !== user.id)
|
if (!repliedMessage || repliedMessage.author.id !== user.id)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const whitelist = parseWhitelist(settings.store.replyPingWhitelist);
|
const isWhitelisted = cachedWhitelist.includes(message.author.id);
|
||||||
const isWhitelisted = whitelist.includes(message.author.id);
|
|
||||||
|
|
||||||
if (isWhitelisted || settings.store.alwaysPingOnReply) {
|
if (isWhitelisted || settings.store.alwaysPingOnReply) {
|
||||||
if (!message.mentions.some(mention => mention.id === user.id))
|
if (!message.mentions.some(mention => mention.id === user.id))
|
||||||
|
@ -66,19 +75,13 @@ export default definePlugin({
|
||||||
|
|
||||||
function validateWhitelist(value: string) {
|
function validateWhitelist(value: string) {
|
||||||
const whitelist = parseWhitelist(value);
|
const whitelist = parseWhitelist(value);
|
||||||
if (whitelist.some(id => !isValidUserId(id))) {
|
return !whitelist.some(id => !isValidUserId(id));
|
||||||
showToast("Invalid User ID: One or more User IDs in the whitelist are invalid. Please check your input.");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
showToast("Whitelist Updated: Reply ping whitelist has been successfully updated.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function parseWhitelist(value: string) {
|
function parseWhitelist(value: string) {
|
||||||
return value.split(",")
|
return value.split(",")
|
||||||
.map(id => id.trim())
|
.map(id => id.trim())
|
||||||
.filter(id => id !== "");
|
.filter(id => id !== "" && isValidUserId(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidUserId(id: string) {
|
function isValidUserId(id: string) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue