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 v2
This commit is contained in:
parent
6ddf203609
commit
bc843c3625
2 changed files with 20 additions and 34 deletions
|
@ -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<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 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, {
|
||||
|
|
|
@ -49,6 +49,7 @@ export const settings = definePluginSettings({
|
|||
],
|
||||
onChange: () => forceUpdate()
|
||||
},
|
||||
|
||||
dmSectioncollapsed: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Collapse DM sections",
|
||||
|
|
Loading…
Add table
Reference in a new issue