add es log
This commit is contained in:
@@ -2,12 +2,15 @@ package linemsg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"git.trj.tw/golang/mtfosbot/model"
|
||||
"git.trj.tw/golang/mtfosbot/module/apis/line"
|
||||
"git.trj.tw/golang/mtfosbot/module/config"
|
||||
"git.trj.tw/golang/mtfosbot/module/es"
|
||||
lineobj "git.trj.tw/golang/mtfosbot/module/line-message/line-object"
|
||||
msgcmd "git.trj.tw/golang/mtfosbot/module/message-command"
|
||||
)
|
||||
@@ -91,6 +94,7 @@ func saveTextMsgToLog(txt string, s *lineobj.SourceObject) {
|
||||
return
|
||||
}
|
||||
|
||||
go saveLineMessageLogToES(s.GroupID, s.UserID, txt, "text")
|
||||
model.AddLineMessageLog(s.GroupID, s.UserID, txt, "text")
|
||||
}
|
||||
|
||||
@@ -137,5 +141,41 @@ func saveImageMsgToLog(id string, s *lineobj.SourceObject) {
|
||||
return
|
||||
}
|
||||
|
||||
furl, err := url.Parse(conf.URL)
|
||||
if err == nil {
|
||||
furl, err = furl.Parse(fmt.Sprintf("/image/line_log_image/%s", fname))
|
||||
if err == nil {
|
||||
fname = furl.String()
|
||||
}
|
||||
}
|
||||
|
||||
go saveLineMessageLogToES(s.GroupID, s.UserID, fname, "image")
|
||||
model.AddLineMessageLog(s.GroupID, s.UserID, fname, "image")
|
||||
}
|
||||
|
||||
func saveLineMessageLogToES(gid, uid, content, msgType string) {
|
||||
lineGroup, err := model.GetLineGroup(gid)
|
||||
if err != nil {
|
||||
log.Println("get line group error :: ", err)
|
||||
return
|
||||
}
|
||||
lineUser, err := model.GetLineUserByID(uid)
|
||||
if err != nil {
|
||||
log.Println("get line user error :: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
logMsg := make(map[string]interface{})
|
||||
|
||||
logMsg["message"] = content
|
||||
logMsg["type"] = msgType
|
||||
logMsg["group"] = lineGroup.ID
|
||||
logMsg["group_name"] = lineGroup.Name
|
||||
logMsg["user"] = lineUser.ID
|
||||
logMsg["user_name"] = lineUser.Name
|
||||
|
||||
err = es.PutLog("log", logMsg)
|
||||
if err != nil {
|
||||
log.Println("put log fail :: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user