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

Commit 07df1a9

Browse files
committed
改正 examples 的一些问题;
1 parent 335305e commit 07df1a9

12 files changed

+48
-110
lines changed

examples/BotEvents.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main()
1313
{
1414
try
1515
{
16-
bot.Auth("INITKEY7A3O1a9v", 1589588851qq);
16+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
1717
break;
1818
}
1919
catch (const std::exception& ex)
@@ -39,14 +39,7 @@ int main()
3939

4040

4141

42-
try
43-
{
44-
bot.EventLoop();
45-
}
46-
catch (const std::exception& ex)
47-
{
48-
cout << ex.what() << endl;
49-
}
42+
bot.EventLoop();
5043

5144
return 0;
5245
}

examples/GetFriendList.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main()
1313
{
1414
try
1515
{
16-
bot.Auth("INITKEY7A3O1a9v", 1589588851qq);
16+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
1717
break;
1818
}
1919
catch (const std::exception& ex)
@@ -24,21 +24,21 @@ int main()
2424
}
2525
cout << "成功登录 bot。" << endl;
2626

27-
auto friends = bot.GetFriendList();
28-
int i = 1;
29-
for (const auto& f : friends)
30-
{
31-
cout << (i++) << ". " << f.QQ << ", " << f.NickName << ", " << f.Remark << endl;
32-
}
33-
3427
try
3528
{
36-
bot.EventLoop();
29+
auto friends = bot.GetFriendList();
30+
int i = 1;
31+
for (const auto& f : friends)
32+
{
33+
cout << (i++) << ". " << f.QQ << ", " << f.NickName << ", " << f.Remark << endl;
34+
}
3735
}
3836
catch (const std::exception& ex)
3937
{
40-
cout << ex.what() << endl;
38+
cerr << ex.what() << endl;
4139
}
4240

41+
bot.EventLoop();
42+
4343
return 0;
4444
}

examples/GetGroupList.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main()
1313
{
1414
try
1515
{
16-
bot.Auth("INITKEY7A3O1a9v", 1589588851qq);
16+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
1717
break;
1818
}
1919
catch (const std::exception& ex)
@@ -36,14 +36,9 @@ int main()
3636
}
3737
}
3838

39-
try
40-
{
41-
bot.EventLoop();
42-
}
43-
catch (const std::exception& ex)
44-
{
45-
cout << ex.what() << endl;
46-
}
39+
40+
bot.EventLoop();
41+
4742

4843
return 0;
4944
}

examples/MemberJoinEvent.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main()
1313
{
1414
try
1515
{
16-
bot.Auth("INITKEY7A3O1a9v", 1589588851qq);
16+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
1717
break;
1818
}
1919
catch (const std::exception& ex)
@@ -24,7 +24,7 @@ int main()
2424
}
2525
cout << "成功登录 bot。" << endl;
2626

27-
bot.OnEventReceived<MemberJoinRequestEvent>(
27+
bot.On<MemberJoinRequestEvent>(
2828
[&](MemberJoinRequestEvent newMember)
2929
{
3030
cout << newMember.Message << endl;
@@ -36,20 +36,14 @@ int main()
3636
{
3737
string memberName = e.NewMember.MemberName;
3838
cout << memberName << endl;
39-
bot.SendMessage(e.NewMember.Group.GID,
39+
bot.SendMessage(e.NewMember.Group.GID,
4040
MessageChain().Plain("欢迎 " + memberName + " 加入本群!"));
4141
});
4242

4343

4444

45-
try
46-
{
47-
bot.EventLoop();
48-
}
49-
catch (const std::exception& ex)
50-
{
51-
cout << ex.what() << endl;
52-
}
45+
46+
bot.EventLoop();
5347

5448
return 0;
5549
}

examples/MemberLeaveEvent.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main()
1313
{
1414
try
1515
{
16-
bot.Auth("INITKEY7A3O1a9v", 1589588851qq);
16+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
1717
break;
1818
}
1919
catch (const std::exception& ex)
@@ -24,14 +24,14 @@ int main()
2424
}
2525
cout << "成功登录 bot。" << endl;
2626

27-
bot.OnEventReceived<MemberLeaveEventKick>(
27+
bot.On<MemberLeaveEventKick>(
2828
[&](MemberLeaveEventKick e)
2929
{
3030
auto mc = MessageChain().Plain("恭喜老哥 " + e.Member.MemberName + " 喜提飞机票!");
3131
bot.SendMessage(e.Member.Group.GID, mc);
3232
});
3333

34-
bot.OnEventReceived<MemberLeaveEventQuit>(
34+
bot.On<MemberLeaveEventQuit>(
3535
[&](MemberLeaveEventQuit e)
3636
{
3737
auto mc = MessageChain().Plain("老哥 " + e.Member.MemberName + " 主动离开了群聊!");
@@ -41,14 +41,9 @@ int main()
4141

4242

4343

44-
try
45-
{
46-
bot.EventLoop();
47-
}
48-
catch (const std::exception& ex)
49-
{
50-
cout << ex.what() << endl;
51-
}
44+
45+
bot.EventLoop();
46+
5247

5348
return 0;
5449
}

examples/Mute.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main()
1313
{
1414
try
1515
{
16-
bot.Auth("INITKEY7A3O1a9v", 1589588851qq);
16+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
1717
break;
1818
}
1919
catch (const std::exception& ex)
@@ -39,7 +39,7 @@ int main()
3939
});
4040

4141
bool res = false;
42-
res = bot.MuteAll(1029259687gid);
42+
res = bot.MuteAll(1029259687_gid);
4343
if (res)
4444
{
4545
cout << "全体禁言成功!" << endl;
@@ -51,7 +51,7 @@ int main()
5151

5252
MiraiBot::SleepSeconds(5);
5353

54-
res = bot.UnMuteAll(1029259687gid);
54+
res = bot.UnMuteAll(1029259687_gid);
5555
if (res)
5656
{
5757
cout << "解除全体禁言成功!" << endl;
@@ -61,7 +61,7 @@ int main()
6161
cout << "解除全体禁言失败" << endl;
6262
}
6363

64-
res = bot.Mute(1029259687gid, 211795583qq, 60);
64+
res = bot.Mute(1029259687_gid, 211795583_qq, 60);
6565
if (res)
6666
{
6767
cout << "禁言群员成功!" << endl;
@@ -73,7 +73,7 @@ int main()
7373

7474
MiraiBot::SleepSeconds(5);
7575

76-
res = bot.UnMute(1029259687gid, 211795583qq);
76+
res = bot.UnMute(1029259687_gid, 211795583_qq);
7777
if (res)
7878
{
7979
cout << "解除禁言群员成功!" << endl;

examples/NewFriendEvent.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main()
1313
{
1414
try
1515
{
16-
bot.Auth("INITKEY7A3O1a9v", 1589588851qq);
16+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
1717
break;
1818
}
1919
catch (const std::exception& ex)
@@ -32,14 +32,9 @@ int main()
3232

3333

3434

35-
try
36-
{
37-
bot.EventLoop();
38-
}
39-
catch (const std::exception& ex)
40-
{
41-
cout << ex.what() << endl;
42-
}
35+
36+
bot.EventLoop();
37+
4338

4439
return 0;
4540
}

examples/Recall.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main()
1313
{
1414
try
1515
{
16-
bot.Auth("INITKEY7A3O1a9v", 1589588851qq);
16+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
1717
break;
1818
}
1919
catch (const std::exception& ex)
@@ -34,6 +34,7 @@ int main()
3434
MiraiBot::SleepSeconds(5);
3535
bot.Recall(id);
3636
MiraiBot::SleepSeconds(2);
37+
// TODO: 不要撤回群主的消息,如果是BOT不是群主,撤回了群主的消息,会抛出异常
3738
gm.Recall();
3839
}
3940
catch (const std::exception& ex)
@@ -44,14 +45,6 @@ int main()
4445

4546

4647
bot.EventLoop();
47-
try
48-
{
49-
50-
}
51-
catch (const std::exception& ex)
52-
{
53-
cout << ex.what() << endl;
54-
}
5548

5649
return 0;
5750
}

examples/RecallEvent.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main()
1313
{
1414
try
1515
{
16-
bot.Auth("INITKEY7A3O1a9v", 1589588851qq);
16+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
1717
break;
1818
}
1919
catch (const std::exception& ex)
@@ -55,14 +55,6 @@ int main()
5555

5656

5757
bot.EventLoop();
58-
try
59-
{
60-
61-
}
62-
catch (const std::exception& ex)
63-
{
64-
cout << ex.what() << endl;
65-
}
6658

6759
return 0;
6860
}

examples/RepeatMessage.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main()
1313
{
1414
try
1515
{
16-
bot.Auth("INITKEY7A3O1a9v", 1589588851qq);
16+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
1717
break;
1818
}
1919
catch (const std::exception& ex)
@@ -43,14 +43,6 @@ int main()
4343
});
4444

4545
bot.EventLoop();
46-
try
47-
{
48-
49-
}
50-
catch (const std::exception& ex)
51-
{
52-
cout << ex.what() << endl;
53-
}
5446

5547
return 0;
5648
}

0 commit comments

Comments
 (0)