change cmd parser to discord package
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package discord
|
||||
|
||||
// SendDiscordMessage -
|
||||
func SendDiscordMessage(channel string) (err error) {
|
||||
return
|
||||
}
|
||||
+10
-29
@@ -3,6 +3,7 @@ package discord
|
||||
import (
|
||||
dsmodel "dorisbot/models/discord"
|
||||
pubmodel "dorisbot/models/public"
|
||||
"dorisbot/pkg/cmdparser"
|
||||
"log"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
@@ -36,36 +37,12 @@ func messageCreateEvt(s *discordgo.Session, evt *discordgo.MessageCreate) {
|
||||
return
|
||||
}
|
||||
|
||||
var cmdmodel *pubmodel.CommandModel
|
||||
var acts []*cmdparser.CmdAction
|
||||
|
||||
// discord server not init
|
||||
if server == nil {
|
||||
cmds, err := pubmodel.GetGlobalCommand(cmd)
|
||||
if err != nil {
|
||||
log.Println("get command fail :: ", err)
|
||||
return
|
||||
}
|
||||
if len(cmds) == 0 {
|
||||
log.Printf("no command found {%s}\n", cmd)
|
||||
return
|
||||
}
|
||||
c := cmds[0]
|
||||
if c.RequireInit {
|
||||
log.Printf("{%s} require init server\n", cmd)
|
||||
return
|
||||
}
|
||||
|
||||
if c.RequireManage {
|
||||
ginfo, err := s.Guild(guildID)
|
||||
if err != nil {
|
||||
log.Println("get guild info err :: ", err)
|
||||
return
|
||||
}
|
||||
if ginfo.OwnerID != uid {
|
||||
log.Printf("{%s} require manage permission\n", cmd)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: command parser
|
||||
cmdmodel, acrs, err = getNotInitServerCommandAction(s, evt, cmd)
|
||||
} else {
|
||||
cmds, err := pubmodel.GetCommandByPlatformBinding(cmd, server.ID, "discord")
|
||||
if err != nil {
|
||||
@@ -112,9 +89,13 @@ func messageCreateEvt(s *discordgo.Session, evt *discordgo.MessageCreate) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: command parser
|
||||
cmdmodel = c
|
||||
acts = cmdparser.ParseCmdAction(cmdmodel.Value)
|
||||
}
|
||||
|
||||
if len(acts) == 0 {
|
||||
// TODO: response cmd value
|
||||
}
|
||||
}
|
||||
|
||||
func guildMemberAddEvt(s *discordgo.Session, evt *discordgo.GuildMemberAdd) {}
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
package discord
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
pubmodel "dorisbot/models/public"
|
||||
"dorisbot/pkg/cmdparser"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var tagRagexp = regexp.MustCompile("<@([0-9]+)>")
|
||||
@@ -40,6 +48,41 @@ func getCMD(str string) (cmd string, keyword bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func getNotInitServerCommandAction(s discordgo.Session, msgEvt *discordgo.MessageCreate, cmd string) (c *pubmodel.CommandModel, acts []*cmdparser.CmdAction, err error) {
|
||||
cmds, err := pubmodel.GetGlobalCommand(cmd)
|
||||
if err != nil {
|
||||
log.Println("get command fail :: ", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
if len(cmds) == 0 {
|
||||
s := fmt.Sprintf("no command found {%s}", cmd)
|
||||
log.Println(s)
|
||||
return nil, nil, errors.New(s)
|
||||
}
|
||||
c := cmds[0]
|
||||
if c.RequireInit {
|
||||
s := fmt.Sprintf("{%s} require init server", cmd)
|
||||
log.Println(s)
|
||||
return nil, nil, errors.New(s)
|
||||
}
|
||||
|
||||
if c.RequireManage {
|
||||
ginfo, err := s.Guild(guildID)
|
||||
if err != nil {
|
||||
log.Println("get guild info err :: ", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
if ginfo.OwnerID != uid {
|
||||
s := fmt.Sprintf("{%s} require manage permission", cmd)
|
||||
log.Println(s)
|
||||
return nil, nil, errors.New(s)
|
||||
}
|
||||
}
|
||||
|
||||
acts = cmdparser.ParseCmdAction(cmdmodel.Value)
|
||||
return c, acts, nil
|
||||
}
|
||||
|
||||
func parseTextMessage(msg string) (cmd string, keyword bool, payload string) {
|
||||
tagBot := getTagBot(msg)
|
||||
_ = tagBot
|
||||
@@ -53,3 +96,10 @@ func parseTextMessage(msg string) (cmd string, keyword bool, payload string) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func selectAction(key, value, payload string) {
|
||||
switch key {
|
||||
case "ds_addserver":
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user