fix all error and bug !!!!!!!!!!!!!

This commit is contained in:
Jay
2018-09-21 01:14:08 +08:00
parent 07436cd8df
commit 906b7be381
24 changed files with 133 additions and 109 deletions
+6 -1
View File
@@ -1,6 +1,7 @@
package msgcmd
import (
"fmt"
"strconv"
"strings"
@@ -23,6 +24,10 @@ func selectAct(cmd, sub, txt string, s *lineobj.SourceObject) (res string) {
return delFacebookPage(sub, txt, s)
case "deltwitch":
return delTwitchChannel(sub, txt, s)
case "image":
return fmt.Sprintf("$image$%s", sub)
case "hello":
return "World!!"
}
return
}
@@ -181,7 +186,7 @@ func addTwitchChannel(sub, txt string, s *lineobj.SourceObject) (res string) {
if ch == nil {
ch = &model.TwitchChannel{
ID: info.ID,
Name: info.DisplayName,
Name: info.Login,
}
err = ch.Add()
if err != nil {
+19 -3
View File
@@ -1,9 +1,12 @@
package msgcmd
import (
"fmt"
"regexp"
"strings"
"git.trj.tw/golang/mtfosbot/module/utils"
"git.trj.tw/golang/mtfosbot/model"
"git.trj.tw/golang/mtfosbot/module/apis/line"
@@ -23,10 +26,12 @@ func parseCMD(in string) (c [][]string) {
// ParseLineMsg -
func ParseLineMsg(txt, replyToken string, source *lineobj.SourceObject) {
fmt.Println("parse Line msg ;::: ", txt, utils.ToMap(source))
if source.Type != "group" {
return
}
strs := strings.Split(strings.Trim(txt, " "), " ")
fmt.Println(strs)
// skip empty string
if len(strs[0]) == 0 {
return
@@ -35,27 +40,36 @@ func ParseLineMsg(txt, replyToken string, source *lineobj.SourceObject) {
if strings.HasPrefix(strs[0], "!") || strings.HasPrefix(strs[0], "") {
// nor cmd
cmd := strs[0][1:]
fmt.Println(cmd)
if len(cmd) == 0 {
return
}
c, err := model.GetGroupCommand(cmd, source.GroupID)
c, err := model.GetGroupCommand(strings.ToLower(cmd), source.GroupID)
if err != nil || c == nil {
fmt.Println("get command fail ", err)
return
}
fmt.Println("get command ::::", utils.ToMap(c))
str := runCMD(strings.Join(strs[1:], " "), c.Message, source)
fmt.Println("cmd result ::::::", str)
m := parseResult(str)
fmt.Println("parsed cmd result :::::", m)
line.ReplyMessage(replyToken, m)
} else {
// key cmd
c, err := model.GetGroupKeyCommand(strs[0], source.GroupID)
c, err := model.GetGroupKeyCommand(strings.ToLower(strs[0]), source.GroupID)
if err != nil || c == nil {
fmt.Println("get command fail::::", err)
return
}
fmt.Println("get command ::::", utils.ToMap(c))
str := runCMD(strings.Join(strs[1:], " "), c.Message, source)
fmt.Println("cmd result ::::", str)
m := parseResult(str)
fmt.Println("parsed cmd result :::::", m)
line.ReplyMessage(replyToken, m)
}
@@ -81,6 +95,7 @@ func parseResult(str string) interface{} {
}
func runCMD(txt, c string, s *lineobj.SourceObject) (res string) {
fmt.Println("run run run::::::", txt, c, s)
cmdAct := parseCMD(c)
if len(cmdAct) == 0 {
return c
@@ -94,8 +109,9 @@ func runCMD(txt, c string, s *lineobj.SourceObject) (res string) {
if len(m) > 1 {
sub = strings.Join(m[1:], " ")
}
fmt.Println("run ::::::::", m[0], sub, txt)
cmdRes := selectAct(m[0], sub, txt, s)
res = strings.Replace(res, v[1], cmdRes, 1)
res = strings.Replace(res, v[0], cmdRes, 1)
}
}
return