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:
parent
9d5164be65
commit
0304ffaeb0
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue