diff --git a/bot/subcommand.go b/bot/subcommand.go index 0b889f8..7e77ad4 100644 --- a/bot/subcommand.go +++ b/bot/subcommand.go @@ -35,6 +35,7 @@ type Subcommand struct { // All registered command contexts: Commands []*CommandContext + Events []*CommandContext // Middleware command contexts: mwMethods []*CommandContext @@ -216,7 +217,6 @@ func (sub *Subcommand) fillStruct(ctx *Context) error { func (sub *Subcommand) parseCommands() error { var numMethods = sub.ptrValue.NumMethod() - var commands = make([]*CommandContext, 0, numMethods) for i := 0; i < numMethods; i++ { method := sub.ptrValue.Method(i) @@ -268,9 +268,16 @@ func (sub *Subcommand) parseCommands() error { command.Command = strings.ToLower(name) } + // Middlewares shouldn't even have arguments. + if flag.Is(Middleware) { + sub.mwMethods = append(sub.mwMethods, &command) + continue + } + // TODO: allow more flexibility if command.event != typeMessageCreate { - goto Done + sub.Events = append(sub.Events, &command) + continue } // If the method only takes an event: @@ -279,11 +286,6 @@ func (sub *Subcommand) parseCommands() error { goto Done } - // Middlewares shouldn't even have arguments. - if flag.Is(Middleware) { - goto Done - } - // If the second argument implements ParseContent() if t := methodT.In(1); t.Implements(typeIManP) { mt, _ := t.MethodByName("ParseContent") @@ -315,13 +317,8 @@ func (sub *Subcommand) parseCommands() error { Done: // Append - if flag.Is(Middleware) { - sub.mwMethods = append(sub.mwMethods, &command) - } else { - commands = append(commands, &command) - } + sub.Commands = append(sub.Commands, &command) } - sub.Commands = commands return nil }