add pre group one bot setting
This commit is contained in:
+23
-6
@@ -7,9 +7,9 @@ import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
|
||||
"git.trj.tw/golang/mtfosbot/module/config"
|
||||
"git.trj.tw/golang/mtfosbot/model"
|
||||
"git.trj.tw/golang/mtfosbot/module/context"
|
||||
"git.trj.tw/golang/mtfosbot/module/line-message"
|
||||
linemsg "git.trj.tw/golang/mtfosbot/module/line-message"
|
||||
lineobj "git.trj.tw/golang/mtfosbot/module/line-message/line-object"
|
||||
)
|
||||
|
||||
@@ -42,10 +42,21 @@ func VerifyLine(c *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
conf := config.GetConf()
|
||||
botid, ok := c.GetQuery("id")
|
||||
if !ok || len(botid) == 0 {
|
||||
c.CustomRes(403, map[string]string{
|
||||
"message": "no bot data",
|
||||
})
|
||||
}
|
||||
|
||||
hash := hmac.New(sha256.New, []byte(conf.Line.Secret))
|
||||
_, err := hash.Write(raw)
|
||||
bot, err := model.GetBotInfo(botid)
|
||||
if err != nil {
|
||||
c.ServerError(nil)
|
||||
return
|
||||
}
|
||||
|
||||
hash := hmac.New(sha256.New, []byte(bot.Secret))
|
||||
_, err = hash.Write(raw)
|
||||
if err != nil {
|
||||
c.ServerError(nil)
|
||||
return
|
||||
@@ -70,6 +81,12 @@ func GetLineMessage(c *context.Context) {
|
||||
if raw, ok = rawbody.([]byte); !ok {
|
||||
c.DataFormat("body type error")
|
||||
}
|
||||
botid, ok := c.GetQuery("id")
|
||||
if !ok || len(botid) == 0 {
|
||||
c.CustomRes(403, map[string]string{
|
||||
"message": "no bot data",
|
||||
})
|
||||
}
|
||||
|
||||
events := struct {
|
||||
Events []*lineobj.EventObject `json:"events"`
|
||||
@@ -83,7 +100,7 @@ func GetLineMessage(c *context.Context) {
|
||||
|
||||
if len(events.Events) > 0 {
|
||||
for _, v := range events.Events {
|
||||
go linemsg.MessageEvent(v)
|
||||
go linemsg.MessageEvent(botid, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user