Tips~ 如有意向一起开发本项目,请联系我邮箱 ( ̄▽ ̄)"
关于MiraiCP
API文档(包含示例) · 文档库 · demo
支持的事件
这些内容可以在Config.kt看到
事件名称 | 函数名称 |
---|---|
机器人上线 | BotOnlineEvent |
群聊消息 | GroupMessageEvent |
私聊消息 | PrivateMessageEvent |
好友申请 | NewFriendRequestEvent |
群聊邀请 | GroupInviteEvent |
新群成员申请 | MemberJoinRequestEvent |
新群成员加入 | MemberJoinEvent |
群成员离开 | MemberLeaveEvent |
机器人加入 | BotJoinEvent |
机器人离开 | BotLeaveEvent |
消息撤回 | RecallEvent |
群临时会话 | GroupTempMessageEvent |
定时事件执行 | SchedulingEvent |
戳一戳 | NugdeEvent |
特性
- C++ 17
- 使用cmake
- 使用jni与kt交互
- c++ utf8编码
- 与mirai-core同步发布(无需mah)
- 支持2种使用方法
- [从2.7.0开始]代码集中到一个hpp文件和其他固定依赖文件,每次更新只需要更新那个文件
- 不封装和隐藏底层实现代码,您可以自定义实现代码或通过实现代码提issue/pr
test
CI Name | status |
---|---|
C++ in windows(mingw&msvc) & linux(g++) | |
kotlin |
使用声明
-
MiraiCP是一个Mirai 的C++语言的社区SDK,基于Mirai-console和Mirai-core插件模板开发
-
本项目仅供学习参考,禁止用于任何商业用途(根据Mirai的AGPLv3许可协议开源)。
-
本项目不含有任何旨在破坏用户计算机数据和获取用户隐私的恶意代码,不含有任何跟踪、监视用户计算机功能代码,不会收集任何用户个人信息,不会泄露用户隐私。
-
本项目不提供任何具体功能实现,仅仅只是对项目mirai-console和mirai-core(详见mirai仓库)的二次封装。
-
任何单位或个人认为本项目可能涉嫌侵权,应及时提出反馈,本项目将会第一时间对违规内容给予删除等相关处理。
使用流程:
1 配置环境
mirai需要java环境 >=11
2 注意事项
- 从v2.6.3-RC开始,使用utf8作为编码, vs需要加/utf8编译参数,见微软文档, 而在CmakeLists里就表现为
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
- MiraiCP版本规则: 从2.2.0开始 (2021/1/31),版本前两位为Mirai的版本,后一位为SDK更新迭代版本
deprecated
方法一般只保存3个版本- 编译出的动态链接库不具备跨平台性, 如在windows下编译的库在linux上无法使用, 要在和目标同系统下编译或者用cmake交叉编译
3 使用方法:
3.1 如何使用MiraiCP SDK?
3.1.1 在demo里写
从MiraiCP-template 中下载模板并解压 在main.cpp中编写代码
3.1.2 在代码中加入MiraiCP sdk依赖
从MiraiCP-template 中下载Single_include文件夹
- 在你的
CMakeLists.txt
里引入JNI文件和single_include
下的文件
set(JAVA_AWT_LIBRARY NotNeeded)
set(JAVA_JVM_LIBRARY NotNeeded)
set(JAVA_AWT_INCLUDE_PATH NotNeeded)
find_package(JNI REQUIRED)
target_include_directories(<Target name> public
${CMAKE_CURRENT_SOURCE_DIR}/single_include/3rd_include
${CMAKE_CURRENT_SOURCE_DIR}/single_include/3rd_include/utf8
${CMAKE_CURRENT_SOURCE_DIR}/single_include/3rd_include/utf8/utf8
${CMAKE_CURRENT_SOURCE_DIR}/single_include/MiraiCP
${JAVA_INCLUDE_PATH}/
${JAVA_INCLUDE_PATH2}/)
其中, <target name>
是你构建的动态链接库的target
-
在你的target里包含
single_include/MiraiCP/MiraiCP.cpp
-
在你需要使用miraiCP sdk的文件
#include "MiraiCP.hpp"
和using namespace MiraiCP;
即可
3.2 启动SDK
3.2.1 使用loader直接使用
适用于只在机器人上使用MiraiCP SDK插件
-
从最新release 中下载MiraiCP-loader-*.jar(*号为版本)
-
在同目录下创建config.json作为配置文件
-
编写json:
{
"accounts": [{
"id": qqid,
"passwords": "passwords密码",
"protocol": "pad",
"heatBeat": "STAT_HB",
"md5": false,
"autoLogin": true
}],
"cppPaths": [
{"path": "dll路径"}
]
}
详细见config.md文档
- 使用java -jar MiraiCP-loader-*.jar 启动loader(*号为版本)
3.2.2 使用plugin作为mcl的插件使用
本种方法适用于还需要加载别的mirai-console插件
3.2.2.1 使用mcl自动下载
在mcl同级目录输入
mcl --update-package io.github.nambers:MiraiCP-plugin --channel nightly --type plugin
安装, 然后在mcl的路径下的data\miraiCP\路径中创建miraicp.json里填写配置, 如
{
"pluginConfig":[{
"path":".\\cmake-build-debug\\MiraiCP.dll"
}]
}
详细见config.md文档
3.2.2.2 手动下载
-
首先下载启动器(mcl), 下载地址 -> 官方
-
从最新release 中下载MiraiCP-plugin-*.mirai.jar(*号为版本)
-
把该mirai.jar放到mcl的plugin路径下(如果没有plugin路径需要启动一次mcl)
-
在mcl的路径下的data\miraiCP\路径中创建miraicp.json里填写配置, 如
{
"pluginConfig":[{
"path":"\\cmake-build-debug\\MiraiCP.dll"
}]
}
详细见config.md文档
- 启动mcl
如果有其他问题,欢迎提交issue和提交PR贡献
更新方式
-
从最新release 中下载loader或plugin的jar文件
-
从MiraiCP-template下载并替换single_include/MiraiCP下全部文件(就MiraiCP.hpp和MiraiCP.cpp)
-
替换你的loader或plugin jar包
交流方式
论坛贴: miraicp
github issue: miraicp issue
qq群: 1044565129
TODO
许可
Copyright (C) 2020-2021 Eritque arcus and contributors.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or any later version(in your opinion).
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
依赖
Dependence name | Url | Author | License |
---|---|---|---|
JSON for modern C++ | https://github.com/nlohmann/json | Niels Lohmann | MIT |
UTF8-CPP: UTF-8 with C++ in a Portable Way | https://github.com/nemtrif/utfcpp | Nemanja Trifunovic | BSL-1.0 |
JNI Headers | Null | Java | GNU General Public License version 2 |