1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-28 01:33:10 +00:00

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 return nil
} }

View file

@ -37,6 +37,11 @@ const (
// Using this flag inside the subcommand will drop all methods (this is an // Using this flag inside the subcommand will drop all methods (this is an
// undefined behavior/UB). // undefined behavior/UB).
Middleware 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) { func ParseFlag(name string) (NameFlag, string) {
@ -57,6 +62,8 @@ func ParseFlag(name string) (NameFlag, string) {
f |= GuildOnly f |= GuildOnly
case 'M': case 'M':
f |= Middleware f |= Middleware
case 'H':
f |= Hidden
} }
} }

View file

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