mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 12:03:50 +08:00
cqcode record
supported.
This commit is contained in:
parent
fa5ee669f4
commit
d5ee8fb331
@ -99,6 +99,15 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
|
|||||||
newElem = append(newElem, gm)
|
newElem = append(newElem, gm)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if i, ok := elem.(*message.GroupVoiceElement); ok {
|
||||||
|
gv, err := bot.Client.UploadGroupPtt(groupId, i.Data, int32(len(i.Data)))
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("警告: 群 %v 消息语音上传失败: %v", groupId, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newElem = append(newElem, gv)
|
||||||
|
continue
|
||||||
|
}
|
||||||
newElem = append(newElem, elem)
|
newElem = append(newElem, elem)
|
||||||
}
|
}
|
||||||
m.Elements = newElem
|
m.Elements = newElem
|
||||||
|
@ -246,6 +246,44 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
|
|||||||
return rsp, nil
|
return rsp, nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("invalid image")
|
return nil, errors.New("invalid image")
|
||||||
|
case "record":
|
||||||
|
if !group {
|
||||||
|
return nil, errors.New("private voice unsupported now")
|
||||||
|
}
|
||||||
|
f := d["file"]
|
||||||
|
var data []byte
|
||||||
|
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
|
||||||
|
b, err := global.GetBytes(f)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
data = b
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(f, "base64") {
|
||||||
|
b, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
data = b
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(f, "file") {
|
||||||
|
fu, err := url.Parse(f)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(fu.Path, "/") && runtime.GOOS == `windows` {
|
||||||
|
fu.Path = fu.Path[1:]
|
||||||
|
}
|
||||||
|
b, err := ioutil.ReadFile(fu.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
data = b
|
||||||
|
}
|
||||||
|
if !global.IsAMR(data) {
|
||||||
|
return nil, errors.New("unsupported voice file format (please use AMR file for now)")
|
||||||
|
}
|
||||||
|
return &message.GroupVoiceElement{Data: data}, nil
|
||||||
case "face":
|
case "face":
|
||||||
id, err := strconv.Atoi(d["id"])
|
id, err := strconv.Atoi(d["id"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -31,3 +31,10 @@ func Check(err error) {
|
|||||||
log.Fatalf("遇到错误: %v", err)
|
log.Fatalf("遇到错误: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsAMR(b []byte) bool {
|
||||||
|
if len(b) <= 6 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return b[0] == 0x23 && b[1] == 0x21 && b[2] == 0x41 && b[3] == 0x4D && b[4] == 0x52 // amr file header
|
||||||
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
|
|||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200807030850-ed30f7ad5934
|
github.com/Mrs4s/MiraiGo v0.0.0-20200808003732-2a32e623270d
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/guonaihong/gout v0.1.1
|
github.com/guonaihong/gout v0.1.1
|
||||||
|
2
go.sum
2
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/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200807030850-ed30f7ad5934 h1:LoNjIsnyEQFGP9IchIQ65yHRCfNKSru3BAOguRepkCM=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200807030850-ed30f7ad5934 h1:LoNjIsnyEQFGP9IchIQ65yHRCfNKSru3BAOguRepkCM=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200807030850-ed30f7ad5934/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200807030850-ed30f7ad5934/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
|
||||||
|
github.com/Mrs4s/MiraiGo v0.0.0-20200808003732-2a32e623270d h1:K9jHdcO13mLqQB0xm0/ZlY852FoVQJ/WSDwfdmfhDlU=
|
||||||
|
github.com/Mrs4s/MiraiGo v0.0.0-20200808003732-2a32e623270d/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
|
||||||
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
|
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
|
||||||
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
|
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=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user