Removed swag from index.ts

Increased processing time by AT LEAST 0.08ms
Added pipebomb (will detonate when rini uses plugin)
This commit is contained in:
AntonMacG 2023-11-17 22:52:20 +00:00
parent 4b02352375
commit 3afece4dbc

View file

@ -7,11 +7,9 @@
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";
import { MessageStore, showToast, UserStore } from "@webpack/common"; import { MessageStore, 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,
@ -23,20 +21,6 @@ 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 => {
const originalIDs = newValue.split(",")
.map(id => id.trim())
.filter(id => id !== "");
const isInvalid = originalIDs.some(id => !isValidUserId(id));
if (isInvalid) {
showToast("Invalid User ID: One or more User IDs in the whitelist are invalid. Please check your input.");
} else {
cachedWhitelist = originalIDs;
showToast("Whitelist Updated: Reply ping whitelist has been successfully updated.");
}
}
} }
}); });
@ -56,18 +40,18 @@ export default definePlugin({
modifyMentions(message: MessageJSON) { modifyMentions(message: MessageJSON) {
const user = UserStore.getCurrentUser(); const user = UserStore.getCurrentUser();
if (message.author.id === user.id) if (message.author.id === user.id) return;
return;
const repliedMessage = this.getRepliedMessage(message); const repliedMessage = this.getRepliedMessage(message);
if (!repliedMessage || repliedMessage.author.id !== user.id) if (!repliedMessage || repliedMessage.author.id !== user.id) return;
return;
const isWhitelisted = settings.store.replyPingWhitelist.split(",").some(id => message.author.id === id.trim()); const whitelist = settings.store.replyPingWhitelist.split(",").map(id => id.trim());
const isWhitelisted = whitelist.some(id => isValidUserId(id) && message.author.id === 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)) {
message.mentions.push(user as any); message.mentions.push(user as any);
}
} else { } else {
message.mentions = message.mentions.filter(mention => mention.id !== user.id); message.mentions = message.mentions.filter(mention => mention.id !== user.id);
} }
@ -82,3 +66,4 @@ export default definePlugin({
function isValidUserId(id: string) { function isValidUserId(id: string) {
return /^\d+$/.test(id); return /^\d+$/.test(id);
} }