From f316278c57f7e7302ee08c5458b4b5307f157a94 Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Sun, 7 Nov 2021 16:28:27 +0800 Subject: [PATCH] feat: get_guild_meta_by_guest api --- coolq/api.go | 24 +++++++++++++++++++++++- modules/api/api.go | 3 +++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/coolq/api.go b/coolq/api.go index 60d329c..a56fd21 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -65,7 +65,7 @@ func (bot *CQBot) CQGetGuildServiceProfile() global.MSG { func (bot *CQBot) CQGetGuildList() global.MSG { fs := make([]global.MSG, 0, len(bot.Client.GuildService.Guilds)) for _, info := range bot.Client.GuildService.Guilds { - channels := make([]global.MSG, len(info.Channels)) + channels := make([]global.MSG, 0, len(info.Channels)) for _, channel := range info.Channels { channels = append(channels, global.MSG{ "channel_id": channel.ChannelId, @@ -83,6 +83,28 @@ func (bot *CQBot) CQGetGuildList() global.MSG { return OK(fs) } +// CQGetGuildMetaByGuest 通过访客权限获取频道元数据 +// @route(get_guild_meta_by_guest) +// @rename(guildId->guild_id) +func (bot *CQBot) CQGetGuildMetaByGuest(guildId int64) global.MSG { + meta, err := bot.Client.GuildService.FetchGuestGuild(uint64(guildId)) + if err != nil { + log.Errorf("获取频道元数据时出现错误: %v", err) + return Failed(100, "API_ERROR", err.Error()) + } + return OK(global.MSG{ + "guild_id": meta.GuildId, + "guild_name": meta.GuildName, + "guild_profile": meta.GuildProfile, + "create_time": meta.CreateTime, + "max_member_count": meta.MaxMemberCount, + "max_robot_count": meta.MaxRobotCount, + "max_admin_count": meta.MaxAdminCount, + "member_count": meta.MemberCount, + "owner_id": meta.OwnerId, + }) +} + // CQGetFriendList 获取好友列表 // // https://git.io/Jtz1L diff --git a/modules/api/api.go b/modules/api/api.go index b20a48a..ebf0956 100644 --- a/modules/api/api.go +++ b/modules/api/api.go @@ -125,6 +125,9 @@ func (c *Caller) call(action string, p Getter) global.MSG { return c.bot.CQGetGroupSystemMessages() case "get_guild_list": return c.bot.CQGetGuildList() + case "get_guild_meta_by_guest": + p0 := p.Get("guild_id").Int() + return c.bot.CQGetGuildMetaByGuest(p0) case "get_guild_service_profile": return c.bot.CQGetGuildServiceProfile() case "get_image":