Bot: Partially implemented middlewares

This commit is contained in:
diamondburned (Forefront) 2020-05-10 01:45:00 -07:00
parent 67430c6d7a
commit e556d2afad
4 changed files with 17 additions and 6 deletions

View File

@ -217,13 +217,13 @@ func (ctx *Context) Subcommands() []*Subcommand {
return ctx.subcommands
}
// FindCommand finds a command based on the struct and method name. The queried
// FindMethod finds a method based on the struct and method name. The queried
// names will have their flags stripped.
//
// // Find a command from the main context:
// cmd := ctx.FindCommand("", "Method")
// cmd := ctx.FindMethod("", "Method")
// // Find a command from a subcommand:
// cmd = ctx.FindCommand("Starboard", "Reset")
// cmd = ctx.FindMethod("Starboard", "Reset")
//
func (ctx *Context) FindCommand(structname, methodname string) *MethodContext {
if structname == "" {

View File

@ -103,7 +103,7 @@ func TestContext(t *testing.T) {
})
t.Run("find commands", func(t *testing.T) {
cmd := ctx.FindCommand("", "NoArgs")
cmd := ctx.FindMethod("", "NoArgs")
if cmd == nil {
t.Fatal("Failed to find NoArgs")
}
@ -242,7 +242,7 @@ func TestContext(t *testing.T) {
t.Fatal("Unexpected call error:", err)
}
if cmd := ctx.FindCommand("testc", "Noop"); cmd == nil {
if cmd := ctx.FindMethod("testc", "Noop"); cmd == nil {
t.Fatal("Failed to find subcommand Noop")
}
})

View File

@ -0,0 +1,11 @@
package main
import "testing"
func TestAdminOnly(t *testing.T) {
t.Fatal("Do me.")
}
func TestGuildOnly(t *testing.T) {
t.Fatal("Do me.")
}

View File

@ -42,7 +42,7 @@ func TestSubcommand(t *testing.T) {
foundNoArgs bool
)
for _, this := range sub.Commands {
for _, this := range sub.Methods {
switch this.Command {
case "send":
foundSend = true