fixed error message
This commit is contained in:
parent
8555a686a6
commit
eff943a715
@ -1,8 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
@ -29,20 +27,20 @@ type CommandMux struct {
|
|||||||
|
|
||||||
func NewCommandMux() *CommandMux { return new(CommandMux) }
|
func NewCommandMux() *CommandMux { return new(CommandMux) }
|
||||||
|
|
||||||
func (c *CommandMux) removeFirst(command string) (string, error) {
|
func (c *CommandMux) removeFirst(command string) string {
|
||||||
split := strings.SplitN(strings.TrimSpace(command), " ", 2)
|
split := strings.SplitN(strings.TrimSpace(command), " ", 2)
|
||||||
if len(split) > 1 {
|
if len(split) > 1 {
|
||||||
return split[1], nil
|
return split[1]
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("separation impossible on string: %s", command)
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CommandMux) firstCommand(command string) (string, error) {
|
func (c *CommandMux) firstCommand(command string) string {
|
||||||
split := strings.SplitN(strings.TrimSpace(command), " ", 2)
|
split := strings.SplitN(strings.TrimSpace(command), " ", 2)
|
||||||
if len(split) > 0 {
|
if len(split) > 0 {
|
||||||
return split[0], nil
|
return split[0]
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("separation impossible on string: %s", command)
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CommandMux) Handler(m *discordgo.MessageCreate) (cmd Command, pattern string) {
|
func (c *CommandMux) Handler(m *discordgo.MessageCreate) (cmd Command, pattern string) {
|
||||||
@ -54,15 +52,8 @@ func (c *CommandMux) Handler(m *discordgo.MessageCreate) (cmd Command, pattern s
|
|||||||
return c.m[c.prefix].h, c.m[c.prefix].pattern
|
return c.m[c.prefix].h, c.m[c.prefix].pattern
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := c.removeFirst(m.Content) /* Here the prefix is removed, so we're left with only the first keyword */
|
m := c.removeFirst(m.Content) /* Here the prefix is removed, so we're left with only the first keyword */
|
||||||
if err != nil {
|
cmd, ok := c.m[c.firstCommand(m)]
|
||||||
return nil, ""
|
|
||||||
}
|
|
||||||
fc, err := c.firstCommand(m)
|
|
||||||
if err != nil {
|
|
||||||
return nil, ""
|
|
||||||
}
|
|
||||||
cmd, ok := c.m[fc]
|
|
||||||
if ok {
|
if ok {
|
||||||
return cmd.h, cmd.pattern
|
return cmd.h, cmd.pattern
|
||||||
}
|
}
|
||||||
@ -75,7 +66,7 @@ func (c *CommandMux) Handler(m *discordgo.MessageCreate) (cmd Command, pattern s
|
|||||||
func (c *CommandMux) Execute(s *discordgo.Session, m *discordgo.MessageCreate) {
|
func (c *CommandMux) Execute(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
h, _ := c.Handler(m)
|
h, _ := c.Handler(m)
|
||||||
if h == nil {
|
if h == nil {
|
||||||
log.Printf("There exists no handler for %s\n", m.Content)
|
//log.Printf("There exists no handler for %s\n", m.Content)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.Execute(s, m)
|
h.Execute(s, m)
|
||||||
|
@ -4,7 +4,7 @@ import "github.com/bwmarrin/discordgo"
|
|||||||
|
|
||||||
func (app *application) LogToConsole(next Command) Command {
|
func (app *application) LogToConsole(next Command) Command {
|
||||||
fn := func(s *discordgo.Session, m *discordgo.MessageCreate) {
|
fn := func(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
app.infoLog.Printf("%s \tsaid: %s\n", m.Author.Username, m.Content)
|
app.infoLog.Printf("%s \tsaid: %s\n", m.Author.Username, m.Content)
|
||||||
next.Execute(s, m)
|
next.Execute(s, m)
|
||||||
}
|
}
|
||||||
return HandlerFunc(fn)
|
return HandlerFunc(fn)
|
||||||
|
Loading…
Reference in New Issue
Block a user