duhhhhhhhh
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { ServerContentBase } from "../ContentBase.ts";
|
||||
import { CommandSender, CommandSenderType } from "./cmdtypes.ts";
|
||||
import type Command from "./command.ts";
|
||||
|
||||
export class CommandsBase extends ServerContentBase {
|
||||
@@ -18,12 +19,20 @@ export class CommandsBase extends ServerContentBase {
|
||||
this.#cmds.delete(cmd);
|
||||
}
|
||||
|
||||
async dispatch(...args: string[]): Promise<unknown> {
|
||||
async dispatch(sender: CommandSender, ...args: string[]): Promise<unknown> {
|
||||
if (sender.type == CommandSenderType.Profile)
|
||||
if (await sender.prof.getRole() !== "developer") return new Error("Unauthorized");
|
||||
|
||||
const root = args[0];
|
||||
if (typeof root !== 'string') return new Error("Root command must be of primitive type 'string'");
|
||||
else {
|
||||
if (root === "help") return JSON.stringify(this.#cmds.values()
|
||||
.map(cmd => cmd.getKey()).toArray()
|
||||
.reduce((prev, accumulator) => prev.concat(accumulator), []));
|
||||
|
||||
const cmd = this.#cmds.values().toArray().find(cmd => cmd.getKey().includes(root));
|
||||
if (cmd) {
|
||||
|
||||
const val = await cmd.dispatch(...args.slice(1));
|
||||
if (val == null) return "null";
|
||||
else if (typeof val == 'string') return `"${val}"`;
|
||||
|
||||
Reference in New Issue
Block a user