mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
cq code 'video' supported.
This commit is contained in:
parent
611d16d79e
commit
1418e36bab
@ -439,7 +439,7 @@ func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
|
|||||||
}
|
}
|
||||||
var r []MSG
|
var r []MSG
|
||||||
for _, n := range m.Nodes {
|
for _, n := range m.Nodes {
|
||||||
checkMedia(n.Message)
|
bot.checkMedia(n.Message)
|
||||||
r = append(r, MSG{
|
r = append(r, MSG{
|
||||||
"sender": MSG{
|
"sender": MSG{
|
||||||
"user_id": n.SenderId,
|
"user_id": n.SenderId,
|
||||||
|
@ -75,6 +75,18 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
|
|||||||
"data": map[string]string{"file": o.Name, "url": o.Url},
|
"data": map[string]string{"file": o.Name, "url": o.Url},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case *message.ShortVideoElement:
|
||||||
|
if ur {
|
||||||
|
m = MSG{
|
||||||
|
"type": "video",
|
||||||
|
"data": map[string]string{"file": o.Name},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m = MSG{
|
||||||
|
"type": "video",
|
||||||
|
"data": map[string]string{"file": o.Name, "url": o.Url},
|
||||||
|
}
|
||||||
|
}
|
||||||
case *message.ImageElement:
|
case *message.ImageElement:
|
||||||
if ur {
|
if ur {
|
||||||
m = MSG{
|
m = MSG{
|
||||||
@ -120,6 +132,12 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
|
|||||||
} else {
|
} else {
|
||||||
r += fmt.Sprintf(`[CQ:record,file=%s,url=%s]`, o.Name, CQCodeEscapeValue(o.Url))
|
r += fmt.Sprintf(`[CQ:record,file=%s,url=%s]`, o.Name, CQCodeEscapeValue(o.Url))
|
||||||
}
|
}
|
||||||
|
case *message.ShortVideoElement:
|
||||||
|
if ur {
|
||||||
|
r += fmt.Sprintf(`[CQ:video,file=%s]`, o.Name)
|
||||||
|
} else {
|
||||||
|
r += fmt.Sprintf(`[CQ:video,file=%s,url=%s]`, o.Name, CQCodeEscapeValue(o.Url))
|
||||||
|
}
|
||||||
case *message.ImageElement:
|
case *message.ImageElement:
|
||||||
if ur {
|
if ur {
|
||||||
r += fmt.Sprintf(`[CQ:image,file=%s]`, o.Filename)
|
r += fmt.Sprintf(`[CQ:image,file=%s]`, o.Filename)
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -30,7 +31,7 @@ func ToFormattedMessage(e []message.IMessageElement, code int64, raw ...bool) (r
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMessage) {
|
func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMessage) {
|
||||||
checkMedia(m.Elements)
|
bot.checkMedia(m.Elements)
|
||||||
cqm := ToStringMessage(m.Elements, 0, true)
|
cqm := ToStringMessage(m.Elements, 0, true)
|
||||||
log.Infof("收到好友 %v(%v) 的消息: %v", m.Sender.DisplayName(), m.Sender.Uin, cqm)
|
log.Infof("收到好友 %v(%v) 的消息: %v", m.Sender.DisplayName(), m.Sender.Uin, cqm)
|
||||||
fm := MSG{
|
fm := MSG{
|
||||||
@ -55,7 +56,7 @@ func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMess
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage) {
|
func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage) {
|
||||||
checkMedia(m.Elements)
|
bot.checkMedia(m.Elements)
|
||||||
for _, elem := range m.Elements {
|
for _, elem := range m.Elements {
|
||||||
if file, ok := elem.(*message.GroupFileElement); ok {
|
if file, ok := elem.(*message.GroupFileElement); ok {
|
||||||
log.Infof("群 %v(%v) 内 %v(%v) 上传了文件: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, file.Name)
|
log.Infof("群 %v(%v) 内 %v(%v) 上传了文件: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, file.Name)
|
||||||
@ -133,7 +134,7 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) tempMessageEvent(c *client.QQClient, m *message.TempMessage) {
|
func (bot *CQBot) tempMessageEvent(c *client.QQClient, m *message.TempMessage) {
|
||||||
checkMedia(m.Elements)
|
bot.checkMedia(m.Elements)
|
||||||
cqm := ToStringMessage(m.Elements, 0, true)
|
cqm := ToStringMessage(m.Elements, 0, true)
|
||||||
bot.tempMsgCache.Store(m.Sender.Uin, m.GroupCode)
|
bot.tempMsgCache.Store(m.Sender.Uin, m.GroupCode)
|
||||||
log.Infof("收到来自群 %v(%v) 内 %v(%v) 的临时会话消息: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, cqm)
|
log.Infof("收到来自群 %v(%v) 内 %v(%v) 的临时会话消息: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, cqm)
|
||||||
@ -362,7 +363,7 @@ func (bot *CQBot) groupDecrease(groupCode, userUin int64, operator *client.Group
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkMedia(e []message.IMessageElement) {
|
func (bot *CQBot) checkMedia(e []message.IMessageElement) {
|
||||||
for _, elem := range e {
|
for _, elem := range e {
|
||||||
switch i := elem.(type) {
|
switch i := elem.(type) {
|
||||||
case *message.ImageElement:
|
case *message.ImageElement:
|
||||||
@ -373,7 +374,7 @@ func checkMedia(e []message.IMessageElement) {
|
|||||||
w.WriteUInt32(uint32(i.Size))
|
w.WriteUInt32(uint32(i.Size))
|
||||||
w.WriteString(i.Filename)
|
w.WriteString(i.Filename)
|
||||||
w.WriteString(i.Url)
|
w.WriteString(i.Url)
|
||||||
}), 0777)
|
}), os.ModePerm)
|
||||||
}
|
}
|
||||||
i.Filename = filename
|
i.Filename = filename
|
||||||
case *message.VoiceElement:
|
case *message.VoiceElement:
|
||||||
@ -385,8 +386,20 @@ func checkMedia(e []message.IMessageElement) {
|
|||||||
log.Warnf("语音文件 %v 下载失败: %v", i.Name, err)
|
log.Warnf("语音文件 %v 下载失败: %v", i.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_ = ioutil.WriteFile(path.Join(global.VOICE_PATH, i.Name), b, 0777)
|
_ = ioutil.WriteFile(path.Join(global.VOICE_PATH, i.Name), b, os.ModePerm)
|
||||||
}
|
}
|
||||||
|
case *message.ShortVideoElement:
|
||||||
|
filename := hex.EncodeToString(i.Md5) + ".video"
|
||||||
|
if !global.PathExists(path.Join(global.VIDEO_PATH, filename)) {
|
||||||
|
_ = ioutil.WriteFile(path.Join(global.VIDEO_PATH, filename), binary.NewWriterF(func(w *binary.Writer) {
|
||||||
|
w.Write(i.Md5)
|
||||||
|
w.WriteUInt32(uint32(i.Size))
|
||||||
|
w.WriteString(i.Name)
|
||||||
|
w.Write(i.Uuid)
|
||||||
|
}), os.ModePerm)
|
||||||
|
}
|
||||||
|
i.Name = filename
|
||||||
|
i.Url = bot.Client.GetShortVideoUrl(i.Uuid, i.Md5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ var IMAGE_PATH = path.Join("data", "images")
|
|||||||
|
|
||||||
var VOICE_PATH = path.Join("data", "voices")
|
var VOICE_PATH = path.Join("data", "voices")
|
||||||
|
|
||||||
|
var VIDEO_PATH = path.Join("data", "videos")
|
||||||
|
|
||||||
func PathExists(path string) bool {
|
func PathExists(path string) bool {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
return err == nil || os.IsExist(err)
|
return err == nil || os.IsExist(err)
|
||||||
|
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-20200812011522-ee1117893fad
|
github.com/Mrs4s/MiraiGo v0.0.0-20200813091456-988a010b51df
|
||||||
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
|
||||||
|
8
go.sum
8
go.sum
@ -1,11 +1,7 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
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/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200809221224-7a84cfae6795 h1:Bu4k9ZS/IIy9Shwd9lS/C2P/2I8fYUwg1OpRF91hr1w=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200813091456-988a010b51df h1:ERLrnv7bONrg4NqvC8AWhtEgCZk97uCZdRpQS4gF8UE=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200809221224-7a84cfae6795/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200813091456-988a010b51df/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200810032556-a425f9d1b98e h1:5LYDouOL9ZgTL5PwZuuSlFYSfboRQjnXqRIlhviRcGE=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200810032556-a425f9d1b98e/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200812011522-ee1117893fad h1:mOz8SozY2NEjXivlOrTwGPsbukcpLYpi/rv0/ASM/Hg=
|
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200812011522-ee1117893fad/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=
|
||||||
|
5
main.go
5
main.go
@ -46,6 +46,11 @@ func init() {
|
|||||||
log.Fatalf("创建语音缓存文件夹失败: %v", err)
|
log.Fatalf("创建语音缓存文件夹失败: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !global.PathExists(global.VIDEO_PATH) {
|
||||||
|
if err := os.MkdirAll(global.VIDEO_PATH, os.ModePerm); err != nil {
|
||||||
|
log.Fatalf("创建视频缓存文件夹失败: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if global.PathExists("cqhttp.json") {
|
if global.PathExists("cqhttp.json") {
|
||||||
log.Info("发现 cqhttp.json 将在五秒后尝试导入配置,按 Ctrl+C 取消.")
|
log.Info("发现 cqhttp.json 将在五秒后尝试导入配置,按 Ctrl+C 取消.")
|
||||||
log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.json 文件.")
|
log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.json 文件.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user