slashCommand refresh impl starting

This commit is contained in:
jacoobes
2022-02-09 22:11:13 -06:00
parent 418bc90854
commit 9e93d38f05
2 changed files with 12 additions and 9 deletions

View File

@@ -24,8 +24,8 @@ export class Handler {
this.wrapper.client
.on("ready", async () => {
if (this.wrapper.init !== undefined) this.wrapper.init(this);
await Files.registerModules(this);
if (this.wrapper.init !== undefined) this.wrapper.init(this);
})
.on("messageCreate", async message => {
@@ -69,23 +69,18 @@ export class Handler {
if (parsedArgs.err) return parsedArgs.val;
const fn = await module.mod.delegate(context, parsedArgs);
return fn?.val;
}
}
private async commandResult(module: Files.CommandVal | undefined, message: Message, args: string): Promise<possibleOutput | undefined> {
if (module?.mod === undefined) return "Unknown legacy command";
if (module.mod.type === CommandType.SLASH) return `This may be a slash command and not a legacy command`
if (module.mod.visibility === "private") {
const checkIsTestServer = this.privateServers.find(({id}) => id === message.guildId!)?.test;
if(checkIsTestServer === undefined) return "This command has the private modifier but is not registered under Handler#privateServers";
if(checkIsTestServer !== module.testOnly) {
return "This private command is a testing command";
}
}
if (module.mod.type === CommandType.SLASH) return `This may be a slash command and not a legacy command`
}
const context = { message: Some(message), interaction: None }
const parsedArgs = module.mod.parse?.(context, ["text", args]) ?? Ok("");
if (parsedArgs.err) return parsedArgs.val;

View File

@@ -44,6 +44,14 @@ export async function registerModules(handler: Sern.Handler): Promise<void> {
case (1 | 2): {
const options = ((await import(absPath)).options as ApplicationCommandOptionData[])
Commands.set(cmdName, { mod, options: options ?? [], testOnly });
switch(mod.visibility) {
case "private" : {
//unimplemented
}
case "public" : {
//unimplemented
}
}
} break;
default: throw Error(`${name}.js is not a valid module type.`);
}