Bot: added the Hidden nameflag

This commit is contained in:
diamondburned (Forefront) 2020-01-25 14:30:15 -08:00
parent 9d5164be65
commit 0304ffaeb0
3 changed files with 19 additions and 1 deletions

View File

@ -111,6 +111,13 @@ func (ctx *Context) callCmd(ev interface{}) error {
}
}
// We call the messages later, since Hidden handlers will go into the Events
// slice, but we don't want to ignore those handlers either.
if evT == typeMessageCreate {
// safe assertion always
return ctx.callMessageCreate(ev.(*gateway.MessageCreateEvent))
}
return nil
}

View File

@ -37,6 +37,11 @@ const (
// Using this flag inside the subcommand will drop all methods (this is an
// undefined behavior/UB).
Middleware
// H - Hidden, which tells the router to not add this into the list of
// commands, hiding it from Help. Handlers that are hidden will not have any
// arguments parsed. It will be treated as an Event.
Hidden
)
func ParseFlag(name string) (NameFlag, string) {
@ -57,6 +62,8 @@ func ParseFlag(name string) (NameFlag, string) {
f |= GuildOnly
case 'M':
f |= Middleware
case 'H':
f |= Hidden
}
}

View File

@ -150,6 +150,10 @@ func (sub *Subcommand) Help(prefix, indent string, hideAdmin bool) string {
return ""
}
if len(sub.Commands) == 0 {
return ""
}
var subHelp string
if sub.Command != "" {
subHelp += indent + sub.Command
@ -309,7 +313,7 @@ func (sub *Subcommand) parseCommands() error {
}
// TODO: allow more flexibility
if command.event != typeMessageCreate {
if command.event != typeMessageCreate || flag.Is(Hidden) {
sub.Events = append(sub.Events, &command)
continue
}