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

Commit cf90289

Browse files
committed
整理实例.
1 parent c46a9b9 commit cf90289

18 files changed

+178
-669
lines changed

examples/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,13 @@ api_exe(RepeatMessage)
2222
api_exe(SendImageMessage)
2323
api_exe(GetFriendList)
2424
api_exe(GetGroupList)
25-
api_exe(Mute)
26-
api_exe(Recall)
27-
api_exe(RichMessage)
2825
api_exe(NewFriendEvent)
2926
api_exe(MemberJoinEvent)
3027
api_exe(BotEvents)
3128
api_exe(MemberLeaveEvent)
32-
api_exe(RecallEvent)
3329
api_exe(MessageType)
34-
api_exe(FetchEventsViaHTTP)
3530
api_exe(GroupMemberInfo)
36-
api_exe(GroupNameChange)
3731
api_exe(GroupConfig)
38-
api_exe(MemberCardChange)
3932
api_exe(Command)
4033
api_exe(VoiceMessage)
4134
api_exe(NudgeEvent)

examples/FetchEventsViaHTTP.cpp

Lines changed: 0 additions & 55 deletions
This file was deleted.

examples/FileMessage.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,16 @@
22
// 使用静态库必须要在引入 mirai.h 前定义这个宏
33
#define MIRAICPP_STATICLIB
44
#include <mirai.h>
5+
using namespace std;
6+
using namespace Cyan;
57

6-
int main()
8+
int main(int argc, char* argv[])
79
{
8-
using namespace std;
9-
using namespace Cyan;
1010
system("chcp 65001");
11-
MiraiBot bot("localhost", 8762);
12-
while (true)
13-
{
14-
try
15-
{
16-
bot.Verify("VerifyKeyASDEWQ", 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;
11+
MiraiBot bot;
12+
SessionOptions opts = SessionOptions::FromCommandLine(argc, argv);
13+
bot.Connect(opts);
14+
cout << "Bot working..." << endl;
2615

2716
bot.On<GroupMessage>(
2817
[&](GroupMessage m)
@@ -56,7 +45,14 @@ int main()
5645
}
5746
});
5847

59-
bot.EventLoop();
60-
48+
string command;
49+
while (cin >> command)
50+
{
51+
if (command == "exit")
52+
{
53+
bot.Disconnect();
54+
break;
55+
}
56+
}
6157
return 0;
6258
}

examples/GetFriendList.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,16 @@
22
// 使用静态库必须要在引入 mirai.h 前定义这个宏
33
#define MIRAICPP_STATICLIB
44
#include <mirai.h>
5+
using namespace std;
6+
using namespace Cyan;
57

6-
int main()
8+
int main(int argc, char* argv[])
79
{
8-
using namespace std;
9-
using namespace Cyan;
1010
system("chcp 65001");
11-
MiraiBot bot("127.0.0.1", 539);
12-
while (true)
13-
{
14-
try
15-
{
16-
bot.Verify("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;
11+
MiraiBot bot;
12+
SessionOptions opts = SessionOptions::FromCommandLine(argc, argv);
13+
bot.Connect(opts);
14+
cout << "Bot working..." << endl;
2615

2716
try
2817
{
@@ -38,7 +27,15 @@ int main()
3827
cerr << ex.what() << endl;
3928
}
4029

41-
bot.EventLoop();
30+
string command;
31+
while (cin >> command)
32+
{
33+
if (command == "exit")
34+
{
35+
bot.Disconnect();
36+
break;
37+
}
38+
}
4239

4340
return 0;
4441
}

examples/GroupConfig.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,16 @@
22
// 使用静态库必须要在引入 mirai.h 前定义这个宏
33
#define MIRAICPP_STATICLIB
44
#include <mirai.h>
5+
using namespace std;
6+
using namespace Cyan;
57

6-
int main()
8+
int main(int argc, char* argv[])
79
{
8-
using namespace std;
9-
using namespace Cyan;
1010
system("chcp 65001");
11-
MiraiBot bot("127.0.0.1", 539);
12-
while (true)
13-
{
14-
try
15-
{
16-
bot.Verify("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;
11+
MiraiBot bot;
12+
SessionOptions opts = SessionOptions::FromCommandLine(argc, argv);
13+
bot.Connect(opts);
14+
cout << "Bot working..." << endl;
2615

2716

2817
GroupConfig group_config = bot.GetGroupConfig(1029259687_gid);
@@ -33,9 +22,15 @@ int main()
3322

3423
cout << group_config.Name << endl;
3524

36-
37-
bot.EventLoop();
38-
25+
string command;
26+
while (cin >> command)
27+
{
28+
if (command == "exit")
29+
{
30+
bot.Disconnect();
31+
break;
32+
}
33+
}
3934

4035
return 0;
4136
}

examples/GroupNameChange.cpp

Lines changed: 0 additions & 36 deletions
This file was deleted.

examples/MemberCardChange.cpp

Lines changed: 0 additions & 39 deletions
This file was deleted.

examples/MemberJoinEvent.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,16 @@
22
// 使用静态库必须要在引入 mirai.h 前定义这个宏
33
#define MIRAICPP_STATICLIB
44
#include <mirai.h>
5+
using namespace std;
6+
using namespace Cyan;
57

6-
int main()
8+
int main(int argc, char* argv[])
79
{
8-
using namespace std;
9-
using namespace Cyan;
1010
system("chcp 65001");
11-
MiraiBot bot("127.0.0.1", 539);
12-
while (true)
13-
{
14-
try
15-
{
16-
bot.Verify("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;
11+
MiraiBot bot;
12+
SessionOptions opts = SessionOptions::FromCommandLine(argc, argv);
13+
bot.Connect(opts);
14+
cout << "Bot working..." << endl;
2615

2716
bot.On<MemberJoinRequestEvent>(
2817
[&](MemberJoinRequestEvent newMember)
@@ -42,9 +31,15 @@ int main()
4231
});
4332

4433

45-
46-
47-
bot.EventLoop();
34+
string command;
35+
while (cin >> command)
36+
{
37+
if (command == "exit")
38+
{
39+
bot.Disconnect();
40+
break;
41+
}
42+
}
4843

4944
return 0;
5045
}

0 commit comments

Comments
 (0)