From bc843c362546c9c2559f46798a1b831050376de7 Mon Sep 17 00:00:00 2001 From: Elvyra <88881326+EepyElvyra@users.noreply.github.com> Date: Sun, 19 Jan 2025 19:43:33 +0100 Subject: [PATCH] revert the changes that migrate datastore to array settings v2 --- src/plugins/messageTags/index.ts | 53 ++++++++++++-------------------- src/plugins/pinDms/index.tsx | 1 + 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/plugins/messageTags/index.ts b/src/plugins/messageTags/index.ts index 50bb62665..5ba4ab94a 100644 --- a/src/plugins/messageTags/index.ts +++ b/src/plugins/messageTags/index.ts @@ -18,7 +18,7 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, registerCommand, sendBotMessage, unregisterCommand } from "@api/Commands"; import * as DataStore from "@api/DataStore"; -import { definePluginSettings, Settings } from "@api/Settings"; +import { Settings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; @@ -32,12 +32,19 @@ interface Tag { enabled: boolean; } -const getTag = (name: string) => settings.store.data.find((tt: Tag) => tt.name === name); -const addTag = (tag: Tag) => { - settings.store.data.push(tag); +const getTags = () => DataStore.get(DATA_KEY).then(t => t ?? []); +const getTag = (name: string) => DataStore.get(DATA_KEY).then((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 removeTag = (name: string) => { - settings.store.data.filter((t: Tag) => t.name !== name); +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; }; function createTagCommand(tag: Tag) { @@ -46,7 +53,7 @@ function createTagCommand(tag: Tag) { description: tag.name, inputType: ApplicationCommandInputType.BUILT_IN_TEXT, execute: async (_, ctx) => { - if (!getTag(tag.name)) { + if (!await getTag(tag.name)) { sendBotMessage(ctx.channel.id, { content: `${EMOTE} The tag **${tag.name}** does not exist anymore! Please reload ur Discord to fix :)` }); @@ -63,21 +70,6 @@ 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.", @@ -90,16 +82,9 @@ export default definePlugin({ default: true } }, - settings, async start() { - 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); - + for (const tag of await getTags()) createTagCommand(tag); }, commands: [ @@ -180,7 +165,7 @@ export default definePlugin({ }; createTagCommand(tag); - addTag(tag); + await addTag(tag); sendBotMessage(ctx.channel.id, { content: `${EMOTE} Successfully created the tag **${name}**!` @@ -196,7 +181,7 @@ export default definePlugin({ }); unregisterCommand(name); - removeTag(name); + await removeTag(name); sendBotMessage(ctx.channel.id, { content: `${EMOTE} Successfully deleted the tag **${name}**!` @@ -210,7 +195,7 @@ export default definePlugin({ // @ts-ignore title: "All Tags:", // @ts-ignore - description: settings.store.data + description: (await getTags()) .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 @@ -223,7 +208,7 @@ export default definePlugin({ } case "preview": { const name: string = findOption(args[0].options, "tag-name", ""); - const tag = getTag(name); + const tag = await getTag(name); if (!tag) return sendBotMessage(ctx.channel.id, { diff --git a/src/plugins/pinDms/index.tsx b/src/plugins/pinDms/index.tsx index fce725cab..8cbb03bfc 100644 --- a/src/plugins/pinDms/index.tsx +++ b/src/plugins/pinDms/index.tsx @@ -49,6 +49,7 @@ export const settings = definePluginSettings({ ], onChange: () => forceUpdate() }, + dmSectioncollapsed: { type: OptionType.BOOLEAN, description: "Collapse DM sections",