GoonCord/src/core/commands/plugins.ts
2024-06-25 02:28:04 +08:00

42 lines
1.6 KiB
TypeScript

import { Strings } from "@core/i18n";
import { ApplicationCommand, ApplicationCommandOptionType } from "@lib/api/commands/types";
import { BunnyPlugin, sourceStore as pluginStorage } from "@lib/managers/plugins";
import { messageUtil } from "@metro/common";
export default () => <ApplicationCommand>{
name: "plugins",
description: Strings.COMMAND_PLUGINS_DESC,
options: [
{
name: "ephemeral",
displayName: "ephemeral",
type: ApplicationCommandOptionType.BOOLEAN,
description: Strings.COMMAND_DEBUG_OPT_EPHEMERALLY,
}
],
execute([ephemeral], ctx) {
const plugins = Object.values(pluginStorage).filter(Boolean) as unknown as BunnyPlugin[];
plugins.sort((a, b) => a.manifest.name.localeCompare(b.manifest.name));
const enabled = plugins.filter(p => p.enabled).map(p => p.manifest.name);
const disabled = plugins.filter(p => !p.enabled).map(p => p.manifest.name);
const content = [
`**Installed Plugins (${plugins.length}):**`,
...(enabled.length > 0 ? [
`Enabled (${enabled.length}):`,
"> " + enabled.join(", "),
] : []),
...(disabled.length > 0 ? [
`Disabled (${disabled.length}):`,
"> " + disabled.join(", "),
] : []),
].join("\n");
if (ephemeral?.value) {
messageUtil.sendBotMessage(ctx.channel.id, content);
} else {
messageUtil.sendMessage(ctx.channel.id, { content });
}
}
};