mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
fix tts panic & support showPic flashPic
This commit is contained in:
parent
aaa73ef5f5
commit
c984f22d4f
@ -665,7 +665,7 @@ func (bot *CQBot) CQCanSendRecord() MSG {
|
||||
}
|
||||
|
||||
func (bot *CQBot) CQOcrImage(imageId string) MSG {
|
||||
img, err := bot.makeImageElem("image", map[string]string{"file": imageId}, true)
|
||||
img, err := bot.makeImageElem(map[string]string{"file": imageId}, true)
|
||||
if err != nil {
|
||||
log.Warnf("load image error: %v", err)
|
||||
return Failed(100)
|
||||
|
@ -362,12 +362,48 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
|
||||
return
|
||||
}
|
||||
|
||||
func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.IMessageElement, error) {
|
||||
func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m message.IMessageElement, err error) {
|
||||
switch t {
|
||||
case "text":
|
||||
return message.NewText(d["text"]), nil
|
||||
case "image":
|
||||
return bot.makeImageElem(t, d, group)
|
||||
img,err := bot.makeImageElem(d, group)
|
||||
if err != nil{
|
||||
return nil, err
|
||||
}
|
||||
tp := d["type"]
|
||||
if tp != "show" && tp != "flash" {
|
||||
return img, nil
|
||||
}
|
||||
if i, ok := img.(*message.ImageElement); ok { // 秀图,闪照什么的就直接传了吧
|
||||
if group {
|
||||
img, err = bot.Client.UploadGroupImage(1, i.Data)
|
||||
} else {
|
||||
img, err = bot.Client.UploadPrivateImage(1, i.Data)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
switch tp {
|
||||
case "flash":
|
||||
if i, ok := img.(*message.GroupImageElement); ok{
|
||||
return &message.GroupFlashPicElement{GroupImageElement: *i},nil
|
||||
}
|
||||
if i, ok := img.(*message.FriendImageElement); ok{
|
||||
return &message.FriendFlashPicElement{FriendImageElement: *i},nil
|
||||
}
|
||||
case "show":
|
||||
id, _ := strconv.ParseInt(d["id"], 10, 64)
|
||||
if id < 40000 || id >= 40006 {
|
||||
id = 40000
|
||||
}
|
||||
if i, ok := img.(*message.GroupImageElement); ok{
|
||||
return &message.GroupShowPicElement{GroupImageElement: *i,EffectId: int32(id)},nil
|
||||
}
|
||||
return img,nil // 私聊还没做
|
||||
}
|
||||
|
||||
case "poke":
|
||||
if !group {
|
||||
return nil, errors.New("todo") // TODO: private poke
|
||||
@ -388,6 +424,12 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
|
||||
if !group {
|
||||
return nil, errors.New("private voice unsupported now")
|
||||
}
|
||||
defer func() {
|
||||
if r := recover();r != nil {
|
||||
m = nil
|
||||
err = errors.New("tts 转换失败")
|
||||
}
|
||||
}()
|
||||
data, err := bot.Client.GetTts(d["text"])
|
||||
ioutil.WriteFile("tts.silk", data, 777)
|
||||
if err != nil {
|
||||
@ -529,7 +571,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
|
||||
if maxheight == 0 {
|
||||
maxheight = 1000
|
||||
}
|
||||
img, err := bot.makeImageElem(t, d, group)
|
||||
img, err := bot.makeImageElem(d, group)
|
||||
if err != nil {
|
||||
return nil, errors.New("send cardimage faild")
|
||||
}
|
||||
@ -537,6 +579,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
|
||||
default:
|
||||
return nil, errors.New("unsupported cq code: " + t)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func CQCodeEscapeText(raw string) string {
|
||||
@ -568,7 +611,7 @@ func CQCodeUnescapeValue(content string) string {
|
||||
}
|
||||
|
||||
// 图片 elem 生成器,单独拎出来,用于公用
|
||||
func (bot *CQBot) makeImageElem(t string, d map[string]string, group bool) (message.IMessageElement, error) {
|
||||
func (bot *CQBot) makeImageElem(d map[string]string, group bool) (message.IMessageElement, error) {
|
||||
f := d["file"]
|
||||
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
|
||||
cache := d["cache"]
|
||||
@ -616,7 +659,7 @@ func (bot *CQBot) makeImageElem(t string, d map[string]string, group bool) (mess
|
||||
rawPath += ".cqimg"
|
||||
}
|
||||
if !global.PathExists(rawPath) && d["url"] != "" {
|
||||
return bot.ToElement(t, map[string]string{"file": d["url"]}, group)
|
||||
return bot.makeImageElem(map[string]string{"file": d["url"]}, group)
|
||||
}
|
||||
if global.PathExists(rawPath) {
|
||||
b, err := ioutil.ReadFile(rawPath)
|
||||
@ -652,7 +695,7 @@ func (bot *CQBot) makeImageElem(t string, d map[string]string, group bool) (mess
|
||||
}
|
||||
if size == 0 {
|
||||
if url != "" {
|
||||
return bot.ToElement(t, map[string]string{"file": url}, group)
|
||||
return bot.makeImageElem(map[string]string{"file": url}, group)
|
||||
}
|
||||
return nil, errors.New("img size is 0")
|
||||
}
|
||||
@ -663,7 +706,7 @@ func (bot *CQBot) makeImageElem(t string, d map[string]string, group bool) (mess
|
||||
rsp, err := bot.Client.QueryGroupImage(1, hash, size)
|
||||
if err != nil {
|
||||
if url != "" {
|
||||
return bot.ToElement(t, map[string]string{"file": url}, group)
|
||||
return bot.makeImageElem(map[string]string{"file": url}, group)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@ -672,7 +715,7 @@ func (bot *CQBot) makeImageElem(t string, d map[string]string, group bool) (mess
|
||||
rsp, err := bot.Client.QueryFriendImage(1, hash, size)
|
||||
if err != nil {
|
||||
if url != "" {
|
||||
return bot.ToElement(t, map[string]string{"file": url}, group)
|
||||
return bot.makeImageElem(map[string]string{"file": url}, group)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
6
go.mod
6
go.mod
@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20201008134448-b53aaceaa1b4
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20201011070235-2fa335fd8b68
|
||||
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
|
||||
github.com/gin-gonic/gin v1.6.3
|
||||
github.com/go-playground/validator/v10 v10.4.0 // indirect
|
||||
@ -27,8 +27,8 @@ require (
|
||||
github.com/xujiajun/nutsdb v0.5.0
|
||||
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
||||
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
|
||||
golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c // indirect
|
||||
golang.org/x/sys v0.0.0-20201005172224-997123666555 // indirect
|
||||
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb // indirect
|
||||
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634 // indirect
|
||||
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
|
||||
gopkg.in/yaml.v2 v2.3.0 // indirect
|
||||
)
|
||||
|
18
go.sum
18
go.sum
@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20201008134448-b53aaceaa1b4 h1:vNDY7JAh+e7ac0Dft3GF+s4WZU55SZkwaAI7UmXfwHc=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20201008134448-b53aaceaa1b4/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20201011070235-2fa335fd8b68 h1:+BT4VZ0ZeiTFRV5hOzxJR0d3FW2dcl+ZZwCY5zL5Xls=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20201011070235-2fa335fd8b68/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
|
||||
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=
|
||||
@ -54,6 +56,7 @@ github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj
|
||||
github.com/jonboulle/clockwork v0.2.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
|
||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
|
||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
|
||||
@ -68,8 +71,10 @@ github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2y
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
@ -130,8 +135,10 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c h1:dk0ukUIHmGHqASjP0iue2261isepFCC6XRCSd1nHgDw=
|
||||
golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c/go.mod h1:iQL9McJNjoIa5mjH6nYTCTZXUN6RP+XW3eib7Ya3XcI=
|
||||
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0 h1:wBouT66WTYFXdxfVdz9sVWARVd/2vfGcmI45D2gj45M=
|
||||
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb h1:mUVeFHoDKis5nxCAzoAi7E8Ghb86EXh/RK6wtvJIqRY=
|
||||
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@ -145,10 +152,13 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201005172224-997123666555 h1:fihtqzYxy4E31W1yUlyRGveTZT1JIP0bmKaDZ2ceKAw=
|
||||
golang.org/x/sys v0.0.0-20201005172224-997123666555/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201007082116-8445cc04cbdf h1:AvBTl0xbF/KtHyvm61X4gSPF7/dKJ/xQqJwKr1Qu9no=
|
||||
golang.org/x/sys v0.0.0-20201007082116-8445cc04cbdf/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634 h1:bNEHhJCnrwMKNMmOx3yAynp5vs5/gRy+XWFtZFu7NBM=
|
||||
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
|
||||
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
Loading…
x
Reference in New Issue
Block a user