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

Commit a5b996e

Browse files
author
Numendacil
committed
dealing with null fields in VoiceMessage and ImageMessage
1 parent 8d4a639 commit a5b996e

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

include/mirai/messages/ImageMessage.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ namespace Cyan
6161
{
6262
if (json["type"].is_null() || json["type"].get<string>() != this->GetType())
6363
throw std::runtime_error("给定的json不正确");
64+
65+
imageId_ = "";
66+
url_ = "";
67+
path_ = "";
68+
base64_ = "";
69+
6470
if (!json["imageId"].is_null())
6571
imageId_ = json["imageId"].get<string>();
6672
if (!json["url"].is_null())
@@ -76,10 +82,10 @@ namespace Cyan
7682
return
7783
{
7884
{ "type", GetType() },
79-
{ "imageId", imageId_ },
80-
{ "url", url_ },
81-
{ "path", path_ },
82-
{ "base64", base64_ }
85+
{ "imageId", imageId_.empty()? nullptr : imageId_ },
86+
{ "url", url_.empty()? nullptr : url_ },
87+
{ "path", path_.empty()? nullptr : path_ },
88+
{ "base64", base64_.empty()? nullptr : base64_ }
8389
};
8490
}
8591
virtual ~ImageMessage() {}

include/mirai/messages/VoiceMessage.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ namespace Cyan
6363
{
6464
if (json["type"].is_null() || json["type"].get<string>() != this->GetType())
6565
throw std::runtime_error("给定的json不正确");
66+
67+
voiceId_ = "";
68+
url_ = "";
69+
path_ = "";
70+
base64_ = "";
71+
length_ = 0;
72+
6673
if (!json["voiceId"].is_null())
6774
voiceId_ = json["voiceId"].get<string>();
6875
if (!json["url"].is_null())
@@ -80,10 +87,10 @@ namespace Cyan
8087
return
8188
{
8289
{ "type", type_ },
83-
{ "voiceId", voiceId_ },
84-
{ "url", url_ },
85-
{ "path", path_ },
86-
{ "base64", base64_ },
90+
{ "voiceId", voiceId_.empty()? nullptr : voiceId_ },
91+
{ "url", url_.empty()? nullptr : url_ },
92+
{ "path", path_.empty()? nullptr : path_ },
93+
{ "base64", base64_.empty()? nullptr : base64_ },
8794
{ "length", length_ }
8895
};
8996
}

0 commit comments

Comments
 (0)