feat: saved flags

This commit is contained in:
nin0dev 2024-10-12 13:19:48 -04:00
parent 059301dcab
commit 8a5c874fe2
Signed by: nin0
GPG key ID: 3FA8F96ABAE04214

View file

@ -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; }) {
<div>
<Text
variant="text-md/semibold"
style={{ color: flags.get(id)?.type === "danger" ? "#f8312f" : flags.get(id)?.type === "warning" ? "#ffb02e" : flags.get(id)?.type === "info" ? "#62A8FF" : "#62FF74" }}
style={{ color: flags.get(id)?.type === "danger" ? "#FF7473" : flags.get(id)?.type === "warning" ? "#ffb02e" : flags.get(id)?.type === "info" ? "#62A8FF" : "#62FF74" }}
>
{flags.get(id)?.type === "danger" ? "🛑" : flags.get(id)?.type === "warning" ? "⚠️" : flags.get(id)?.type === "info" ? "🔵" : "✅"} {flags.get(id)?.text}
</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<string, Flag>(JSON.parse(savedFlags));
parsedFlags.forEach((value, key) => {
flags.set(key, value);
});
}
addAccessory("flag", (props: Record<string, any>) => {
if (flags.has((props.message as Message).author.id)) {
return <Flag id={props.message.author.id} />;
@ -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;
}
}