1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00
go-cqhttp/coolq/feed.go
2021-11-27 16:01:09 +08:00

53 lines
1.2 KiB
Go

package coolq
import (
"github.com/Mrs4s/MiraiGo/topic"
"github.com/Mrs4s/go-cqhttp/global"
)
// FeedContentsToArrayMessage 将话题频道帖子内容转换为 Array Message
func FeedContentsToArrayMessage(contents []topic.IFeedRichContentElement) []global.MSG {
r := make([]global.MSG, 0, len(contents))
for _, e := range contents {
var m global.MSG
switch elem := e.(type) {
case *topic.TextElement:
m = global.MSG{
"type": "text",
"data": global.MSG{"text": elem.Content},
}
case *topic.AtElement:
m = global.MSG{
"type": "at",
"data": global.MSG{"qq": elem.Id},
}
case *topic.EmojiElement:
m = global.MSG{
"type": "face",
"data": global.MSG{"id": elem.Id},
}
case *topic.ChannelQuoteElement:
m = global.MSG{
"type": "channel_quote",
"data": global.MSG{
"guild_id": fU64(elem.GuildId),
"channel_id": fU64(elem.ChannelId),
"display_text": elem.DisplayText,
},
}
case *topic.UrlQuoteElement:
m = global.MSG{
"type": "url_quote",
"data": global.MSG{
"url": elem.Url,
"display_text": elem.DisplayText,
},
}
}
if m != nil {
r = append(r, m)
}
}
return r
}