diff --git a/api.h b/api.h index 86f4234..a9e7e50 100644 --- a/api.h +++ b/api.h @@ -185,6 +185,12 @@ namespace cq::api { return utils::string_from_coolq(ret); } + inline std::string get_group_info_base64(const int64_t group_id, const bool no_cache = false) noexcept(false) { + const auto ret = raw::CQ_getGroupInfo(app::auth_code, group_id, no_cache); + __throw_if_needed(ret); + return utils::string_from_coolq(ret); + } + inline std::string get_group_member_list_base64(const int64_t group_id) noexcept(false) { const auto ret = raw::CQ_getGroupMemberList(app::auth_code, group_id); __throw_if_needed(ret); @@ -297,6 +303,14 @@ namespace cq::api { } } + inline Group get_group_info(const int64_t group_id, const bool no_cache = false) noexcept(false) { + try { + return ObjectHelper::from_base64(get_group_info_base64(group_id, no_cache)); + } catch (exception::ParseError &) { + throw exception::ApiError(exception::ApiError::INVALID_DATA); + } + } + inline std::vector get_group_member_list(const int64_t group_id) noexcept(false) { try { return ObjectHelper::multi_from_base64>(get_group_member_list_base64(group_id)); diff --git a/api_funcs.h b/api_funcs.h index 2537ac4..0356f5a 100644 --- a/api_funcs.h +++ b/api_funcs.h @@ -50,6 +50,7 @@ FUNC(const char *, getLoginNick, int32_t auth_code) FUNC(const char *, getStrangerInfo, int32_t auth_code, int64_t qq, cq_bool_t no_cache) FUNC(const char *, getFriendList, int32_t auth_code, cq_bool_t reserved) FUNC(const char *, getGroupList, int32_t auth_code) +FUNC(const char *, getGroupInfo, int32_t auth_code, int64_t group_id, cq_bool_t no_cache) FUNC(const char *, getGroupMemberList, int32_t auth_code, int64_t group_id) FUNC(const char *, getGroupMemberInfoV2, int32_t auth_code, int64_t group_id, int64_t qq, cq_bool_t no_cache) diff --git a/types.h b/types.h index bd85f5b..affa22e 100644 --- a/types.h +++ b/types.h @@ -93,6 +93,8 @@ namespace cq { int64_t group_id = 0; std::string group_name; + int32_t member_count = 0; // only available with get_group_info() + int32_t max_member_count = 0; // only available with get_group_info() static Group from_bytes(const std::string &bytes) { auto pack = utils::BinPack(bytes); @@ -100,6 +102,12 @@ namespace cq { try { group.group_id = pack.pop_int(); group.group_name = pack.pop_string(); + try { + // optional, since this method should work for both get_group_list() and get_group_info() + group.member_count = pack.pop_int(); + group.max_member_count = pack.pop_int(); + } catch (exception::BytesNotEnough &ignored) { + } } catch (exception::BytesNotEnough &) { throw exception::ParseError("failed to parse from bytes to a Group object"); }