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) { for (const setting of settings) {
if (SettingsStore.plain.plugins[pluginName] === undefined || typeof SettingsStore.plain.plugins[pluginName][setting] !== "string") continue; if (SettingsStore.plain.plugins[pluginName] === undefined || typeof SettingsStore.plain.plugins[pluginName][setting] !== "string") continue;
logger.info(`Migrating setting ${setting} from ${pluginName} to list`); 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); 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 === "") { if (!inputElement || inputElement.value === "") {
return; 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)))) { 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"); setError("Value is not a valid snowflake ID");
inputElement.value = ""; inputElement.value = "";
@ -104,7 +104,6 @@ export function SettingArrayComponent({
// FIXME make channels and guilds nicer! // FIXME make channels and guilds nicer!
// TODO make string type work
return ( return (
<Forms.FormSection> <Forms.FormSection>
<Forms.FormTitle>{wordsToTitle(wordsFromCamel(id))}</Forms.FormTitle> <Forms.FormTitle>{wordsToTitle(wordsFromCamel(id))}</Forms.FormTitle>
@ -151,13 +150,11 @@ export function SettingArrayComponent({
marginTop: "10px", marginTop: "10px",
}} }}
> >
{/* Add a single input field */}
<TextInput <TextInput
type="text" type="text"
placeholder="Add Item (as ID)" 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"}`} 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 <Button
size={Button.Sizes.MIN} size={Button.Sizes.MIN}
onClick={handleSubmit} onClick={handleSubmit}

View file

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

View file

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