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 +60
-3
lines changed
Expand file tree Collapse file tree 3 files changed +60
-3
lines changed Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ // 使用静态库必须要在引入 mirai.h 前定义这个宏
3+ #define MIRAICPP_STATICLIB
4+ #include < mirai.h>
5+
6+ int main ()
7+ {
8+ using namespace std ;
9+ using namespace Cyan ;
10+ system (" chcp 65001" );
11+ MiraiBot bot (" 127.0.0.1" , 539 );
12+ while (true )
13+ {
14+ try
15+ {
16+ bot.Auth (" INITKEY7A3O1a9v" , 1589588851_qq);
17+ break ;
18+ }
19+ catch (const std::exception& ex)
20+ {
21+ cout << ex.what () << endl;
22+ }
23+ MiraiBot::SleepSeconds (1 );
24+ }
25+ cout << " 成功登录 bot。" << endl;
26+
27+ bot.OnEventReceived <GroupMessage>(
28+ [&](GroupMessage gm)
29+ {
30+ gm.QuoteReply (gm.MessageChain );
31+ });
32+
33+ bot.OnEventReceived <FriendMessage>(
34+ [&](FriendMessage fm)
35+ {
36+ fm.Reply (" 你好呀, " + fm.MessageChain );
37+ });
38+
39+ bot.OnEventReceived <TempMessage>(
40+ [&](TempMessage tm)
41+ {
42+ tm.Reply (tm.MessageChain );
43+ });
44+
45+ // 默认使用 WebSocket 拉取事件、消息
46+ // 如果要使用 HTTP 可以在 EventLoop 前执行 UseHTTP
47+ // 记录轮询事件时的错误
48+ bot.UseHTTP ().EventLoop ([](const char * errMsg)
49+ {
50+ cout << " 轮询事件时出错: " << errMsg << endl;
51+ });
52+
53+ // 默认参数是在 cerr 输出错误
54+ // bot.EventLoop();
55+
56+ return 0 ;
57+ }
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ int main()
6060
6161 });
6262
63- bot.UseWebSocket (). EventLoop ();
63+ bot.EventLoop ();
6464
6565 return 0 ;
6666}
Original file line number Diff line number Diff line change @@ -54,15 +54,15 @@ namespace Cyan
5454 host_ (" localhost" ),
5555 port_ (8080 ),
5656 cacheSize_ (4096 ),
57- ws_enabled_ (false ) {}
57+ ws_enabled_ (true ) {}
5858 MiraiBot (const string& host, int port) :
5959 qq_ (0 ),
6060 pool_ (4 ),
6161 http_client_ (host, port),
6262 host_ (host),
6363 port_ (port),
6464 cacheSize_ (4096 ),
65- ws_enabled_ (false ) {}
65+ ws_enabled_ (true ) {}
6666 ~MiraiBot ()
6767 {
6868 Release ();
You can’t perform that action at this time.
0 commit comments