apps/bot/src/feats/proxy/index.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
import { option } from "@purrkit/router";
import { editActor } from "@stealth-developers/db";
import { errorMessage, upsertUser } from "@/lib";
import { useGetData } from "@/middleware";
import { glorpify, uwuify } from "./lib";
const proxyGroup = useGetData.command("proxy", {
description: "uwuify & glorpify related commands",
});
const proxyConfigurations: {
name: "glorpify" | "uwuify";
formatter: (text: string) => string;
}[] = [
{ name: "glorpify", formatter: glorpify },
{ name: "uwuify", formatter: uwuify },
];
for (const { name, formatter } of proxyConfigurations) {
proxyGroup.subcommand(name, {
description: formatter(`Enable ${name}`),
options: {
user: option.user(formatter(`The user to enable ${name} for`), { required: false }),
},
async run(interaction, { user: target }, { actor }) {
if (target && !actor?.moderator)
return errorMessage(
interaction,
formatter(`You must be a moderator to enable ${name} for another user.`),
);
if (!interaction.guild)
return errorMessage(interaction, formatter(`This command can only be used in a server.`));
const proxyActor = target ? (await upsertUser(target, interaction.guild))?.actor : actor;
if (!proxyActor)
return errorMessage(interaction, formatter(`Failed to find your user data.`));
await editActor(proxyActor.id, {
proxy: name,
});
return interaction.reply({
content: formatter(`Enabled ${name} for ${target ? target : "you"}`),
flags: ["Ephemeral"],
});
},
});
}
proxyGroup.subcommand("disable", {
description: "Disable proxy",
options: {
user: option.user("The user to disable proxy for", { required: false }),
},
async run(interaction, { user: target }, { actor }) {
if (target && !actor?.moderator)
return errorMessage(
interaction,
`You must be a moderator to disable proxy for another user.`,
);
if (!interaction.guild)
return errorMessage(interaction, `This command can only be used in a server.`);
const proxyActor = target ? (await upsertUser(target, interaction.guild))?.actor : actor;
if (!proxyActor) return errorMessage(interaction, `Failed to find your user data.`);
await editActor(proxyActor.id, {
proxy: null,
});
return interaction.reply({
content: `Disabled proxy for ${target ? target : "you"}`,
flags: ["Ephemeral"],
});
},
});
export const proxyCommands = [proxyGroup];
|