1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 12:03:50 +08:00

Merge pull request #3 from Mrs4s/master

pull
This commit is contained in:
wdvxdr1123 2020-08-24 19:52:55 +08:00 committed by GitHub
commit 17f8232a1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 9 deletions

View File

@ -489,7 +489,7 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
bot.CQProcessFriendRequest(context.Get("flag").Str, operation.Get("approve").Bool())
}
if reqType == "group" {
bot.CQProcessGroupRequest(context.Get("flag").Str, context.Get("sub_type").Str, context.Get("reason").Str, operation.Get("approve").Bool())
bot.CQProcessGroupRequest(context.Get("flag").Str, context.Get("sub_type").Str, operation.Get("reason").Str, operation.Get("approve").Bool())
}
}
}
@ -503,11 +503,19 @@ func (bot *CQBot) CQGetImage(file string) MSG {
if b, err := ioutil.ReadFile(path.Join(global.IMAGE_PATH, file)); err == nil {
r := binary.NewReader(b)
r.ReadBytes(16)
return OK(MSG{
msg := MSG{
"size": r.ReadInt32(),
"filename": r.ReadString(),
"url": r.ReadString(),
})
}
local := path.Join(global.CACHE_PATH, file+"."+path.Ext(msg["filename"].(string)))
if !global.PathExists(local) {
if data, err := global.GetBytes(msg["url"].(string)); err == nil {
_ = ioutil.WriteFile(local, data, 0644)
}
}
msg["file"] = local
return OK(msg)
}
return Failed(100)
}

View File

@ -329,6 +329,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
}
var size int32
var hash []byte
var url string
if path.Ext(rawPath) == ".cqimg" {
for _, line := range strings.Split(global.ReadAllText(rawPath), "\n") {
kv := strings.SplitN(line, "=", 2)
@ -344,8 +345,13 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
r := binary.NewReader(b)
hash = r.ReadBytes(16)
size = r.ReadInt32()
r.ReadString()
url = r.ReadString()
}
if size == 0 {
if url != "" {
return bot.ToElement(t, map[string]string{"file": url}, group)
}
return nil, errors.New("img size is 0")
}
if len(hash) != 16 {

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
require (
github.com/Mrs4s/MiraiGo v0.0.0-20200822190748-ce670caee0a8
github.com/Mrs4s/MiraiGo v0.0.0-20200823184203-93de1f445681
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/gorilla/websocket v1.4.2

8
go.sum
View File

@ -1,9 +1,9 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20200822102558-4dc018de2be7 h1:X6ebQxHSXRXDa3ZkMSFYnUhEIKdn6iPUmcFf2pl46oA=
github.com/Mrs4s/MiraiGo v0.0.0-20200822102558-4dc018de2be7/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
github.com/Mrs4s/MiraiGo v0.0.0-20200822190748-ce670caee0a8 h1:29b2Y1TehWby+jEXC7kjOvXk/PxwZ1BeFAKwOzTaW7M=
github.com/Mrs4s/MiraiGo v0.0.0-20200822190748-ce670caee0a8/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
github.com/Mrs4s/MiraiGo v0.0.0-20200823075559-507fe33e842d h1:F7ssNQDHqB7NZVwTeADRY+AxKT3eeSlBzfzeZYTUfxM=
github.com/Mrs4s/MiraiGo v0.0.0-20200823075559-507fe33e842d/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
github.com/Mrs4s/MiraiGo v0.0.0-20200823184203-93de1f445681 h1:hnaJH7BGD+Sb2Xb59SLpRy+f8B3Rx29Qy53ZM0AbIsE=
github.com/Mrs4s/MiraiGo v0.0.0-20200823184203-93de1f445681/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=

View File

@ -41,7 +41,7 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
c.Status(404)
return
}
if c.Request.Method == "POST" && c.Request.Header.Get("Content-Type") == "application/json" {
if c.Request.Method == "POST" && strings.Contains(c.Request.Header.Get("Content-Type"), "application/json") {
d, err := c.GetRawData()
if err != nil {
log.Warnf("获取请求 %v 的Body时出现错误: %v", c.Request.RequestURI, err)