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 +19
-4
lines changed
Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,15 @@ int main()
4242 tm.Reply (tm.MessageChain );
4343 });
4444
45- bot.EventLoop ();
45+
46+ // 记录轮询事件时的错误
47+ bot.EventLoop ([](const char * errMsg)
48+ {
49+ cout << " 轮询事件时出错: " << errMsg << endl;
50+ });
51+
52+ // 默认参数是在 cerr 输出错误
53+ // bot.EventLoop();
4654
4755 return 0 ;
4856}
Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ namespace Cyan
112112 std::this_thread::sleep_for (std::chrono::milliseconds (ms));
113113 }
114114
115- void EventLoop ();
115+ void EventLoop (function< void ( const char *)> errLogger = nullptr );
116116
117117 private:
118118 bool SessionVerify ();
Original file line number Diff line number Diff line change @@ -562,7 +562,7 @@ namespace Cyan
562562 }
563563
564564
565- void MiraiBot::EventLoop ()
565+ void MiraiBot::EventLoop (function< void ( const char *)> errLogger )
566566 {
567567 const unsigned count_per_loop = 20 ;
568568 const unsigned time_interval = 100 ;
@@ -575,7 +575,14 @@ namespace Cyan
575575 }
576576 catch (const std::exception& ex)
577577 {
578- std::cerr << ex.what () << std::endl;
578+ if (errLogger == nullptr )
579+ {
580+ std::cerr << ex.what () << std::endl;
581+ }
582+ else
583+ {
584+ errLogger (ex.what ());
585+ }
579586 }
580587
581588 if (count < count_per_loop)
You can’t perform that action at this time.
0 commit comments