add cdmparser
This commit is contained in:
parent
30d38d6d20
commit
8fe40c92f4
59
pkg/cmdparser/cmdparser.go
Normal file
59
pkg/cmdparser/cmdparser.go
Normal 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) {
|
||||
}
|
@ -78,7 +78,6 @@ func messageCreateEvt(s *discordgo.Session, evt *discordgo.MessageCreate) {
|
||||
}
|
||||
c := cmds[0]
|
||||
|
||||
// TODO: check user role group
|
||||
if c.RequireManage && server.Owner != uid {
|
||||
roles, err := server.GetRoleList()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user