mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 15:35:11 +00:00
revert the changes that migrate datastore to array settings
This commit is contained in:
parent
0a96e1a508
commit
6ddf203609
4 changed files with 40 additions and 68 deletions
|
@ -34,10 +34,10 @@ interface Tag {
|
|||
|
||||
const getTag = (name: string) => settings.store.data.find((tt: Tag) => tt.name === name);
|
||||
const addTag = (tag: Tag) => {
|
||||
settings.store.data = [...settings.store.data, tag];
|
||||
settings.store.data.push(tag);
|
||||
};
|
||||
const removeTag = (name: string) => {
|
||||
settings.store.data = settings.store.data.filter((t: Tag) => t.name !== name);
|
||||
settings.store.data.filter((t: Tag) => t.name !== name);
|
||||
};
|
||||
|
||||
function createTagCommand(tag: Tag) {
|
||||
|
@ -64,16 +64,17 @@ function createTagCommand(tag: Tag) {
|
|||
|
||||
|
||||
const settings = definePluginSettings({
|
||||
clyde: {
|
||||
description: "If enabled, clyde will send you an ephemeral message when a tag was used.",
|
||||
type: OptionType.BOOLEAN,
|
||||
default: true
|
||||
},
|
||||
data: {
|
||||
type: OptionType.ARRAY,
|
||||
hidden: true,
|
||||
description: ""
|
||||
},
|
||||
migrated: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "",
|
||||
default: false,
|
||||
hidden: true
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
@ -81,16 +82,22 @@ export default definePlugin({
|
|||
name: "MessageTags",
|
||||
description: "Allows you to save messages and to use them with a simple command.",
|
||||
authors: [Devs.Luna],
|
||||
options: {
|
||||
clyde: {
|
||||
name: "Clyde message on send",
|
||||
description: "If enabled, clyde will send you an ephemeral message when a tag was used.",
|
||||
type: OptionType.BOOLEAN,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
settings,
|
||||
|
||||
async start() {
|
||||
const data = await DataStore.get(DATA_KEY);
|
||||
|
||||
if (data != null) {
|
||||
settings.store.data = data;
|
||||
await DataStore.del(DATA_KEY);
|
||||
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);
|
||||
|
||||
},
|
||||
|
|
|
@ -28,18 +28,19 @@ const OLD_CATEGORY_KEY = "BetterPinDMsCategories-";
|
|||
export let categories: Category[] = [];
|
||||
|
||||
export async function saveCats(cats: Category[]) {
|
||||
settings.store.data = cats;
|
||||
const { id } = UserStore.getCurrentUser();
|
||||
await DataStore.set(CATEGORY_BASE_KEY + id, cats);
|
||||
}
|
||||
|
||||
export async function init() {
|
||||
const id = UserStore.getCurrentUser()?.id;
|
||||
await initCategories();
|
||||
await initCategories(id);
|
||||
await migrateData(id);
|
||||
forceUpdate();
|
||||
}
|
||||
|
||||
export async function initCategories() {
|
||||
categories = settings.store.data ?? [];
|
||||
export async function initCategories(userId: string) {
|
||||
categories = await DataStore.get<Category[]>(CATEGORY_BASE_KEY + userId) ?? [];
|
||||
}
|
||||
|
||||
export function getCategory(id: string) {
|
||||
|
@ -206,22 +207,13 @@ async function migrateOldCategories(userId: string) {
|
|||
await DataStore.set(CATEGORY_MIGRATED_KEY, true);
|
||||
}
|
||||
|
||||
async function migrateFromDatastore(userId: string) {
|
||||
const cats = await DataStore.get<Category[]>(CATEGORY_BASE_KEY + userId);
|
||||
if (cats !== undefined) settings.store.data = cats;
|
||||
}
|
||||
|
||||
export async function migrateData(userId: string) {
|
||||
if (settings.store.data.length > 0) return;
|
||||
const m1 = await DataStore.get(CATEGORY_MIGRATED_KEY), m2 = await DataStore.get(CATEGORY_MIGRATED_PINDMS_KEY);
|
||||
if (m1 && m2) {
|
||||
return await migrateFromDatastore(userId);
|
||||
}
|
||||
if (m1 && m2) return;
|
||||
|
||||
// want to migrate the old categories first and then slove any conflicts with the PinDMs pins
|
||||
if (!m1) await migrateOldCategories(userId);
|
||||
if (!m2) await migratePinDMs();
|
||||
if (settings.store.data.length === 0) await migrateFromDatastore(userId);
|
||||
|
||||
await saveCats(categories);
|
||||
}
|
||||
|
|
|
@ -54,12 +54,7 @@ export const settings = definePluginSettings({
|
|||
description: "Collapse DM sections",
|
||||
default: false,
|
||||
onChange: () => forceUpdate()
|
||||
},
|
||||
data: {
|
||||
type: OptionType.ARRAY,
|
||||
hidden: true,
|
||||
description: "",
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
export default definePlugin({
|
||||
|
|
|
@ -46,6 +46,9 @@ const makeEmptyRule: () => Rule = () => ({
|
|||
});
|
||||
const makeEmptyRuleArray = () => [makeEmptyRule()];
|
||||
|
||||
let stringRules = makeEmptyRuleArray();
|
||||
let regexRules = makeEmptyRuleArray();
|
||||
|
||||
const settings = definePluginSettings({
|
||||
replace: {
|
||||
type: OptionType.COMPONENT,
|
||||
|
@ -56,13 +59,13 @@ const settings = definePluginSettings({
|
|||
<>
|
||||
<TextReplace
|
||||
title="Using String"
|
||||
rulesArray={settings.store.stringRules}
|
||||
rulesArray={stringRules}
|
||||
rulesKey={STRING_RULES_KEY}
|
||||
update={update}
|
||||
/>
|
||||
<TextReplace
|
||||
title="Using Regex"
|
||||
rulesArray={settings.store.regexRules}
|
||||
rulesArray={regexRules}
|
||||
rulesKey={REGEX_RULES_KEY}
|
||||
update={update}
|
||||
/>
|
||||
|
@ -71,16 +74,6 @@ const settings = definePluginSettings({
|
|||
);
|
||||
}
|
||||
},
|
||||
stringRules: {
|
||||
type: OptionType.ARRAY,
|
||||
hidden: true,
|
||||
description: ""
|
||||
},
|
||||
regexRules: {
|
||||
type: OptionType.ARRAY,
|
||||
hidden: true,
|
||||
description: ""
|
||||
},
|
||||
});
|
||||
|
||||
function stringToRegex(str: string) {
|
||||
|
@ -134,8 +127,7 @@ function TextReplace({ title, rulesArray, rulesKey, update }: TextReplaceProps)
|
|||
if (index === rulesArray.length - 1) return;
|
||||
rulesArray.splice(index, 1);
|
||||
|
||||
if (rulesKey === STRING_RULES_KEY) settings.store.stringRules = [...rulesArray];
|
||||
else settings.store.regexRules = [...rulesArray];
|
||||
await DataStore.set(rulesKey, rulesArray);
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -148,8 +140,7 @@ function TextReplace({ title, rulesArray, rulesKey, update }: TextReplaceProps)
|
|||
if (rulesArray[index].find === "" && rulesArray[index].replace === "" && rulesArray[index].onlyIfIncludes === "" && index !== rulesArray.length - 1)
|
||||
rulesArray.splice(index, 1);
|
||||
|
||||
if (rulesKey === STRING_RULES_KEY) settings.store.stringRules = [...rulesArray];
|
||||
else settings.store.regexRules = [...rulesArray];
|
||||
await DataStore.set(rulesKey, rulesArray);
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -220,8 +211,8 @@ function applyRules(content: string): string {
|
|||
if (content.length === 0)
|
||||
return content;
|
||||
|
||||
if (settings.store.stringRules) {
|
||||
for (const rule of settings.store.stringRules) {
|
||||
if (stringRules) {
|
||||
for (const rule of stringRules) {
|
||||
if (!rule.find) continue;
|
||||
if (rule.onlyIfIncludes && !content.includes(rule.onlyIfIncludes)) continue;
|
||||
|
||||
|
@ -229,8 +220,8 @@ function applyRules(content: string): string {
|
|||
}
|
||||
}
|
||||
|
||||
if (settings.store.regexRules) {
|
||||
for (const rule of settings.store.regexRules) {
|
||||
if (regexRules) {
|
||||
for (const rule of regexRules) {
|
||||
if (!rule.find) continue;
|
||||
if (rule.onlyIfIncludes && !content.includes(rule.onlyIfIncludes)) continue;
|
||||
|
||||
|
@ -258,21 +249,8 @@ export default definePlugin({
|
|||
settings,
|
||||
|
||||
async start() {
|
||||
|
||||
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();
|
||||
}
|
||||
stringRules = await DataStore.get(STRING_RULES_KEY) ?? makeEmptyRuleArray();
|
||||
regexRules = await DataStore.get(REGEX_RULES_KEY) ?? makeEmptyRuleArray();
|
||||
|
||||
this.preSend = addPreSendListener((channelId, msg) => {
|
||||
// Channel used for sharing rules, applying rules here would be messy
|
||||
|
|
Loading…
Add table
Reference in a new issue