1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-10 09:56:24 +00:00

update plugins

This commit is contained in:
Elvy 2025-01-03 20:35:05 +01:00
parent 2a5d84de7b
commit 716b75995b
4 changed files with 44 additions and 29 deletions

View file

@ -224,7 +224,7 @@ export function migrateSettingsToArrays(pluginName: string, settings: string[],
for (const setting of settings) {
if (SettingsStore.plain.plugins[pluginName] === undefined || typeof SettingsStore.plain.plugins[pluginName][setting] !== "string") continue;
logger.info(`Migrating setting ${setting} from ${pluginName} to list`);
if (SettingsStore.plain.plugins[pluginName][setting] === "") SettingsStore.plain.plugins[pluginName][setting] = [];
if (SettingsStore.plain.plugins[pluginName][setting] === "") SettingsStore.plain.plugins[pluginName][setting] = SettingsStore.plain.plugins[pluginName][setting].default ?? [];
else SettingsStore.plain.plugins[pluginName][setting] = SettingsStore.plain.plugins[pluginName][setting].split(stringSeparator);
}
}

View file

@ -91,7 +91,7 @@ export function SettingArrayComponent({
if (!inputElement || inputElement.value === "") {
return;
}
// TODO add picker for users?
// TODO add picker for users etc?
if (option.type !== OptionType.ARRAY && !(inputElement.value.length >= 18 && inputElement.value.length <= 19 && !isNaN(Number(inputElement.value)))) {
setError("Value is not a valid snowflake ID");
inputElement.value = "";
@ -104,7 +104,6 @@ export function SettingArrayComponent({
// FIXME make channels and guilds nicer!
// TODO make string type work
return (
<Forms.FormSection>
<Forms.FormTitle>{wordsToTitle(wordsFromCamel(id))}</Forms.FormTitle>
@ -151,13 +150,11 @@ export function SettingArrayComponent({
marginTop: "10px",
}}
>
{/* Add a single input field */}
<TextInput
type="text"
placeholder="Add Item (as ID)"
id={`vc-plugin-modal-input-${option.type === OptionType.CHANNELS ? "channel" : option.type === OptionType.GUILDS ? "guild" : option.type === OptionType.USERS ? "user" : "string"}`}
/>
{/* Add a submit button */}
<Button
size={Button.Sizes.MIN}
onClick={handleSubmit}

View file

@ -19,7 +19,7 @@
import { addChatBarButton, ChatBarButton } from "@api/ChatButtons";
import { addButton, removeButton } from "@api/MessagePopover";
import { updateMessage } from "@api/MessageUpdater";
import { definePluginSettings } from "@api/Settings";
import { definePluginSettings, migrateSettingsToArrays } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { getStegCloak } from "@utils/dependencies";
@ -92,11 +92,14 @@ const ChatBarIcon: ChatBarButton = ({ isMainChat }) => {
);
};
migrateSettingsToArrays("InvisibleChat", ["savedPasswords"]);
const settings = definePluginSettings({
savedPasswords: {
type: OptionType.STRING,
default: "password, Password",
description: "Saved Passwords (Seperated with a , )"
type: OptionType.ARRAY,
default: ["password", "Password"],
description: "Saved Passwords",
}
});
@ -206,7 +209,7 @@ export function isCorrectPassword(result: string): boolean {
}
export async function iteratePasswords(message: Message): Promise<string | false> {
const passwords = settings.store.savedPasswords.split(",").map(s => s.trim());
const passwords = settings.store.savedPasswords.map(s => s.trim());
if (!message?.content || !passwords?.length) return false;

View file

@ -18,7 +18,7 @@
import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, registerCommand, sendBotMessage, unregisterCommand } from "@api/Commands";
import * as DataStore from "@api/DataStore";
import { Settings } from "@api/Settings";
import { definePluginSettings, Settings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
@ -32,19 +32,12 @@ interface Tag {
enabled: boolean;
}
const getTags = () => DataStore.get(DATA_KEY).then<Tag[]>(t => t ?? []);
const getTag = (name: string) => DataStore.get(DATA_KEY).then<Tag | null>((t: Tag[]) => (t ?? []).find((tt: Tag) => tt.name === name) ?? null);
const addTag = async (tag: Tag) => {
const tags = await getTags();
tags.push(tag);
DataStore.set(DATA_KEY, tags);
return tags;
const getTag = (name: string) => settings.store.data.find((tt: Tag) => tt.name === name);
const addTag = (tag: Tag) => {
settings.store.data.push(tag);
};
const removeTag = async (name: string) => {
let tags = await getTags();
tags = await tags.filter((t: Tag) => t.name !== name);
DataStore.set(DATA_KEY, tags);
return tags;
const removeTag = (name: string) => {
settings.store.data.filter((t: Tag) => t.name !== name);
};
function createTagCommand(tag: Tag) {
@ -53,7 +46,7 @@ function createTagCommand(tag: Tag) {
description: tag.name,
inputType: ApplicationCommandInputType.BUILT_IN_TEXT,
execute: async (_, ctx) => {
if (!await getTag(tag.name)) {
if (!getTag(tag.name)) {
sendBotMessage(ctx.channel.id, {
content: `${EMOTE} The tag **${tag.name}** does not exist anymore! Please reload ur Discord to fix :)`
});
@ -70,6 +63,21 @@ function createTagCommand(tag: Tag) {
}
const settings = definePluginSettings({
data: {
type: OptionType.ARRAY,
hidden: true,
description: ""
},
migrated: {
type: OptionType.BOOLEAN,
description: "",
default: false,
hidden: true
}
});
export default definePlugin({
name: "MessageTags",
description: "Allows you to save messages and to use them with a simple command.",
@ -82,9 +90,16 @@ export default definePlugin({
default: true
}
},
settings,
async start() {
for (const tag of await getTags()) createTagCommand(tag);
if (!settings.store.migrated) {
const data = await DataStore.get(DATA_KEY);
if (!!data) settings.store.data = data;
settings.store.migrated = true;
}
for (const tag of settings.store.data) createTagCommand(tag);
},
commands: [
@ -165,7 +180,7 @@ export default definePlugin({
};
createTagCommand(tag);
await addTag(tag);
addTag(tag);
sendBotMessage(ctx.channel.id, {
content: `${EMOTE} Successfully created the tag **${name}**!`
@ -181,7 +196,7 @@ export default definePlugin({
});
unregisterCommand(name);
await removeTag(name);
removeTag(name);
sendBotMessage(ctx.channel.id, {
content: `${EMOTE} Successfully deleted the tag **${name}**!`
@ -195,7 +210,7 @@ export default definePlugin({
// @ts-ignore
title: "All Tags:",
// @ts-ignore
description: (await getTags())
description: settings.store.data
.map(tag => `\`${tag.name}\`: ${tag.message.slice(0, 72).replaceAll("\\n", " ")}${tag.message.length > 72 ? "..." : ""}`)
.join("\n") || `${EMOTE} Woops! There are no tags yet, use \`/tags create\` to create one!`,
// @ts-ignore
@ -208,7 +223,7 @@ export default definePlugin({
}
case "preview": {
const name: string = findOption(args[0].options, "tag-name", "");
const tag = await getTag(name);
const tag = getTag(name);
if (!tag)
return sendBotMessage(ctx.channel.id, {