From e6188b7cc5c4c9feb301f6cae877e2514c471875 Mon Sep 17 00:00:00 2001 From: Elvyra <88881326+EepyElvyra@users.noreply.github.com> Date: Tue, 14 Jan 2025 02:19:40 +0100 Subject: [PATCH] fix textreplace migration --- src/plugins/textReplace/index.tsx | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/plugins/textReplace/index.tsx b/src/plugins/textReplace/index.tsx index 04500b746..f5426dc4c 100644 --- a/src/plugins/textReplace/index.tsx +++ b/src/plugins/textReplace/index.tsx @@ -81,12 +81,6 @@ const settings = definePluginSettings({ hidden: true, description: "" }, - migrated: { - type: OptionType.BOOLEAN, - hidden: true, - default: false, - description: "" - } }); function stringToRegex(str: string) { @@ -264,13 +258,20 @@ export default definePlugin({ settings, async start() { - if (!settings.store.migrated) { - const stringRules = await DataStore.get(STRING_RULES_KEY) ?? makeEmptyRuleArray(); - const regexRules = await DataStore.get(REGEX_RULES_KEY) ?? makeEmptyRuleArray(); - settings.store.stringRules = stringRules; - settings.store.regexRules = regexRules; - settings.store.migrated = true; + if (settings.store.stringRules.length === 0 || settings.store.regexRules.length === 0) { + const stringRules = await DataStore.get(STRING_RULES_KEY); + const regexRules = await DataStore.get(REGEX_RULES_KEY); + + if (stringRules != null) { + settings.store.stringRules = stringRules; + await DataStore.del(STRING_RULES_KEY); + } else if (settings.store.stringRules.length === 0) settings.store.stringRules = makeEmptyRuleArray(); + + if (regexRules != null) { + settings.store.regexRules = regexRules; + await DataStore.del(REGEX_RULES_KEY); + } else if (settings.store.regexRules.length === 0) settings.store.regexRules = makeEmptyRuleArray(); } this.preSend = addPreSendListener((channelId, msg) => {