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

Commit 90dca5d

Browse files
authored
Merge pull request #10 from cyanray/dev/cyanray
今日重构
2 parents ae19822 + f981256 commit 90dca5d

File tree

10 files changed

+161
-294
lines changed

10 files changed

+161
-294
lines changed

include/defs/friend.hpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,9 @@ namespace Cyan
1616
QQ_t QQ;
1717
string NickName;
1818
string Remark;
19-
20-
Friend_t() = default;
21-
Friend_t(const Friend_t& f)
22-
{
23-
QQ = f.QQ;
24-
NickName = f.NickName;
25-
Remark = f.Remark;
26-
}
27-
Friend_t& operator=(const Friend_t& t)
28-
{
29-
Friend_t tmp(t);
30-
std::swap(this->QQ, tmp.QQ);
31-
std::swap(this->NickName, tmp.NickName);
32-
std::swap(this->Remark, tmp.Remark);
33-
return *this;
34-
}
35-
virtual ~Friend_t() = default;
3619
virtual bool Set(const json& j) override
3720
{
38-
QQ = (QQ_t)(j["id"].get<int64_t>());
21+
QQ = QQ_t(j["id"].get<int64_t>());
3922
NickName = j["nickname"].get<string>();
4023
Remark = j["remark"].get<string>();
4124
return true;

include/defs/group.hpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,9 @@ namespace Cyan
1616
GID_t GID;
1717
string Name;
1818
GroupPermission Permission;
19-
20-
Group_t() = default;
21-
Group_t(const Group_t& g)
22-
{
23-
GID = g.GID;
24-
Name = g.Name;
25-
Permission = g.Permission;
26-
}
27-
Group_t& operator=(const Group_t& t)
28-
{
29-
Group_t tmp(t);
30-
std::swap(this->GID, tmp.GID);
31-
std::swap(this->Name, tmp.Name);
32-
std::swap(this->Permission, tmp.Permission);
33-
return *this;
34-
}
35-
virtual ~Group_t() = default;
3619
virtual bool Set(const json& j) override
3720
{
38-
GID = (GID_t)(j["id"].get<int64_t>());
21+
GID = GID_t(j["id"].get<int64_t>());
3922
Name = j["name"].get<string>();
4023
Permission = GroupPermissionStr(j["permission"].get<string>());
4124
return true;

include/defs/group_member.hpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,6 @@ namespace Cyan
1818
string MemberName;
1919
GroupPermission Permission;
2020
Group_t Group;
21-
22-
GroupMember_t() = default;
23-
GroupMember_t(const GroupMember_t& gm)
24-
{
25-
QQ = gm.QQ;
26-
MemberName = gm.MemberName;
27-
Permission = gm.Permission;
28-
Group = gm.Group;
29-
}
30-
GroupMember_t& operator=(const GroupMember_t& t)
31-
{
32-
GroupMember_t tmp(t);
33-
std::swap(this->QQ, tmp.QQ);
34-
std::swap(this->MemberName, tmp.MemberName);
35-
std::swap(this->Permission, tmp.Permission);
36-
std::swap(this->Group, tmp.Group);
37-
return *this;
38-
}
39-
virtual ~GroupMember_t() = default;
4021
virtual bool Set(const json& j) override
4122
{
4223
QQ = (QQ_t)(j["id"].get<int64_t>());

include/defs/group_member_info.hpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@ namespace Cyan
1616
public:
1717
string Name;
1818
string SpecialTitle;
19-
20-
GroupMemberInfo() = default;
21-
GroupMemberInfo(const GroupMemberInfo& gm)
22-
{
23-
Name = gm.Name;
24-
SpecialTitle = gm.SpecialTitle;
25-
}
26-
GroupMemberInfo& operator=(const GroupMemberInfo& t)
27-
{
28-
GroupMemberInfo tmp(t);
29-
std::swap(this->Name, tmp.Name);
30-
std::swap(this->SpecialTitle, tmp.SpecialTitle);
31-
return *this;
32-
}
33-
virtual ~GroupMemberInfo() = default;
3419
virtual bool Set(const json& j) override
3520
{
3621
Name = j["name"].get<string>();

include/defs/message_chain.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ namespace Cyan
279279
return res;
280280
}
281281

282-
vector<QQ_t> GetAt()
282+
vector<QQ_t> GetAt() const
283283
{
284284
vector<QQ_t> res;
285285
for (const auto& ele : messages_)
@@ -294,7 +294,7 @@ namespace Cyan
294294
return res;
295295
}
296296

297-
vector<int> GetFace()
297+
vector<int> GetFace() const
298298
{
299299
vector<int> res;
300300
for (const auto& ele : messages_)
@@ -322,7 +322,7 @@ namespace Cyan
322322
virtual bool Set(const json& j) override
323323
{
324324
messages_ = j;
325-
if (j.size() >= 1)
325+
if (!j.empty())
326326
{
327327
try
328328
{

include/events/group_message.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ namespace Cyan
4141

4242
MessageId Reply(const Cyan::MessageChain& mc) const;
4343
MessageId QuoteReply(const Cyan::MessageChain& mc) const;
44-
bool Recall();
45-
bool AtMe();
44+
bool Recall() const;
45+
bool AtMe() const;
4646

4747
virtual bool Set(const json& j) override
4848
{

include/events/join_request_event.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ namespace Cyan
3535

3636
bool Accept()
3737
{
38-
return Respose(0, "");
38+
return Response(0, "");
3939
}
4040

4141
bool Reject(const string& message = "")
4242
{
43-
return Respose(1, message);
43+
return Response(1, message);
4444
}
4545

4646
bool Ignore(const string& message = "")
4747
{
48-
return Respose(2, message);
48+
return Response(2, message);
4949
}
5050

5151
bool RejectAndBlock(const string& message = "")
5252
{
53-
return Respose(3, message);
53+
return Response(3, message);
5454
}
5555

5656
bool IgnoreAndBlock(const string& message = "")
5757
{
58-
return Respose(4, message);
58+
return Response(4, message);
5959
}
6060

6161
virtual bool Set(const json& j) override
@@ -83,7 +83,7 @@ namespace Cyan
8383

8484
private:
8585
MiraiBot* bot_;
86-
bool Respose(int operate, const string& message);
86+
bool Response(int operate, const string& message);
8787
};
8888

8989
}

include/events/new_friend_event.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ namespace Cyan
3434

3535
bool Accept()
3636
{
37-
return Respose(0, "");
37+
return Response(0, "");
3838
}
3939

4040
bool Reject(const string& message = "")
4141
{
42-
return Respose(1, message);
42+
return Response(1, message);
4343
}
4444

4545
bool RejectAndBlock(const string& message = "")
4646
{
47-
return Respose(2, message);
47+
return Response(2, message);
4848
}
4949

5050
virtual bool Set(const json& j) override
@@ -70,7 +70,7 @@ namespace Cyan
7070

7171
private:
7272
MiraiBot* bot_;
73-
bool Respose(int operate, const string& message);
73+
bool Response(int operate, const string& message);
7474
};
7575

7676
}

src/event_func.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,68 +38,60 @@ namespace Cyan
3838
return bot_->SendMessage(Sender.Group.GID, mc, GetMessageId());
3939
}
4040

41-
bool GroupMessage::Recall()
41+
bool GroupMessage::Recall() const
4242
{
4343
return bot_->Recall(GetMessageId());
4444
}
4545

46-
bool GroupMessage::AtMe()
46+
bool GroupMessage::AtMe() const
4747
{
4848
auto at = MessageChain.GetAt();
4949
auto it = std::find(at.begin(), at.end(), bot_->GetBotQQ());
5050
if (it != at.end()) return true;
5151
else return false;
5252
}
5353

54-
bool NewFriendRequestEvent::Respose(int operate, const string& message)
54+
bool NewFriendRequestEvent::Response(int operate, const string& message)
5555
{
5656
json data =
5757
{
5858
{ "sessionKey", bot_->GetSessionKey() },
5959
{ "eventId", this->EventId},
60-
{ "fromId", (int64_t)this->FromId},
61-
{ "groupId", (int64_t)this->GroupId},
60+
{ "fromId", int64_t(this->FromId)},
61+
{ "groupId", int64_t(this->GroupId)},
6262
{ "operate", operate},
6363
{ "message", message},
6464
};
6565

6666
httplib::Client& http_client = *(bot_->GetHttpClient());
6767
auto res = http_client.Post("/resp/newFriendRequestEvent", data.dump(), "application/json;charset=UTF-8");
68-
if (res)
69-
{
70-
if (res->status != 200)
71-
throw std::runtime_error("[mirai-api-http error]: " + res->body);
72-
return true;
73-
}
74-
else
68+
if (!res)
7569
throw std::runtime_error("网络错误");
76-
70+
if (res->status != 200)
71+
throw std::runtime_error("[mirai-api-http error]: " + res->body);
72+
return true;
7773
}
7874

79-
bool MemberJoinRequestEvent::Respose(int operate, const string& message)
75+
bool MemberJoinRequestEvent::Response(int operate, const string& message)
8076
{
8177

8278
json data =
8379
{
8480
{ "sessionKey", bot_->GetSessionKey() },
8581
{ "eventId", this->EventId},
86-
{ "fromId", (int64_t)this->FromId},
87-
{ "groupId", (int64_t)this->GroupId},
82+
{ "fromId", int64_t(this->FromId)},
83+
{ "groupId", int64_t(this->GroupId)},
8884
{ "operate", operate},
8985
{ "message", message},
9086
};
9187

9288
httplib::Client& http_client = *(bot_->GetHttpClient());
9389
auto res = http_client.Post("/resp/memberJoinRequestEvent", data.dump(), "application/json;charset=UTF-8");
94-
if (res)
95-
{
96-
if (res->status != 200)
97-
throw std::runtime_error("[mirai-api-http error]: " + res->body);
98-
return true;
99-
}
100-
else
90+
if (!res)
10191
throw std::runtime_error("网络错误");
102-
92+
if (res->status != 200)
93+
throw std::runtime_error("[mirai-api-http error]: " + res->body);
94+
return true;
10395
}
10496

10597
}

0 commit comments

Comments
 (0)