diff --git a/index.tsx b/index.tsx
index 0c02458..a1f9b2b 100644
--- a/index.tsx
+++ b/index.tsx
@@ -5,6 +5,7 @@
*/
import { ApplicationCommandInputType, ApplicationCommandOptionType, Argument, CommandContext, sendBotMessage } from "@api/Commands";
+import { DataStore } from "@api/index";
import { addAccessory } from "@api/MessageAccessories";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
@@ -22,7 +23,7 @@ function Flag({ id }: { id: string; }) {
{flags.get(id)?.type === "danger" ? "🛑" : flags.get(id)?.type === "warning" ? "⚠️" : flags.get(id)?.type === "info" ? "🔵" : "✅"} {flags.get(id)?.text}
@@ -35,7 +36,14 @@ export default definePlugin({
description: `Add "flags" to users that will always show under their messages`,
authors: [Devs.nin0dev],
dependencies: ["MessageAccessoriesAPI"],
- start() {
+ async start() {
+ const savedFlags = await DataStore.get("USERFLAGS");
+ if (savedFlags) {
+ const parsedFlags = new Map(JSON.parse(savedFlags));
+ parsedFlags.forEach((value, key) => {
+ flags.set(key, value);
+ });
+ }
addAccessory("flag", (props: Record) => {
if (flags.has((props.message as Message).author.id)) {
return ;
@@ -90,15 +98,15 @@ export default definePlugin({
required: true
},
],
- execute: (args: Argument[], ctx: CommandContext) => {
+ execute: async (args: Argument[], ctx: CommandContext) => {
flags.set(args[0].value, {
type: args[1].value as "danger" | "warning" | "info" | "positive",
text: args[2].value
});
sendBotMessage(ctx.channel.id, {
- content: `Flag added to <@${args[0].value}> with content \`${args[2].value}\`!`
+ content: `Flag set on <@${args[0].value}> with content \`${args[2].value}\`!`
});
- console.log(flags);
+ await DataStore.set("USERFLAGS", JSON.stringify(Array.from(flags.entries())));
return;
}
},
@@ -114,12 +122,12 @@ export default definePlugin({
required: true
}
],
- execute: (args: Argument[], ctx: CommandContext) => {
+ execute: async (args: Argument[], ctx: CommandContext) => {
flags.delete(args[0].value);
sendBotMessage(ctx.channel.id, {
content: `Flag removed from <@${args[0].value}>`
});
- console.log(flags);
+ await DataStore.set("USERFLAGS", JSON.stringify(Array.from(flags.entries())));
return;
}
}