Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Add get_group_info function
Browse files Browse the repository at this point in the history
  • Loading branch information
stdrc committed Oct 8, 2019
1 parent dac5421 commit fa0f5f3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<Group>(get_group_info_base64(group_id, no_cache));
} catch (exception::ParseError &) {
throw exception::ApiError(exception::ApiError::INVALID_DATA);
}
}

inline std::vector<GroupMember> get_group_member_list(const int64_t group_id) noexcept(false) {
try {
return ObjectHelper::multi_from_base64<std::vector<GroupMember>>(get_group_member_list_base64(group_id));
Expand Down
1 change: 1 addition & 0 deletions api_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,21 @@ 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);
Group group;
try {
group.group_id = pack.pop_int<int64_t>();
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<int32_t>();
group.max_member_count = pack.pop_int<int32_t>();
} catch (exception::BytesNotEnough &ignored) {
}
} catch (exception::BytesNotEnough &) {
throw exception::ParseError("failed to parse from bytes to a Group object");
}
Expand Down

0 comments on commit fa0f5f3

Please sign in to comment.