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

feat: get_guild_member_list api

This commit is contained in:
Mrs4s 2021-12-08 21:52:00 +08:00
parent 7278f99ed9
commit e69051e88b
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
6 changed files with 71 additions and 15 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/segmentio/asm/base64"
"math"
"os"
"path"
@ -29,6 +30,19 @@ import (
"github.com/Mrs4s/go-cqhttp/modules/filter"
)
type guildMemberPageToken struct {
guildID uint64
nextIndex uint32
nextRoleID uint64
nextQueryParam string
}
var defaultPageToken = &guildMemberPageToken{
guildID: 0,
nextIndex: 0,
nextRoleID: 2,
}
// CQGetLoginInfo 获取登录号信息
//
// https://git.io/Jtz1I
@ -128,17 +142,49 @@ func (bot *CQBot) CQGetGuildChannelList(guildID uint64, noCache bool) global.MSG
return OK(channels)
}
/*
// CQGetGuildMembers 获取频道成员列表
// @route(get_guild_members)
func (bot *CQBot) CQGetGuildMembers(guildID uint64) global.MSG {
// @route(get_guild_member_list)
func (bot *CQBot) CQGetGuildMembers(guildID uint64, nextToken string) global.MSG {
guild := bot.Client.GuildService.FindGuild(guildID)
if guild == nil {
return Failed(100, "GUILD_NOT_FOUND")
}
return OK(nil) // todo
token := defaultPageToken
if nextToken != "" {
i, exists := bot.nextTokenCache.Get(nextToken)
if !exists {
return Failed(100, "NEXT_TOKEN_NOT_EXISTS")
}
token = i.(*guildMemberPageToken)
if token.guildID != guildID {
return Failed(100, "GUILD_NOT_MATCH")
}
}
ret, err := bot.Client.GuildService.FetchGuildMemberListWithRole(guildID, 0, token.nextIndex, token.nextRoleID, token.nextQueryParam)
if err != nil {
return Failed(100, "API_ERROR", err.Error())
}
res := global.MSG{
"members": convertGuildMemberInfo(ret.Members),
"finished": ret.Finished,
"next_token": nil,
}
if !ret.Finished {
next := &guildMemberPageToken{
guildID: guildID,
nextIndex: ret.NextIndex,
nextRoleID: ret.NextRoleId,
nextQueryParam: ret.NextQueryParam,
}
id := base64.StdEncoding.EncodeToString(binary.NewWriterF(func(w *binary.Writer) {
w.WriteUInt64(uint64(time.Now().UnixNano()))
w.WriteString(utils.RandomString(5))
}))
bot.nextTokenCache.Add(id, next, time.Minute*10)
res["next_token"] = id
}
return OK(res)
}
*/
// CQGetGuildRoles 获取频道角色列表
// @route(get_guild_roles)

View File

@ -34,6 +34,7 @@ type CQBot struct {
friendReqCache sync.Map
tempSessionCache sync.Map
nextTokenCache *utils.Cache
}
// Event 事件
@ -68,6 +69,7 @@ func (e *Event) JSONString() string {
func NewQQBot(cli *client.QQClient) *CQBot {
bot := &CQBot{
Client: cli,
nextTokenCache: utils.NewCache(time.Second * 10),
}
bot.Client.OnPrivateMessage(bot.privateMessageEvent)
bot.Client.OnGroupMessage(bot.groupMessageEvent)

View File

@ -52,13 +52,17 @@ func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) global.MSG
}
}
func convertGuildMemberInfo(m *client.GuildMemberInfo) global.MSG {
return global.MSG{
"tiny_id": fU64(m.TinyId),
"title": m.Title,
"nickname": m.Nickname,
"role": m.Role,
func convertGuildMemberInfo(m []*client.GuildMemberInfo) (r []global.MSG) {
for _, mem := range m {
r = append(r, global.MSG{
"tiny_id": fU64(mem.TinyId),
"title": mem.Title,
"nickname": mem.Nickname,
"role_id": fU64(mem.Role),
"role_name": mem.RoleName,
})
}
return
}
func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) global.MSG {

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.17
require (
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
github.com/Microsoft/go-winio v0.5.1
github.com/Mrs4s/MiraiGo v0.0.0-20211208080234-25c67a3ee1c1
github.com/Mrs4s/MiraiGo v0.0.0-20211208132533-8cd25e02fcf3
github.com/dustin/go-humanize v1.0.0
github.com/fumiama/go-hide-param v0.1.4
github.com/gabriel-vasile/mimetype v1.4.0

4
go.sum
View File

@ -3,8 +3,8 @@ 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/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/Mrs4s/MiraiGo v0.0.0-20211208080234-25c67a3ee1c1 h1:UipCzEST10GzJnvlhHsY4g39xzwVzSHE+5Go9d0dTPY=
github.com/Mrs4s/MiraiGo v0.0.0-20211208080234-25c67a3ee1c1/go.mod h1:YD9gBKkxC9lPPtx3doYXRG26VBkK6YXjrS76cv01C5w=
github.com/Mrs4s/MiraiGo v0.0.0-20211208132533-8cd25e02fcf3 h1:w42Z7gE+HjBcjXDjVZ8o5rzNgAzt7nhuL84HOYpIhRE=
github.com/Mrs4s/MiraiGo v0.0.0-20211208132533-8cd25e02fcf3/go.mod h1:YD9gBKkxC9lPPtx3doYXRG26VBkK6YXjrS76cv01C5w=
github.com/RomiChan/protobuf v0.0.0-20211204042931-ff4f35848737 h1:p4o7/eSoP39jwnGZz08N1IpH/mNzg9SdCn7kPM9A9BE=
github.com/RomiChan/protobuf v0.0.0-20211204042931-ff4f35848737/go.mod h1:CKKOWC7mBxd36zxsCB1V8DTrwlTNRQvkSVbYqyUiGEE=
github.com/bits-and-blooms/bitset v1.2.1 h1:M+/hrU9xlMp7t4TyTDQW97d3tRPVuKFC6zBEK16QnXY=

View File

@ -140,6 +140,10 @@ func (c *Caller) call(action string, p Getter) global.MSG {
return c.bot.CQGetGuildChannelList(p0, p1)
case "get_guild_list":
return c.bot.CQGetGuildList()
case "get_guild_member_list":
p0 := p.Get("guild_id").Uint()
p1 := p.Get("next_token").String()
return c.bot.CQGetGuildMembers(p0, p1)
case "get_guild_meta_by_guest":
p0 := p.Get("guild_id").Uint()
return c.bot.CQGetGuildMetaByGuest(p0)