This repository was archived by the owner on Aug 16, 2024. It is now read-only.
File tree 2 files changed +28
-15
lines changed
2 files changed +28
-15
lines changed Original file line number Diff line number Diff line change @@ -13,16 +13,15 @@ int main(int argc, char* argv[])
13
13
bot.Connect (opts);
14
14
cout << " Bot working..." << endl;
15
15
16
- FriendImage img = bot.UploadFriendImage (" D:\\ test.png" );
17
- GroupImage gImg = bot.UploadGroupImage (" D:\\ test.png" );
18
- TempImage tImg = bot.UploadTempImage (" D:\\ test.png" );
16
+ string ImagePath (" E:/test.png" );
19
17
20
18
bot.On <FriendMessage>(
21
- [&](FriendMessage fm )
19
+ [&](FriendMessage m )
22
20
{
23
21
try
24
22
{
25
- fm.Reply (MessageChain ().Image (img));
23
+ FriendImage img = bot.UploadFriendImage (ImagePath);
24
+ m.Reply (MessageChain ().Image (img));
26
25
}
27
26
catch (const std::exception & ex)
28
27
{
@@ -31,11 +30,12 @@ int main(int argc, char* argv[])
31
30
});
32
31
33
32
bot.On <GroupMessage>(
34
- [&](GroupMessage gm )
33
+ [&](GroupMessage m )
35
34
{
36
35
try
37
36
{
38
- bot.SendMessage (gm.Sender .Group .GID , MessageChain ().Image (gImg ));
37
+ GroupImage gImg = bot.UploadGroupImage (ImagePath);
38
+ bot.SendMessage (m.Sender .Group .GID , MessageChain ().Image (gImg ));
39
39
}
40
40
catch (const std::exception & ex)
41
41
{
@@ -44,11 +44,12 @@ int main(int argc, char* argv[])
44
44
});
45
45
46
46
bot.On <TempMessage>(
47
- [&](TempMessage gm )
47
+ [&](TempMessage m )
48
48
{
49
49
try
50
50
{
51
- gm.Reply (MessageChain ().Image (tImg));
51
+ TempImage tImg = bot.UploadTempImage (ImagePath);
52
+ m.Reply (MessageChain ().Image (tImg));
52
53
}
53
54
catch (const std::exception & ex)
54
55
{
Original file line number Diff line number Diff line change @@ -79,14 +79,26 @@ namespace Cyan
79
79
}
80
80
virtual json ToJson () const override
81
81
{
82
- return
82
+ json result =
83
83
{
84
- { " type" , GetType () },
85
- { " imageId" , imageId_ },
86
- { " url" , url_ },
87
- { " path" , path_ },
88
- { " base64" , base64_ }
84
+ { " type" , GetType () }
89
85
};
86
+ imageId_.empty ()
87
+ ? result[" imageId" ] = json (nullptr )
88
+ : result[" imageId" ] = imageId_;
89
+
90
+ url_.empty ()
91
+ ? result[" url" ] = json (nullptr )
92
+ : result[" url" ] = url_;
93
+
94
+ path_.empty ()
95
+ ? result[" path" ] = json (nullptr )
96
+ : result[" path" ] = path_;
97
+
98
+ base64_.empty ()
99
+ ? result[" base64" ] = json (nullptr )
100
+ : result[" base64" ] = base64_;
101
+ return result;
90
102
}
91
103
virtual ~ImageMessage () {}
92
104
You can’t perform that action at this time.
0 commit comments