feat: saved flags
This commit is contained in:
parent
059301dcab
commit
8a5c874fe2
1 changed files with 15 additions and 7 deletions
22
index.tsx
22
index.tsx
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ApplicationCommandInputType, ApplicationCommandOptionType, Argument, CommandContext, sendBotMessage } from "@api/Commands";
|
import { ApplicationCommandInputType, ApplicationCommandOptionType, Argument, CommandContext, sendBotMessage } from "@api/Commands";
|
||||||
|
import { DataStore } from "@api/index";
|
||||||
import { addAccessory } from "@api/MessageAccessories";
|
import { addAccessory } from "@api/MessageAccessories";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
|
@ -22,7 +23,7 @@ function Flag({ id }: { id: string; }) {
|
||||||
<div>
|
<div>
|
||||||
<Text
|
<Text
|
||||||
variant="text-md/semibold"
|
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}
|
{flags.get(id)?.type === "danger" ? "🛑" : flags.get(id)?.type === "warning" ? "⚠️" : flags.get(id)?.type === "info" ? "🔵" : "✅"} {flags.get(id)?.text}
|
||||||
</Text>
|
</Text>
|
||||||
|
@ -35,7 +36,14 @@ export default definePlugin({
|
||||||
description: `Add "flags" to users that will always show under their messages`,
|
description: `Add "flags" to users that will always show under their messages`,
|
||||||
authors: [Devs.nin0dev],
|
authors: [Devs.nin0dev],
|
||||||
dependencies: ["MessageAccessoriesAPI"],
|
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>) => {
|
addAccessory("flag", (props: Record<string, any>) => {
|
||||||
if (flags.has((props.message as Message).author.id)) {
|
if (flags.has((props.message as Message).author.id)) {
|
||||||
return <Flag id={props.message.author.id} />;
|
return <Flag id={props.message.author.id} />;
|
||||||
|
@ -90,15 +98,15 @@ export default definePlugin({
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
execute: (args: Argument[], ctx: CommandContext) => {
|
execute: async (args: Argument[], ctx: CommandContext) => {
|
||||||
flags.set(args[0].value, {
|
flags.set(args[0].value, {
|
||||||
type: args[1].value as "danger" | "warning" | "info" | "positive",
|
type: args[1].value as "danger" | "warning" | "info" | "positive",
|
||||||
text: args[2].value
|
text: args[2].value
|
||||||
});
|
});
|
||||||
sendBotMessage(ctx.channel.id, {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -114,12 +122,12 @@ export default definePlugin({
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
execute: (args: Argument[], ctx: CommandContext) => {
|
execute: async (args: Argument[], ctx: CommandContext) => {
|
||||||
flags.delete(args[0].value);
|
flags.delete(args[0].value);
|
||||||
sendBotMessage(ctx.channel.id, {
|
sendBotMessage(ctx.channel.id, {
|
||||||
content: `Flag removed from <@${args[0].value}>`
|
content: `Flag removed from <@${args[0].value}>`
|
||||||
});
|
});
|
||||||
console.log(flags);
|
await DataStore.set("USERFLAGS", JSON.stringify(Array.from(flags.entries())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue