Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/command-abstractions/text-based-command-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ export type TextBasedCommandParameterOptions = {
autocomplete?: (partial: string, command_name: string) => { name: string; value: string }[];
};

export type CommandCategory =
| "Wiki Articles"
| "References"
| "Thread Control"
| "Utility"
| "Misc"
| "Moderation"
| "Moderation Utilities"
| "Admin utilities"
| "Hidden";

export enum EarlyReplyMode {
ephemeral,
visible,
Expand All @@ -38,7 +49,9 @@ export class TextBasedCommandBuilder<
descriptions!: ConditionalOptional<HasDescriptions, string[]>;
options = new Discord.Collection<string, TextBasedCommandParameterOptions & { type: TextBasedCommandOptionType }>();
slash_config: boolean[];
permissions: undefined | bigint = undefined;
permissions: bigint | undefined = undefined;
category: CommandCategory | undefined = undefined;
alias_of: string | undefined = undefined;
subcommands: TextBasedCommandBuilder<any, true, true>[] = [];
type: HasSubcommands extends true ? "top-level" : "default";
allow_trailing_junk: boolean = false;
Expand Down Expand Up @@ -212,6 +225,16 @@ export class TextBasedCommandBuilder<
return this;
}

set_category(category: CommandCategory) {
this.category = category;
return this;
}

set_alias_of(command_name: string) {
this.alias_of = command_name;
return this;
}

set_allow_trailing_junk(allow_trailing_junk: boolean) {
this.allow_trailing_junk = allow_trailing_junk;
return this;
Expand Down Expand Up @@ -245,10 +268,12 @@ export class TextBasedCommandBuilder<
descriptors.push(
new BotTextBasedCommand(
name,
name,
"",
description,
slash,
this.permissions,
this.category,
this.alias_of,
this.allow_trailing_junk,
this.early_reply_mode,
this,
Expand Down
18 changes: 15 additions & 3 deletions src/command-abstractions/text-based-command-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
TextBasedCommandOptionType,
TextBasedCommandBuilder,
EarlyReplyMode,
CommandCategory,
} from "./text-based-command-builder.js";
import { TextBasedCommand } from "./text-based-command.js";
import { BaseBotInteraction } from "./interaction-base.js";
Expand All @@ -23,20 +24,28 @@ export class BotTextBasedCommand<Args extends unknown[] = []> extends BaseBotInt
TextBasedCommandParameterOptions & { type: TextBasedCommandOptionType }
>();
public readonly subcommands: Discord.Collection<string, BotTextBasedCommand<any>> | null = null;
public readonly display_name: string;
public readonly all_names: string[];
public readonly all_display_names: string[];

constructor(
name: string,
public readonly display_name: string,
public readonly display_prefix: string,
public readonly description: string,
public readonly slash: boolean,
public readonly permissions: undefined | bigint,
public readonly category: CommandCategory | undefined,
public readonly alias_of: string | undefined,
public readonly allow_trailing_junk: boolean,
public readonly early_reply_mode: EarlyReplyMode,
builder: TextBasedCommandBuilder<Args, true, true> | TextBasedCommandBuilder<Args, true, false, true>,
protected readonly wheatley: Wheatley,
) {
super(name, builder.handler ?? (async () => wheatley.critical_error("This shouldn't happen")));
this.options = builder.options;
this.display_name = `${display_prefix}${name}`;
this.all_names = builder.names;
this.all_display_names = builder.names.map(name => `${display_prefix}${name}`);
if (builder.type === "top-level") {
this.subcommands = new Discord.Collection();
for (const subcommand of builder.subcommands) {
Expand All @@ -50,10 +59,12 @@ export class BotTextBasedCommand<Args extends unknown[] = []> extends BaseBotInt
sub_name,
new BotTextBasedCommand(
sub_name,
`${display_name} ${sub_name}`,
`${display_prefix}${name} `,
sub_description,
sub_slash,
permissions,
category,
subcommand.alias_of ?? alias_of,
allow_trailing_junk,
subcommand.early_reply_mode,
subcommand,
Expand Down Expand Up @@ -293,9 +304,10 @@ export class BotTextBasedCommand<Args extends unknown[] = []> extends BaseBotInt
if (this.subcommands) {
return this.subcommands.map(command => command.get_usage()).join("\n");
} else {
const command_part = `!${this.display_prefix}${this.all_names.join("/")}`;
return wrap(
[
"!" + this.display_name,
command_part,
...this.options.map(option => (option.required ? `<${option.title}>` : `[${option.title}]`)),
].join(" "),
"`",
Expand Down
4 changes: 4 additions & 0 deletions src/command-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export class CommandHandler {
return this.text_commands[command];
}

public get_all_commands() {
return this.text_commands;
}

//
// Command dispatch
//
Expand Down
1 change: 1 addition & 0 deletions src/components/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class Code extends BotComponent {
override async setup(commands: CommandSetBuilder) {
commands.add(
new TextBasedCommandBuilder("code", EarlyReplyMode.visible)
.set_category("Misc")
.set_description("code formatting help")
.set_allow_trailing_junk(true)
.set_handler(this.code.bind(this)),
Expand Down
2 changes: 2 additions & 0 deletions src/components/echo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class Echo extends BotComponent {
override async setup(commands: CommandSetBuilder) {
commands.add(
new TextBasedCommandBuilder("echo", EarlyReplyMode.none)
.set_category("Misc")
.set_description("Echo")
.add_string_option({
title: "input",
Expand All @@ -32,6 +33,7 @@ export default class Echo extends BotComponent {
);
commands.add(
new TextBasedCommandBuilder("say", EarlyReplyMode.none)
.set_category("Misc")
.set_permissions(Discord.PermissionFlagsBits.BanMembers)
.set_description("Say as wheatley")
.set_handler(this.say.bind(this)),
Expand Down
1 change: 1 addition & 0 deletions src/components/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class Google extends BotComponent {
override async setup(commands: CommandSetBuilder) {
commands.add(
new TextBasedCommandBuilder("google", EarlyReplyMode.none)
.set_category("Misc")
.set_description("google")
.add_string_option({
title: "query",
Expand Down
Loading