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

Commit 5f7e8c2

Browse files
authored
Merge pull request #119 from cyanray/dev/cyanray
适配 mirai-api-http v2.3.1;
2 parents 546fbbb + a72a953 commit 5f7e8c2

20 files changed

+291
-107
lines changed

examples/GroupFile.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ int main(int argc, char* argv[])
2525
// 取群列表的第一个群
2626
auto& group = groups.front();
2727
// 获取该群的群文件列表
28-
vector<GroupFile> fileList = bot.GetGroupFiles(group.GID);
28+
vector<GroupFile> fileList = bot.GetGroupFiles(group.GID, true);
2929
if (fileList.empty())
3030
{
3131
cout << "这个群没有群文件!" << endl;
3232
}
3333
for (int i = 0; i < fileList.size(); i++)
3434
{
3535
cout << i << ". " << fileList[i].Name << endl;
36+
if (fileList[i].DownloadInfo)
37+
{
38+
cout << fileList[i].DownloadInfo->ToString() << endl;
39+
}
3640
}
3741
}
3842
else
Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
#pragma once
2-
#ifndef mirai_cpp_defs_group_file_info_hpp_H_
3-
#define mirai_cpp_defs_group_file_info_hpp_H_
2+
#ifndef mirai_cpp_defs_file_download_info_hpp_H_
3+
#define mirai_cpp_defs_file_download_info_hpp_H_
44

55
#include "mirai/third-party/nlohmann/json.hpp"
66
#include "mirai/defs/qq_types.hpp"
77
#include "serializable.hpp"
88

99
namespace Cyan
1010
{
11-
// 群文件详细信息
12-
class GroupFileInfo : public ISerializable
11+
/**
12+
* @brief 文件下载信息
13+
*/
14+
class FileDownloadInfo : public ISerializable
1315
{
1416
public:
15-
/**
16-
* @brief 文件名称
17-
*/
18-
string Name;
19-
/**
20-
* @brief 文件ID
21-
*/
22-
string Id;
23-
/**
24-
* @brief 完整路径
25-
*/
26-
string Path;
2717
/**
2818
* @brief 下载地址
2919
*/
@@ -36,10 +26,6 @@ namespace Cyan
3626
* @brief Md5
3727
*/
3828
string Md5;
39-
/**
40-
* @brief 文件大小
41-
*/
42-
size_t Size = 0;
4329
/**
4430
* @brief 下载次数
4531
*/
@@ -59,13 +45,9 @@ namespace Cyan
5945

6046
virtual bool Set(const json& j) override
6147
{
62-
Name = j["name"].get<string>();
63-
Id = j["id"].get<string>();
64-
Path = j["path"].get<string>();
65-
DownloadUrl = j["downloadUrl"].get<string>();
48+
DownloadUrl = j["url"].get<string>();
6649
Sha1 = j["sha1"].get<string>();
6750
Md5 = j["md5"].get<string>();
68-
Size = j["length"].get<size_t>();
6951
DownloadCount = j["downloadTimes"].get<size_t>();
7052
UploadTime = j["uploadTime"].get<int64_t>();
7153
LastModifyTime = j["lastModifyTime"].get<int64_t>();
@@ -76,13 +58,9 @@ namespace Cyan
7658
{
7759
return
7860
{
79-
{ "name", Name },
80-
{ "id", Id },
81-
{ "path", Path },
82-
{ "downloadUrl", DownloadUrl },
61+
{ "url", DownloadUrl },
8362
{ "sha1", Sha1 },
8463
{ "md5", Md5 },
85-
{ "length", Size },
8664
{ "downloadTimes", DownloadCount },
8765
{ "uploadTime", UploadTime },
8866
{ "lastModifyTime", LastModifyTime },
@@ -93,4 +71,4 @@ namespace Cyan
9371

9472
}
9573

96-
#endif // !mirai_cpp_defs_group_file_info_hpp_H_
74+
#endif // !mirai_cpp_defs_file_download_info_hpp_H_

include/mirai/defs/defs.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
#include "profile.hpp"
1313
#include "group_config.hpp"
1414
#include "group_file.hpp"
15-
#include "group_file_info.hpp"
15+
#include "FileDownloadInfo.hpp"
1616

1717
#endif // !mirai_cpp_defs_defs_hpp_H_

include/mirai/defs/group_file.hpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#ifndef mirai_cpp_defs_group_file_hpp_H_
33
#define mirai_cpp_defs_group_file_hpp_H_
44
#include <memory>
5+
#include <optional>
56
#include "mirai/third-party/nlohmann/json.hpp"
67
#include "mirai/defs/qq_types.hpp"
78
#include "serializable.hpp"
9+
#include "FileDownloadInfo.hpp"
810
using std::shared_ptr;
911

1012
namespace Cyan
@@ -18,6 +20,11 @@ namespace Cyan
1820
*/
1921
bool IsDirectory = false;
2022

23+
/**
24+
* @brief 文件大小
25+
*/
26+
int Size = 0;
27+
2128
/**
2229
* @brief 文件名称
2330
*/
@@ -43,8 +50,14 @@ namespace Cyan
4350
*/
4451
std::shared_ptr<GroupFile> ParentDirectory = nullptr;
4552

53+
/**
54+
* @brief 文件下载信息
55+
*/
56+
std::optional<FileDownloadInfo> DownloadInfo = std::nullopt;
57+
4658
virtual bool Set(const json& j) override
4759
{
60+
Size = j["size"].get<int64_t>();
4861
Name = j["name"].get<string>();
4962
Id = j["id"].get<string>();
5063
Path = j["path"].get<string>();
@@ -55,6 +68,12 @@ namespace Cyan
5568
ParentDirectory = std::make_shared<GroupFile>();
5669
ParentDirectory->Set(j["parent"]);
5770
}
71+
if (!j["downloadInfo"].is_null())
72+
{
73+
FileDownloadInfo t;
74+
t.Set(j["downloadInfo"]);
75+
DownloadInfo = t;
76+
}
5877
return true;
5978
}
6079
virtual json ToJson() const override
@@ -64,10 +83,12 @@ namespace Cyan
6483
{ "name", Name },
6584
{ "id", Id },
6685
{ "path", Path },
86+
{ "size", Size },
6787
{ "contact", Group.ToJson() },
6888
{ "isFile", !IsDirectory },
69-
{ "isDictionary", IsDirectory },
70-
{ "parent", ParentDirectory != nullptr ? ParentDirectory->ToJson() : RootDirectoryJson() }
89+
{ "isDirectory", IsDirectory },
90+
{ "parent", ParentDirectory != nullptr ? ParentDirectory->ToJson() : RootDirectoryJson() },
91+
{ "downloadInfo", DownloadInfo ? DownloadInfo->ToJson() : json(nullptr) }
7192
};
7293
}
7394
private:
@@ -77,10 +98,12 @@ namespace Cyan
7798
{
7899
{ "id", json(nullptr) },
79100
{ "parent", json(nullptr) },
101+
{ "downloadInfo", json(nullptr) },
80102
{ "name", "" },
81103
{ "path", "/" },
104+
{ "Size", 0 },
82105
{ "isFile", false },
83-
{ "isDictionary", true },
106+
{ "isDirectory", true },
84107
{ "contact", Group.ToJson() }
85108
};
86109
}

include/mirai/defs/qq_types.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ namespace Cyan
134134
string Id;
135135
string Url;
136136
string Path;
137+
/**
138+
* @brief 语音长度
139+
*/
140+
size_t Length;
137141
};
138142

139143
/**
@@ -143,6 +147,9 @@ namespace Cyan
143147
{
144148
string Id;
145149
string FileName;
150+
/**
151+
* @brief 文件大小
152+
*/
146153
size_t FileSize = 0;
147154
int InternalId = 102;
148155
};

include/mirai/events/BotJoinGroupEvent.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#ifndef mirai_cpp_events_BotJoinGroupEvent_hpp_H_
33
#define mirai_cpp_events_BotJoinGroupEvent_hpp_H_
44

5+
#include <optional>
56
#include "mirai/third-party/nlohmann/json.hpp"
67
#include "event_interface.hpp"
78
#include "mirai/defs/group.hpp"
9+
#include "mirai/defs/group_member.hpp"
10+
using std::optional;
811

912
namespace Cyan
1013
{
@@ -16,6 +19,7 @@ namespace Cyan
1619
{
1720
public:
1821
Group_t Group;
22+
std::optional<GroupMember> Inviter;
1923

2024
static MiraiEvent GetMiraiEvent()
2125
{
@@ -25,6 +29,12 @@ namespace Cyan
2529
virtual bool Set(const json& j) override
2630
{
2731
this->Group.Set(j["group"]);
32+
if (!j["invitor"].is_null())
33+
{
34+
GroupMember tmp;
35+
tmp.Set(j["invitor"]);
36+
this->Inviter = tmp;
37+
}
2838
return true;
2939
}
3040

@@ -33,6 +43,9 @@ namespace Cyan
3343
json j = json::object();
3444
j["type"] = "BotJoinGroupEvent";
3545
j["group"] = this->Group.ToJson();
46+
// Not a typo, MAH made a typo.
47+
j["invitor"] = (Inviter ? this->Inviter->ToJson() : json(nullptr));
48+
3649
return j;
3750
}
3851
};

include/mirai/events/BotLeaveEventKick.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#ifndef mirai_cpp_events_BotLeaveEventKick_hpp_H_
33
#define mirai_cpp_events_BotLeaveEventKick_hpp_H_
44

5+
#include <optional>
56
#include "mirai/third-party/nlohmann/json.hpp"
67
#include "mirai/defs/group.hpp"
8+
#include "mirai/defs/group_member.hpp"
79
#include "event_interface.hpp"
10+
using std::optional;
811

912
namespace Cyan
1013
{
@@ -16,6 +19,7 @@ namespace Cyan
1619
{
1720
public:
1821
Group_t Group;
22+
std::optional<GroupMember> Operator;
1923

2024
static MiraiEvent GetMiraiEvent()
2125
{
@@ -25,13 +29,20 @@ namespace Cyan
2529
virtual bool Set(const json& j) override
2630
{
2731
this->Group.Set(j["group"]);
32+
if (!j["operator"].is_null())
33+
{
34+
GroupMember tmp;
35+
tmp.Set(j["operator"]);
36+
this->Operator = tmp;
37+
}
2838
return true;
2939
}
3040
virtual json ToJson() const override
3141
{
3242
json j = json::object();
3343
j["type"] = "BotLeaveEventKick";
3444
j["group"] = this->Group.ToJson();
45+
j["operator"] = (Operator ? this->Operator->ToJson() : json(nullptr));
3546
return j;
3647
}
3748

include/mirai/events/MemberJoinEvent.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#ifndef mirai_cpp_events_MemberJoinEvent_hpp_H_
33
#define mirai_cpp_events_MemberJoinEvent_hpp_H_
44

5+
#include <optional>
56
#include "mirai/third-party/nlohmann/json.hpp"
67
#include "mirai/defs/group_member.hpp"
78
#include "event_interface.hpp"
9+
using std::optional;
810

911
namespace Cyan
1012
{
@@ -16,6 +18,7 @@ namespace Cyan
1618
{
1719
public:
1820
GroupMember NewMember;
21+
std::optional<GroupMember> Inviter;
1922

2023
static MiraiEvent GetMiraiEvent()
2124
{
@@ -25,13 +28,21 @@ namespace Cyan
2528
virtual bool Set(const json& j) override
2629
{
2730
this->NewMember.Set(j["member"]);
31+
if (!j["invitor"].is_null())
32+
{
33+
GroupMember tmp;
34+
tmp.Set(j["invitor"]);
35+
this->Inviter = tmp;
36+
}
2837
return true;
2938
}
3039
virtual json ToJson() const override
3140
{
3241
json j = json::object();
3342
j["type"] = "MemberJoinEvent";
3443
j["member"] = this->NewMember.ToJson();
44+
// Not a typo, MAH made a typo.
45+
j["invitor"] = (Inviter ? this->Inviter->ToJson() : json(nullptr));
3546
return j;
3647
}
3748

include/mirai/messages/AppMessage.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
#pragma once
22
#ifndef mirai_cpp_defs_messages_app_message_hpp_H_
33
#define mirai_cpp_defs_messages_app_message_hpp_H_
4+
5+
#include <string>
6+
#include <string_view>
47
#include "mirai/defs/message_interface.hpp"
8+
using std::string;
9+
using std::string_view;
510

611
namespace Cyan
712
{
813
class AppMessage : public IMessage
914
{
1015
public:
1116
AppMessage() : content_() {}
12-
AppMessage(const string& content) : content_(content) {}
17+
AppMessage(std::string_view content) : content_(content) {}
1318
AppMessage(const AppMessage& m) : content_(m.content_) {}
1419
AppMessage(AppMessage&& m) noexcept
1520
{
@@ -49,7 +54,7 @@ namespace Cyan
4954
virtual ~AppMessage() {}
5055

5156
const string& Content() const { return content_; }
52-
void Content(const string& content) { this->content_ = content; }
57+
void Content(std::string_view content) { this->content_ = content; }
5358

5459
private:
5560
const string type_ = "App";

0 commit comments

Comments
 (0)