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

Commit a9d1a19

Browse files
authored
Merge pull request #38 from cyanray/dev/cyanray
支持mirai-http的指令系统
2 parents 1202893 + 6f134e2 commit a9d1a19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+414
-172
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ aux_source_directory(./src SRCS)
2323

2424
add_library(${PROJECT_NAME} ${LIBRARY_TYPE} ${SRCS})
2525
target_include_directories(${PROJECT_NAME} PUBLIC
26-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/mirai>
26+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
2727
$<INSTALL_INTERFACE:include>
2828
)
2929

examples/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ api_exe(FetchEventsViaHTTP)
3333
api_exe(GroupMemberInfo)
3434
api_exe(GroupNameChange)
3535
api_exe(GroupConfig)
36-
api_exe(MemberCardChange)
36+
api_exe(MemberCardChange)
37+
api_exe(Command)

examples/Command.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <iostream>
2+
#include <ctime>
3+
// 使用静态库必须要在引入 mirai.h 前定义这个宏
4+
#define MIRAICPP_STATICLIB
5+
#include <mirai.h>
6+
7+
int main()
8+
{
9+
using namespace std;
10+
using namespace Cyan;
11+
system("chcp 65001");
12+
MiraiBot bot("127.0.0.1", 539);
13+
while (true)
14+
{
15+
try
16+
{
17+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
18+
break;
19+
}
20+
catch (const std::exception& ex)
21+
{
22+
cout << ex.what() << endl;
23+
}
24+
MiraiBot::SleepSeconds(1);
25+
}
26+
cout << "成功登录 bot。" << endl;
27+
28+
try
29+
{
30+
bot.RegisterCommand("hello", { "hi","你好" }, "指令描述描述描述", "使用方法:/hello 你想说的话");
31+
auto managers = bot.GetManagers();
32+
for (auto manager : managers)
33+
{
34+
cout << "manager : " << manager << endl;
35+
}
36+
}
37+
catch (const std::exception& ex)
38+
{
39+
cout << ex.what() << endl;
40+
}
41+
42+
bot.On<Command>(
43+
[&](Command e)
44+
{
45+
cout << "收到指令: " << e.CommandName << ", "
46+
<< "发送者: " << e.Sender.ToInt64() << ", "
47+
<< "发送群: " << e.GroupId.ToInt64() << endl;
48+
cout << "参数:" << endl;
49+
for (const auto& arg : e.Args)
50+
cout << arg << " ";
51+
cout << endl;
52+
});
53+
54+
// 发送指令
55+
bot.SendCommand("hello", { "arg1","arg2" });
56+
57+
bot.EventLoop();
58+
return 0;
59+
}

include/mirai/defs/friend.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef mirai_cpp_defs_friend_hpp_H_
33
#define mirai_cpp_defs_friend_hpp_H_
44

5-
#include "third-party/nlohmann/json.hpp"
5+
#include "mirai/third-party/nlohmann/json.hpp"
66
#include "qq_types.hpp"
77
#include "serializable.hpp"
88

include/mirai/defs/group.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef mirai_cpp_defs_group_hpp_H_
33
#define mirai_cpp_defs_group_hpp_H_
44

5-
#include "third-party/nlohmann/json.hpp"
5+
#include "mirai/third-party/nlohmann/json.hpp"
66
#include "qq_types.hpp"
77
#include "serializable.hpp"
88

include/mirai/defs/group_config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef mirai_cpp_defs_group_config_hpp_H_
33
#define mirai_cpp_defs_group_config_hpp_H_
44

5-
#include "third-party/nlohmann/json.hpp"
5+
#include "mirai/third-party/nlohmann/json.hpp"
66
#include "serializable.hpp"
77

88
namespace Cyan

include/mirai/defs/group_member.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef mirai_cpp_defs_group_member_hpp_H_
33
#define mirai_cpp_defs_group_member_hpp_H_
44

5-
#include "third-party/nlohmann/json.hpp"
5+
#include "mirai/third-party/nlohmann/json.hpp"
66
#include "qq_types.hpp"
77
#include "serializable.hpp"
88
#include "group.hpp"

include/mirai/defs/group_member_info.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#define mirai_cpp_defs_group_member_info_hpp_H_
44

55
#include <string>
6-
#include "third-party/nlohmann/json.hpp"
6+
#include "mirai/third-party/nlohmann/json.hpp"
77
#include "serializable.hpp"
88

99

include/mirai/defs/message_chain.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
#ifndef mirai_cpp_defs_message_chain_hpp_H_
33
#define mirai_cpp_defs_message_chain_hpp_H_
44

5-
#include "third-party/nlohmann/json.hpp"
5+
#include "mirai/third-party/nlohmann/json.hpp"
66
#include <sstream>
77
#include <vector>
88
#include <memory>
9-
#include "exported.h"
9+
#include "mirai/exported.h"
1010
#include "qq_types.hpp"
1111
#include "serializable.hpp"
12-
#include "defs/message_interface.hpp"
13-
#include "defs/messages/PlainMessage.hpp"
14-
#include "defs/messages/ImageMessage.hpp"
15-
#include "defs/messages/FlashImageMessage.hpp"
16-
#include "defs/messages/AtMessage.hpp"
17-
#include "defs/messages/AtAllMessage.hpp"
18-
#include "defs/messages/FaceMessage.hpp"
19-
#include "defs/messages/XmlMessage.hpp"
20-
#include "defs/messages/AppMessage.hpp"
21-
#include "defs/messages/JsonMessage.hpp"
22-
#include "defs/messages/PokeMessage.hpp"
23-
#include "defs/messages/QuoteMessage.hpp"
12+
#include "message_interface.hpp"
13+
#include "messages/PlainMessage.hpp"
14+
#include "messages/ImageMessage.hpp"
15+
#include "messages/FlashImageMessage.hpp"
16+
#include "messages/AtMessage.hpp"
17+
#include "messages/AtAllMessage.hpp"
18+
#include "messages/FaceMessage.hpp"
19+
#include "messages/XmlMessage.hpp"
20+
#include "messages/AppMessage.hpp"
21+
#include "messages/JsonMessage.hpp"
22+
#include "messages/PokeMessage.hpp"
23+
#include "messages/QuoteMessage.hpp"
2424

2525
using std::vector;
2626

include/mirai/defs/message_interface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef mirai_cpp_defs_message_interface_hpp_H_
33
#define mirai_cpp_defs_message_interface_hpp_H_
44

5-
#include "third-party/nlohmann/json.hpp"
5+
#include "mirai/third-party/nlohmann/json.hpp"
66
#include "serializable.hpp"
77

88
namespace Cyan

0 commit comments

Comments
 (0)