1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 03:53:50 +08:00

feat: get_topic_channel_feeds api

This commit is contained in:
Mrs4s 2021-11-27 15:58:13 +08:00
parent 30edae64b3
commit 3e9920b31b
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
6 changed files with 134 additions and 9 deletions

View File

@ -236,6 +236,32 @@ func (bot *CQBot) CQModifyRoleInGuild(guildID uint64, roleID uint64, name string
return OK(nil) return OK(nil)
} }
// CQGetTopicChannelFeeds 获取话题频道帖子列表
// @route(get_topic_channel_feeds)
func (bot *CQBot) CQGetTopicChannelFeeds(guildID, channelID uint64) global.MSG {
guild := bot.Client.GuildService.FindGuild(guildID)
if guild == nil {
return Failed(100, "GUILD_NOT_FOUND")
}
channel := guild.FindChannel(channelID)
if channel == nil {
return Failed(100, "CHANNEL_NOT_FOUND")
}
if channel.ChannelType != client.ChannelTypeTopic {
return Failed(100, "CHANNEL_TYPE_ERROR")
}
feeds, err := bot.Client.GuildService.GetTopicChannelFeeds(guildID, channelID)
if err != nil {
log.Errorf("获取频道 %v 帖子时出现错误: %v", channelID, err)
return Failed(100, "API_ERROR", err.Error())
}
c := make([]global.MSG, 0, len(feeds))
for _, feed := range feeds {
c = append(c, convertChannelFeedInfo(feed))
}
return OK(c)
}
// CQGetFriendList 获取好友列表 // CQGetFriendList 获取好友列表
// //
// https://git.io/Jtz1L // https://git.io/Jtz1L

View File

@ -1,6 +1,7 @@
package coolq package coolq
import ( import (
"github.com/Mrs4s/MiraiGo/topic"
"strconv" "strconv"
"github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/MiraiGo/client"
@ -158,6 +159,48 @@ func convertChannelInfo(c *client.ChannelInfo) global.MSG {
} }
} }
func convertChannelFeedInfo(f *topic.Feed) global.MSG {
m := global.MSG{
"id": f.Id,
"title": f.Title,
"sub_title": f.SubTitle,
"create_time": f.CreateTime,
"guild_id": fU64(f.GuildId),
"channel_id": fU64(f.ChannelId),
"poster_info": global.MSG{
"tiny_id": f.Poster.TinyIdStr,
"nickname": f.Poster.Nickname,
"icon_url": f.Poster.IconUrl,
},
"contents": FeedContentsToArrayMessage(f.Contents),
}
images := make([]global.MSG, 0, len(f.Images))
videos := make([]global.MSG, 0, len(f.Videos))
for _, image := range f.Images {
images = append(images, global.MSG{
"file_id": image.FileId,
"pattern_id": image.PatternId,
"url": image.Url,
"width": image.Width,
"height": image.Height,
})
}
for _, video := range f.Videos {
videos = append(videos, global.MSG{
"file_id": video.FileId,
"pattern_id": video.PatternId,
"url": video.Url,
"width": video.Width,
"height": video.Height,
})
}
m["resource"] = global.MSG{
"images": images,
"videos": videos,
}
return m
}
func fU64(v uint64) string { func fU64(v uint64) string {
return strconv.FormatUint(v, 10) return strconv.FormatUint(v, 10)
} }

51
coolq/feed.go Normal file
View File

@ -0,0 +1,51 @@
package coolq
import (
"github.com/Mrs4s/MiraiGo/topic"
"github.com/Mrs4s/go-cqhttp/global"
)
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
}

7
go.mod
View File

@ -5,7 +5,7 @@ go 1.17
require ( require (
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
github.com/Microsoft/go-winio v0.5.1 github.com/Microsoft/go-winio v0.5.1
github.com/Mrs4s/MiraiGo v0.0.0-20211123160412-4c60c8ee4740 github.com/Mrs4s/MiraiGo v0.0.0-20211126180457-5c5e61d27903
github.com/dustin/go-humanize v1.0.0 github.com/dustin/go-humanize v1.0.0
github.com/fumiama/go-hide-param v0.1.4 github.com/fumiama/go-hide-param v0.1.4
github.com/gabriel-vasile/mimetype v1.4.0 github.com/gabriel-vasile/mimetype v1.4.0
@ -30,10 +30,12 @@ require (
) )
require ( require (
github.com/RomiChan/protobuf v0.0.0-20211126015646-ee3d29b19e08 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect github.com/go-stack/stack v1.8.1 // indirect
github.com/gocq/rs v1.0.1 // indirect github.com/gocq/rs v1.0.1 // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect
@ -48,11 +50,10 @@ require (
github.com/xdg-go/scram v1.0.2 // indirect github.com/xdg-go/scram v1.0.2 // indirect
github.com/xdg-go/stringprep v1.0.2 // indirect github.com/xdg-go/stringprep v1.0.2 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211113001501-0c823b97ae02 // indirect golang.org/x/sys v0.0.0-20211113001501-0c823b97ae02 // indirect
golang.org/x/text v0.3.7 // indirect golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
modernc.org/libc v1.11.70 // indirect modernc.org/libc v1.11.70 // indirect
modernc.org/mathutil v1.4.1 // indirect modernc.org/mathutil v1.4.1 // indirect
modernc.org/memory v1.0.5 // indirect modernc.org/memory v1.0.5 // indirect

12
go.sum
View File

@ -3,8 +3,10 @@ github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/g
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY= github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/Mrs4s/MiraiGo v0.0.0-20211123160412-4c60c8ee4740 h1:8i8ILE2q+jw8zhmTtsNRhwrufkJQJ2kOyVhncmAfhTg= github.com/Mrs4s/MiraiGo v0.0.0-20211126180457-5c5e61d27903 h1:09DWaPpfF9u/qwRNW8wmieCaySeXZmYLnfSbrow4Cbs=
github.com/Mrs4s/MiraiGo v0.0.0-20211123160412-4c60c8ee4740/go.mod h1:imVKbfKqqeit+C/eaWGb4MKQ3z3gN6pRpBU5RMtp5so= github.com/Mrs4s/MiraiGo v0.0.0-20211126180457-5c5e61d27903/go.mod h1:ET7ZfE/OgwdZUBF+kdYlKUCAw+HavEet/5D4+lq/8Xc=
github.com/RomiChan/protobuf v0.0.0-20211126015646-ee3d29b19e08 h1:VAR3nNyBAc+oPlLKihkLTP0GXf8bQi085y2pSrNzAF0=
github.com/RomiChan/protobuf v0.0.0-20211126015646-ee3d29b19e08/go.mod h1:lM1Te2wqdBLPSF7QLaskSn1fGW3Tw2l0iFGsTHTxqIg=
github.com/bits-and-blooms/bitset v1.2.1 h1:M+/hrU9xlMp7t4TyTDQW97d3tRPVuKFC6zBEK16QnXY= github.com/bits-and-blooms/bitset v1.2.1 h1:M+/hrU9xlMp7t4TyTDQW97d3tRPVuKFC6zBEK16QnXY=
github.com/bits-and-blooms/bitset v1.2.1/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/bits-and-blooms/bitset v1.2.1/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -175,9 +177,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9 h1:0qxwC5n+ttVOINCBeRHO0nq9X7uy8SDsPoi5OaCdIEI=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -232,7 +233,6 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=

View File

@ -167,6 +167,10 @@ func (c *Caller) call(action string, p Getter) global.MSG {
case "get_stranger_info": case "get_stranger_info":
p0 := p.Get("user_id").Int() p0 := p.Get("user_id").Int()
return c.bot.CQGetStrangerInfo(p0) return c.bot.CQGetStrangerInfo(p0)
case "get_topic_channel_feeds":
p0 := p.Get("guild_id").Uint()
p1 := p.Get("channel_id").Uint()
return c.bot.CQGetTopicChannelFeeds(p0, p1)
case "get_unidirectional_friend_list": case "get_unidirectional_friend_list":
return c.bot.CQGetUnidirectionalFriendList() return c.bot.CQGetUnidirectionalFriendList()
case "get_version_info": case "get_version_info":