2024-10-12 12:39:41 -04:00
|
|
|
/*
|
|
|
|
* Vencord, a Discord client mod
|
|
|
|
* Copyright (c) 2024 Vendicated and contributors
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { ApplicationCommandInputType, ApplicationCommandOptionType, Argument, CommandContext, sendBotMessage } from "@api/Commands";
|
2024-10-12 13:19:48 -04:00
|
|
|
import { DataStore } from "@api/index";
|
2024-10-12 12:39:41 -04:00
|
|
|
import { addAccessory } from "@api/MessageAccessories";
|
2024-10-06 15:01:19 -04:00
|
|
|
import { Devs } from "@utils/constants";
|
|
|
|
import definePlugin from "@utils/types";
|
2024-10-12 12:39:41 -04:00
|
|
|
import { React, Text } from "@webpack/common";
|
|
|
|
import { Message } from "discord-types/general";
|
|
|
|
|
|
|
|
const flags = new Map<string, Flag>();
|
|
|
|
type Flag = {
|
|
|
|
type: "danger" | "warning" | "info" | "positive";
|
|
|
|
text: string;
|
|
|
|
};
|
|
|
|
|
2024-10-12 12:57:36 -04:00
|
|
|
function Flag({ id }: { id: string; }) {
|
|
|
|
return (
|
2024-10-12 12:39:41 -04:00
|
|
|
<div>
|
2024-10-12 12:57:36 -04:00
|
|
|
<Text
|
2024-10-12 13:23:10 -04:00
|
|
|
variant="text-md/bold"
|
2024-10-12 13:19:48 -04:00
|
|
|
style={{ color: flags.get(id)?.type === "danger" ? "#FF7473" : flags.get(id)?.type === "warning" ? "#ffb02e" : flags.get(id)?.type === "info" ? "#62A8FF" : "#62FF74" }}
|
2024-10-12 12:57:36 -04:00
|
|
|
>
|
|
|
|
{flags.get(id)?.type === "danger" ? "🛑" : flags.get(id)?.type === "warning" ? "⚠️" : flags.get(id)?.type === "info" ? "🔵" : "✅"} {flags.get(id)?.text}
|
2024-10-12 12:39:41 -04:00
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2024-10-06 15:01:19 -04:00
|
|
|
|
|
|
|
export default definePlugin({
|
|
|
|
name: "UserFlags",
|
2024-10-12 12:39:41 -04:00
|
|
|
description: `Add "flags" to users that will always show under their messages`,
|
2024-10-06 15:01:19 -04:00
|
|
|
authors: [Devs.nin0dev],
|
2024-10-12 12:39:41 -04:00
|
|
|
dependencies: ["MessageAccessoriesAPI"],
|
2024-10-12 13:19:48 -04:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
2024-10-12 12:39:41 -04:00
|
|
|
addAccessory("flag", (props: Record<string, any>) => {
|
2024-10-12 12:57:36 -04:00
|
|
|
if (flags.has((props.message as Message).author.id)) {
|
|
|
|
return <Flag id={props.message.author.id} />;
|
|
|
|
}
|
|
|
|
return null;
|
2024-10-12 12:39:41 -04:00
|
|
|
}, 4);
|
|
|
|
},
|
|
|
|
commands: [
|
|
|
|
{
|
|
|
|
name: "flag set",
|
|
|
|
description: "Set a flag on a user",
|
|
|
|
inputType: ApplicationCommandInputType.BOT,
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: "user",
|
|
|
|
type: ApplicationCommandOptionType.USER,
|
|
|
|
description: "The user to set a flag to",
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "type",
|
|
|
|
"type": ApplicationCommandOptionType.STRING,
|
|
|
|
"description": "The type of flag to add",
|
|
|
|
choices: [
|
|
|
|
{
|
|
|
|
label: "Danger",
|
|
|
|
value: "danger",
|
|
|
|
name: "Danger"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Warning",
|
|
|
|
value: "warning",
|
|
|
|
name: "Warning"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Info",
|
|
|
|
value: "info",
|
|
|
|
name: "Info"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Positive",
|
|
|
|
value: "positive",
|
|
|
|
name: "Positive"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "message",
|
|
|
|
type: ApplicationCommandOptionType.STRING,
|
|
|
|
description: "The flag content",
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
],
|
2024-10-12 13:19:48 -04:00
|
|
|
execute: async (args: Argument[], ctx: CommandContext) => {
|
2024-10-12 12:39:41 -04:00
|
|
|
flags.set(args[0].value, {
|
|
|
|
type: args[1].value as "danger" | "warning" | "info" | "positive",
|
|
|
|
text: args[2].value
|
|
|
|
});
|
|
|
|
sendBotMessage(ctx.channel.id, {
|
2024-10-12 13:19:48 -04:00
|
|
|
content: `Flag set on <@${args[0].value}> with content \`${args[2].value}\`!`
|
2024-10-12 12:39:41 -04:00
|
|
|
});
|
2024-10-12 13:19:48 -04:00
|
|
|
await DataStore.set("USERFLAGS", JSON.stringify(Array.from(flags.entries())));
|
2024-10-12 12:39:41 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "flag delete",
|
|
|
|
description: "Delete the flag from a user",
|
|
|
|
inputType: ApplicationCommandInputType.BOT,
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: "user",
|
|
|
|
type: ApplicationCommandOptionType.USER,
|
|
|
|
description: "The user to delete the flag from",
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
],
|
2024-10-12 13:19:48 -04:00
|
|
|
execute: async (args: Argument[], ctx: CommandContext) => {
|
2024-10-12 12:39:41 -04:00
|
|
|
flags.delete(args[0].value);
|
|
|
|
sendBotMessage(ctx.channel.id, {
|
|
|
|
content: `Flag removed from <@${args[0].value}>`
|
|
|
|
});
|
2024-10-12 13:19:48 -04:00
|
|
|
await DataStore.set("USERFLAGS", JSON.stringify(Array.from(flags.entries())));
|
2024-10-12 12:39:41 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2024-10-06 15:01:19 -04:00
|
|
|
});
|
|
|
|
|