This repository was archived by the owner on Aug 16, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +66
-1
lines changed
Expand file tree Collapse file tree 3 files changed +66
-1
lines changed Original file line number Diff line number Diff line change @@ -23,4 +23,5 @@ api_exe(NewFriendEvent)
2323api_exe(MemberJoinEvent)
2424api_exe(BotEvents)
2525api_exe(MemberLeaveEvent)
26- api_exe(RecallEvent)
26+ api_exe(RecallEvent)
27+ api_exe(MessageType)
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < algorithm>
3+ // 使用静态库必须要在引入 mirai.h 前定义这个宏
4+ #define MIRAICPP_STATICLIB
5+ #include < mirai.h>
6+
7+ int main ()
8+ {
9+ using namespace std ;
10+ using namespace Cyan ;
11+ system (" chcp 65001" );
12+ MiraiBot bot (" 127.0.0.1" , 539 );
13+ while (true )
14+ {
15+ try
16+ {
17+ bot.Auth (" INITKEY7A3O1a9v" , 1589588851_qq);
18+ break ;
19+ }
20+ catch (const std::exception& ex)
21+ {
22+ cout << ex.what () << endl;
23+ }
24+ MiraiBot::SleepSeconds (1 );
25+ }
26+ cout << " 成功登录 bot。" << endl;
27+
28+ bot.On <GroupMessage>(
29+ [&](GroupMessage gm)
30+ {
31+ cout << gm.MessageChain .ToString () << endl;
32+ MessageChain mc = gm.MessageChain ;
33+
34+ // 把收到的图片再发回去
35+ vector<MiraiImage> imgs = mc.GetImage ();
36+ if (imgs.size () != 0 )
37+ {
38+ gm.QuoteReply (MessageChain ().Plain (" 你发了 " ).Plain (imgs.size ()).Plain (" 张图" ));
39+ for (auto && img : imgs)
40+ {
41+ gm.Reply (MessageChain ().FlashImage (img));
42+ MiraiBot::SleepMilliseconds (500 );
43+ }
44+ }
45+
46+ // 如果有人发微笑,就问候对方 (微笑的id是14)
47+ vector<int > faceId = mc.GetFace ();
48+ auto result = find (faceId.begin (), faceId.end (), 14 );
49+ if (result != faceId.end ())
50+ {
51+ gm.QuoteReply (MessageChain ().Face (14 ));
52+ }
53+
54+ });
55+
56+ bot.EventLoop ();
57+
58+ return 0 ;
59+ }
Original file line number Diff line number Diff line change 44
55#include < nlohmann/json.hpp>
66#include < sstream>
7+ #include < vector>
78#include " qq_types.hpp"
89#include " serializable.hpp"
910
11+ using std::vector;
12+
1013namespace Cyan
1114{
1215
@@ -196,6 +199,7 @@ namespace Cyan
196199 }
197200 return string ();
198201 }
202+
199203 vector<string> GetPlain () const
200204 {
201205 vector<string> res;
@@ -208,6 +212,7 @@ namespace Cyan
208212 }
209213 return res;
210214 }
215+
211216 vector<MiraiImage> GetImage () const
212217 {
213218 vector<MiraiImage> res;
You can’t perform that action at this time.
0 commit comments