Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a389de2c77 | ||
|
|
bc86a36745 | ||
|
|
3151e1479a |
+14
-22
@@ -9,10 +9,10 @@ package disgoman
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/kballard/go-shellquote"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddCommand adds the Command at the address passed in to the Commands array on the CommandManager.
|
// AddCommand adds the Command at the address passed in to the Commands array on the CommandManager.
|
||||||
@@ -92,31 +92,23 @@ func (c *CommandManager) OnMessage(session *discordgo.Session, m *discordgo.Mess
|
|||||||
guild, _ := session.Guild(m.GuildID)
|
guild, _ := session.Guild(m.GuildID)
|
||||||
|
|
||||||
ctx := Context{
|
ctx := Context{
|
||||||
Session: session,
|
Session: session,
|
||||||
Channel: channel,
|
Channel: channel,
|
||||||
Message: m.Message,
|
Message: m.Message,
|
||||||
User: m.Author,
|
User: m.Author,
|
||||||
Guild: guild,
|
Guild: guild,
|
||||||
Member: m.Member,
|
Member: m.Member,
|
||||||
Invoked: "",
|
Invoked: "",
|
||||||
ErrorChannel: c.ErrorChannel,
|
CommandManager: c,
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd []string
|
var cmd []string
|
||||||
// If we found our prefix then remove it and split the command into pieces
|
// If we found our prefix then remove it and split the command into pieces
|
||||||
cmd, err = shellquote.Split(strings.TrimPrefix(content, prefix))
|
content = strings.TrimPrefix(content, prefix)
|
||||||
if err != nil {
|
r := regexp.MustCompile(`[^ "]+|"([^"]*)"`)
|
||||||
fmt.Println(err.Error())
|
cmd = r.FindAllString(content, -1)
|
||||||
if strings.Contains(err.Error(), "Unterminated") {
|
for i, val := range cmd {
|
||||||
cmd = strings.Split(strings.TrimPrefix(content, prefix), " ")
|
cmd[i] = strings.Trim(val, "\"")
|
||||||
} else {
|
|
||||||
c.ErrorChannel <- CommandError{
|
|
||||||
Context: ctx,
|
|
||||||
Message: "",
|
|
||||||
Error: err,
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cmd) < 1 {
|
if len(cmd) < 1 {
|
||||||
|
|||||||
+2
-2
@@ -80,6 +80,6 @@ type Context struct {
|
|||||||
Member *discordgo.Member
|
Member *discordgo.Member
|
||||||
// Name of the command as it was invoked (this is so you know what alias was used to call the command)
|
// Name of the command as it was invoked (this is so you know what alias was used to call the command)
|
||||||
Invoked string
|
Invoked string
|
||||||
// Error channel
|
// Command Manager
|
||||||
ErrorChannel chan CommandError
|
CommandManager *CommandManager
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user