Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit bf6b65c

Browse files
committed
更新 example;
1 parent ea26c3d commit bf6b65c

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

examples/RepeatMessage.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ int main()
77
{
88
using namespace std;
99
using namespace Cyan;
10-
system("chcp 65001");
10+
11+
// 源文件使用 UTF-8 编码保存,在 Windows 上需要切换代码页才不会显示乱码
12+
#if defined(WIN32) || defined(_WIN32)
13+
system("chcp 65001");
14+
#endif
15+
1116
MiraiBot bot("127.0.0.1", 539);
17+
18+
// 检查一下版本
1219
try
1320
{
21+
// 获取 mirai-api-http 插件地版本
1422
string current_version = bot.GetApiVersion();
23+
// 获取 mirai-cpp 适配的版本
1524
string required_version = bot.GetRequiredApiVersion();
1625
cout << "! 需要的 API 版本: " << required_version
1726
<< "; 当前 API 版本: " << current_version << "; " << endl;
@@ -20,7 +29,12 @@ int main()
2029
cout << "! 警告: 你的 mirai-api-http 插件的版本与 mirai-cpp 适配的版本不同,可能存在潜在的异常。" << endl;
2130
}
2231
}
23-
catch (const std::exception&) {}
32+
catch (const std::exception&ex)
33+
{
34+
cout << ex.what() << endl;
35+
}
36+
37+
// 自动重试地进行 Auth
2438
while (true)
2539
{
2640
try
@@ -34,24 +48,25 @@ int main()
3448
}
3549
MiraiBot::SleepSeconds(1);
3650
}
37-
cout << "成功登录 bot。" << endl;
51+
cout << "Bot Working..." << endl;
3852

53+
// 监听各类事件
3954
bot.OnEventReceived<GroupMessage>(
40-
[&](GroupMessage gm)
55+
[&](GroupMessage m)
4156
{
42-
gm.QuoteReply(gm.MessageChain);
57+
m.QuoteReply(m.MessageChain);
4358
});
4459

4560
bot.OnEventReceived<FriendMessage>(
46-
[&](FriendMessage fm)
61+
[&](FriendMessage m)
4762
{
48-
fm.Reply("你好呀, " + fm.MessageChain);
63+
m.Reply("你好呀, " + m.MessageChain);
4964
});
5065

5166
bot.OnEventReceived<TempMessage>(
52-
[&](TempMessage tm)
67+
[&](TempMessage m)
5368
{
54-
tm.Reply(tm.MessageChain);
69+
m.Reply(m.MessageChain);
5570
});
5671

5772

@@ -61,8 +76,5 @@ int main()
6176
cout << "轮询事件时出错: " << errMsg << endl;
6277
});
6378

64-
// 默认参数是在 cerr 输出错误
65-
// bot.EventLoop();
66-
6779
return 0;
6880
}

0 commit comments

Comments
 (0)