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 +27
-11
lines changed Expand file tree Collapse file tree 3 files changed +27
-11
lines changed Original file line number Diff line number Diff line change 1- #include < iostream>
1+ #include < iostream>
22// 使用静态库必须要在引入 mirai.h 前定义这个宏
33#define MIRAICPP_STATICLIB
44#include < mirai.h>
@@ -10,11 +10,12 @@ int main()
1010
1111 // 源文件使用 UTF-8 编码保存,在 Windows 上需要切换代码页才不会显示乱码
1212#if defined(WIN32) || defined(_WIN32)
13- system (" chcp 65001" );
13+ system (" chcp 65001" );
1414#endif
1515
16- MiraiBot bot (" 127.0.0.1" , 539 );
17-
16+ // 16 条事件处理线程
17+ MiraiBot bot (" 127.0.0.1" , 539 , 16 );
18+
1819 // 检查一下版本
1920 try
2021 {
@@ -29,7 +30,7 @@ system("chcp 65001");
2930 cout << " ! 警告: 你的 mirai-api-http 插件的版本与 mirai-cpp 适配的版本不同,可能存在潜在的异常。" << endl;
3031 }
3132 }
32- catch (const std::exception&ex)
33+ catch (const std::exception& ex)
3334 {
3435 cout << ex.what () << endl;
3536 }
@@ -62,7 +63,7 @@ system("chcp 65001");
6263 {
6364 m.Reply (" 2222 " + m.MessageChain );
6465 });
65-
66+
6667 bot.On <FriendMessage>(
6768 [&](FriendMessage m)
6869 {
@@ -81,16 +82,16 @@ system("chcp 65001");
8182 bot.On <Message>(
8283 [&](Message m)
8384 {
84- cout<< int64_t (m.Sender ) << " 发来一条消息." << endl;
85+ cout << int64_t (m.Sender ) << " 发来一条消息." << endl;
8586 m.Reply (" Message事件可处理三种消息:" + m.MessageChain );
8687
8788 // 判断是否群组消息
88- if (m.GetMessageType () == MessageType::GroupMessage)
89+ if (m.GetMessageType () == MessageType::GroupMessage)
8990 {
9091 GroupMessage gm = m.ToGroupMessage ();
9192 // TODO: 针对群组消息的特别处理
9293 }
93-
94+
9495 });
9596
9697
Original file line number Diff line number Diff line change 1- #pragma once
1+ #pragma once
22#ifndef mirai_cpp__mirai_bot_hpp_H_
33#define mirai_cpp__mirai_bot_hpp_H_
44#include < string>
@@ -44,6 +44,13 @@ namespace Cyan
4444 * \param port port
4545 */
4646 MiraiBot (const string& host, int port);
47+ /* *
48+ * \brief
49+ * \param host hostname
50+ * \param port port
51+ * \param threadNums 线程池线程数
52+ */
53+ MiraiBot (const string& host, int port, int threadNums);
4754 MiraiBot (const MiraiBot&) = delete ;
4855 MiraiBot& operator =(const MiraiBot&) = delete ;
4956 ~MiraiBot ();
Original file line number Diff line number Diff line change 1- #include " mirai_bot.hpp"
1+ #include " mirai_bot.hpp"
22#include < iostream>
33#include < exception>
44#include " easywsclient.hpp"
@@ -26,6 +26,14 @@ namespace Cyan
2626 ws_enabled_ (true ),
2727 http_client_ (host, port),
2828 pool_ (4 ) {}
29+ MiraiBot::MiraiBot (const string& host, int port, int threadNums) :
30+ host_ (host),
31+ port_ (port),
32+ qq_ (0 ),
33+ cacheSize_ (4096 ),
34+ ws_enabled_ (true ),
35+ http_client_ (host, port),
36+ pool_ (threadNums) {}
2937 MiraiBot::~MiraiBot ()
3038 {
3139 Release ();
You can’t perform that action at this time.
0 commit comments