Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit 64ba679

Browse files
committed
支持修改群名片/群头衔;
1 parent 0e8d5c2 commit 64ba679

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

include/mirai_bot.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ namespace Cyan
6666
vector<Group_t> GetGroupList();
6767
vector<GroupMember_t> GetGroupMembers(GID_t target);
6868
GroupMemberInfo GetGroupMemberInfo(GID_t gid, QQ_t memberId);
69+
bool SetGroupMemberInfo(GID_t gid, QQ_t memberId, const GroupMemberInfo& memberInfo);
70+
bool SetGroupMemberName(GID_t gid, QQ_t memberId, const string& name);
71+
bool SetGroupMemberSpecialTitle(GID_t gid, QQ_t memberId, const string& title);
6972
bool MuteAll(GID_t target);
7073
bool UnMuteAll(GID_t target);
7174
bool Mute(GID_t GID, QQ_t memberID, unsigned int time_seconds);

src/mirai_bot.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,50 @@ namespace Cyan
385385
return result;
386386
}
387387

388+
bool MiraiBot::SetGroupMemberInfo(GID_t gid, QQ_t memberId, const GroupMemberInfo& memberInfo)
389+
{
390+
json data =
391+
{
392+
{ "sessionKey", sessionKey_ },
393+
{ "target", int64_t(gid)},
394+
{ "memberId", int64_t(memberId)}
395+
};
396+
data["info"] = memberInfo.ToJson();
397+
398+
auto res = http_client_.Post("/memberInfo", data.dump(), "application/json;charset=UTF-8");
399+
if (res)
400+
{
401+
if (res->status != 200)
402+
throw std::runtime_error("[mirai-api-http error]: " + res->body);
403+
json reJson = json::parse(res->body);
404+
int code = reJson["code"].get<int>();
405+
if (code == 0)
406+
return true;
407+
else
408+
{
409+
string msg = reJson["msg"].get<string>();
410+
throw runtime_error(msg);
411+
}
412+
}
413+
else
414+
throw std::runtime_error("网络错误");
415+
return false;
416+
}
417+
418+
bool MiraiBot::SetGroupMemberName(GID_t gid, QQ_t memberId, const string& name)
419+
{
420+
auto memberInfo = this->GetGroupMemberInfo(gid, memberId);
421+
memberInfo.Name = name;
422+
return this->SetGroupMemberInfo(gid, memberId, memberInfo);
423+
}
424+
425+
bool MiraiBot::SetGroupMemberSpecialTitle(GID_t gid, QQ_t memberId, const string& title)
426+
{
427+
auto memberInfo = this->GetGroupMemberInfo(gid, memberId);
428+
memberInfo.SpecialTitle = title;
429+
return this->SetGroupMemberInfo(gid, memberId, memberInfo);
430+
}
431+
388432
bool MiraiBot::MuteAll(GID_t target)
389433
{
390434
json data =

0 commit comments

Comments
 (0)