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

Commit 6566209

Browse files
authored
Merge pull request #96 from cyanray/dev/cyanray
新增: 支持群文件相关操作(重命名、移动、删除).
2 parents 777d6c7 + ea97044 commit 6566209

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

include/mirai/mirai_bot.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,26 @@ namespace Cyan
212212
* @return GroupFileInfo
213213
*/
214214
GroupFileInfo GetGroupFileInfo(GID_t gid, const GroupFile& groupFile);
215+
/**
216+
* @brief 重命名群文件
217+
* @param gid 群组(GID_t)
218+
* @param groupFile 群文件(GroupFile)
219+
* @param newName 新群文件名
220+
*/
221+
void GroupFileRename(GID_t gid, const GroupFile& groupFile, const string& newName);
222+
/**
223+
* @brief 移动群文件
224+
* @param gid 群组(GID_t)
225+
* @param groupFile 群文件(GroupFile)
226+
* @param moveToPath 移动目标路径, "/" 为根目录
227+
*/
228+
void GroupFileMove(GID_t gid, const GroupFile& groupFile, const string& moveToPath = "/");
229+
/**
230+
* @brief 删除群文件
231+
* @param gid 群组(GID_t)
232+
* @param groupFile 群文件(GroupFile)
233+
*/
234+
void GroupFileDelete(GID_t gid, const GroupFile& groupFile);
215235
/**
216236
* \brief 设置群成员的群名片和群头衔信息
217237
* \param gid 群组(GID_t)

src/mirai_bot.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,77 @@ namespace Cyan
559559
return result;
560560
}
561561

562+
void MiraiBot::GroupFileRename(GID_t gid, const GroupFile& groupFile, const string& newName)
563+
{
564+
json data =
565+
{
566+
{ "sessionKey", sessionKey_ },
567+
{ "target", int64_t(gid) },
568+
{ "id", groupFile.Id },
569+
{ "rename", newName }
570+
};
571+
572+
auto res = http_client_.Post("/groupFileRename", data.dump(), "application/json;charset=UTF-8");
573+
if (!res)
574+
throw std::runtime_error("网络错误");
575+
if (res->status != 200)
576+
throw std::runtime_error("[mirai-api-http error]: " + res->body);
577+
json re_json = json::parse(res->body);
578+
int code = re_json["code"].get<int>();
579+
if (code != 0)
580+
{
581+
string msg = re_json["msg"].get<string>();
582+
throw runtime_error(msg);
583+
}
584+
}
585+
586+
void MiraiBot::GroupFileMove(GID_t gid, const GroupFile& groupFile, const string& moveToPath)
587+
{
588+
json data =
589+
{
590+
{ "sessionKey", sessionKey_ },
591+
{ "target", int64_t(gid) },
592+
{ "id", groupFile.Id },
593+
{ "movePath", moveToPath }
594+
};
595+
596+
auto res = http_client_.Post("/groupFileMove", data.dump(), "application/json;charset=UTF-8");
597+
if (!res)
598+
throw std::runtime_error("网络错误");
599+
if (res->status != 200)
600+
throw std::runtime_error("[mirai-api-http error]: " + res->body);
601+
json re_json = json::parse(res->body);
602+
int code = re_json["code"].get<int>();
603+
if (code != 0)
604+
{
605+
string msg = re_json["msg"].get<string>();
606+
throw runtime_error(msg);
607+
}
608+
}
609+
610+
void MiraiBot::GroupFileDelete(GID_t gid, const GroupFile& groupFile)
611+
{
612+
json data =
613+
{
614+
{ "sessionKey", sessionKey_ },
615+
{ "target", int64_t(gid) },
616+
{ "id", groupFile.Id }
617+
};
618+
619+
auto res = http_client_.Post("/groupFileDelete", data.dump(), "application/json;charset=UTF-8");
620+
if (!res)
621+
throw std::runtime_error("网络错误");
622+
if (res->status != 200)
623+
throw std::runtime_error("[mirai-api-http error]: " + res->body);
624+
json re_json = json::parse(res->body);
625+
int code = re_json["code"].get<int>();
626+
if (code != 0)
627+
{
628+
string msg = re_json["msg"].get<string>();
629+
throw runtime_error(msg);
630+
}
631+
}
632+
562633
bool MiraiBot::MuteAll(GID_t target)
563634
{
564635
json data =

0 commit comments

Comments
 (0)