add cdmparser

This commit is contained in:
Jay 2019-07-03 09:58:38 +00:00
parent 30d38d6d20
commit 8fe40c92f4
2 changed files with 59 additions and 1 deletions

View File

@ -0,0 +1,59 @@
package cmdparser
import "regexp"
// CommandType -
type CommandType int
// Cmd Types
const (
TextCmd CommandType = 1 << iota
ImageCmd
VideoCmd
)
// Command -
type Command struct {
Type CommandType
Message string
}
// CmdAction -
type CmdAction struct {
Key string
Act string
}
var actRegex = regexp.MustCompile("{{(.+?)}}")
// CommandParser -
func CommandParser(value string) (cmd *Command, err error) {
acts := parseCmdAction(value)
if len(acts) == 0 {
// no get actions return origin value
return &Command{
Type: TextCmd,
Message: value,
}, nil
}
return
}
func parseCmdAction(value string) (acts []*CmdAction) {
strs := actRegex.FindAllStringSubmatch(value, -1)
if len(strs) == 0 {
return nil
}
acts = make([]*CmdAction, 0, len(strs))
for _, key := range strs {
acts = append(acts, &CmdAction{Key: key[1]})
}
return
}
func selectAction(act *CmdAction) {
}

View File

@ -78,7 +78,6 @@ func messageCreateEvt(s *discordgo.Session, evt *discordgo.MessageCreate) {
} }
c := cmds[0] c := cmds[0]
// TODO: check user role group
if c.RequireManage && server.Owner != uid { if c.RequireManage && server.Owner != uid {
roles, err := server.GetRoleList() roles, err := server.GetRoleList()
if err != nil { if err != nil {