github.com/Mrs4s/go-cqhttp@v1.2.0/coolq/feed.go (about) 1 package coolq 2 3 import ( 4 "github.com/Mrs4s/MiraiGo/topic" 5 6 "github.com/Mrs4s/go-cqhttp/global" 7 ) 8 9 // FeedContentsToArrayMessage 将话题频道帖子内容转换为 Array Message 10 func FeedContentsToArrayMessage(contents []topic.IFeedRichContentElement) []global.MSG { 11 r := make([]global.MSG, 0, len(contents)) 12 for _, e := range contents { 13 var m global.MSG 14 switch elem := e.(type) { 15 case *topic.TextElement: 16 m = global.MSG{ 17 "type": "text", 18 "data": global.MSG{"text": elem.Content}, 19 } 20 case *topic.AtElement: 21 m = global.MSG{ 22 "type": "at", 23 "data": global.MSG{"id": elem.Id, "qq": elem.Id}, 24 } 25 case *topic.EmojiElement: 26 m = global.MSG{ 27 "type": "face", 28 "data": global.MSG{"id": elem.Id}, 29 } 30 case *topic.ChannelQuoteElement: 31 m = global.MSG{ 32 "type": "channel_quote", 33 "data": global.MSG{ 34 "guild_id": fU64(elem.GuildId), 35 "channel_id": fU64(elem.ChannelId), 36 "display_text": elem.DisplayText, 37 }, 38 } 39 case *topic.UrlQuoteElement: 40 m = global.MSG{ 41 "type": "url_quote", 42 "data": global.MSG{ 43 "url": elem.Url, 44 "display_text": elem.DisplayText, 45 }, 46 } 47 } 48 if m != nil { 49 r = append(r, m) 50 } 51 } 52 return r 53 }