mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-03-22 09:59:37 +00:00
Bot: Partially implemented middlewares
This commit is contained in:
parent
67430c6d7a
commit
e556d2afad
|
@ -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 == "" {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
})
|
||||
|
|
11
bot/extras/middlewares/test.go
Normal file
11
bot/extras/middlewares/test.go
Normal 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.")
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue