Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
2020/11/4 FIX Bugs
Browse files Browse the repository at this point in the history
Former-commit-id: b47b6ff
  • Loading branch information
Nambers committed Nov 4, 2020
1 parent 35aa7f7 commit 09c636d
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 26 deletions.
Binary file modified kotlin_mirai/.gradle/6.2/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified kotlin_mirai/.gradle/6.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified kotlin_mirai/.gradle/6.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified kotlin_mirai/.gradle/6.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified kotlin_mirai/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified kotlin_mirai/.gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
6 changes: 0 additions & 6 deletions kotlin_mirai/CPPHeadFilesBuild.bat

This file was deleted.

1 change: 1 addition & 0 deletions kotlin_mirai/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
implementation "net.mamoe:mirai-core-qqandroid:1.1.3"
implementation "net.mamoe:mirai-console:0.5.2"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.4.10"
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10'
}

Expand Down
1 change: 1 addition & 0 deletions kotlin_mirai/src/main/kotlin/com/example/plugin/CPP_lib.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CPP_lib {
Send(message, id)
}
}
return
}
@JvmStatic
fun GetNick(qqid:Long): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package com.example.plugin
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.mamoe.mirai.Bot
import net.mamoe.mirai.console.plugins.PluginBase
import net.mamoe.mirai.event.events.*
Expand Down Expand Up @@ -63,9 +64,9 @@ object ExamplePluginMain : PluginBase() {
}
subscribeAlways<FriendMessageEvent> {
//个人信息
logger.info("starting")
cpp.PrivateMessage(subject.id,message.toString())
logger.info("ending")
GlobalScope.launch(Dispatchers.Default) {
cpp.PrivateMessage(subject.id, message.toString())
}
}
subscribeAlways<MemberJoinEvent.Active> {
cpp.GroupMemberJoin(member.id, true, group.id)
Expand Down
6 changes: 6 additions & 0 deletions kotlin_mirai/生成头文件指引.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
please run the classes task in gradle first
先执行classes任务在gradle里
and use cmd into the "...\MiraiCP\kotlin_mirai\build\classes\kotlin\main\com\example\plugin" address
然后用cmd cd到"...\MiraiCP\kotlin_mirai\build\classes\kotlin\main\com\example\plugin"路径下
run this command "javah com.example.plugin.CPP_lib"
执行这个指令 "javah com.example.plugin.CPP_lib"
Binary file modified mirai-demo/.vs/mirai-demo/v16/.suo
Binary file not shown.
2 changes: 1 addition & 1 deletion mirai-demo/.vs/mirai-demo/v16/Browse.VC.db.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ef4dfeb15025a34c24b8207bf8ac8a647d003414
1482065dc947777cf4e15b464480c2c274081ba6
Original file line number Diff line number Diff line change
@@ -1 +1 @@
153fee2b821f694a97e719a53791bf3f30ad5b23
0bfc5006fc37aa5f5976e64167ef2e13fa71d1f3
4 changes: 4 additions & 0 deletions mirai-demo/cpp.hint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// 提示文件帮助 Visual Studio IDE 解释 Visual C++ 标识符,
// 如函数和宏的名称。
// 有关详细信息,请参见 https://go.microsoft.com/fwlink/?linkid=865984
#define JNIEXPORT __declspec(dllexport)
3 changes: 3 additions & 0 deletions mirai-demo/mirai-demo.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@
</ClCompile>
<ClCompile Include="tools.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>
3 changes: 3 additions & 0 deletions mirai-demo/mirai-demo.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />
</ItemGroup>
</Project>
25 changes: 13 additions & 12 deletions mirai-demo/pch.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "pch.h"
void SendLog(JNIEnv* env, jobject job, string log) {
JNIEXPORT void SendLog(JNIEnv* env, jobject job, string log) {
//1.首先要在C中获取jclass对象,也就是找到方法所在的类,通过完整 包名+类名
jclass java_first = env->FindClass("com/example/plugin/CPP_lib");

Expand Down Expand Up @@ -31,7 +31,7 @@ void SendLog(JNIEnv* env, jobject job, string log) {
* 参数:env 必备参数,job 必备参数,memberid qq号,active 是否主动加入(非邀请)
* 返回值: void
*/
void JNICALL Java_com_example_plugin_CPP_1lib_GroupMemberJoin
JNIEXPORT void JNICALL Java_com_example_plugin_CPP_1lib_GroupMemberJoin
(JNIEnv* env, jobject job, jlong memberid, jboolean active,jlong groupid) {
Group g(env, job, groupid);
g.SendMsg(tools.JLongToString(memberid) + "加入了本群");
Expand All @@ -42,7 +42,7 @@ void SendLog(JNIEnv* env, jobject job, string log) {
* 参数:env 必备参数,job 必备参数,memberid qq号,active 是否退出(非踢出)
* 返回值:void
*/
void JNICALL Java_com_example_plugin_CPP_1lib_GroupMemberLeave
JNIEXPORT void JNICALL Java_com_example_plugin_CPP_1lib_GroupMemberLeave
(JNIEnv* env, jobject job, jlong memberid, jboolean active,jlong groupid) {
Group g(env, job, groupid);
Friend f(env, job, memberid);
Expand All @@ -54,7 +54,7 @@ void SendLog(JNIEnv* env, jobject job, string log) {
* 参数:env 必备参数,job 必备参数,origin 原名,newName 新名字,Groupid 群号,operateid 操作者qq(如果是机器人则为0)
* 返回值: void
*/
void JNICALL Java_com_example_plugin_CPP_1lib_GroupNameChange
JNIEXPORT void JNICALL Java_com_example_plugin_CPP_1lib_GroupNameChange
(JNIEnv* env, jobject job, jstring origin, jstring newName, jlong Groupid, jlong operateid) {
//不做反应
}
Expand All @@ -64,7 +64,7 @@ void SendLog(JNIEnv* env, jobject job, string log) {
* 参数:env 必备参数,job 必备参数,qqid qq号,nick 申请者昵称,message 验证消息
* 返回值:bool 是为添加 否为不添加
*/
jboolean JNICALL Java_com_example_plugin_CPP_1lib_FriendRequest
JNIEXPORT jboolean JNICALL Java_com_example_plugin_CPP_1lib_FriendRequest
(JNIEnv* env, jobject job, jlong qqid, jstring nick, jstring message) {
Friend object(env, job, qqid);
object.SendMsg("Hi");
Expand All @@ -77,7 +77,7 @@ void SendLog(JNIEnv* env, jobject job, string log) {
* 参数:env 必备,job 必备
* 返回值:jstring (用str2jstring把string类型转成jsrting) 发送返回的字符串
*/
jstring JNICALL Java_com_example_plugin_CPP_1lib_Verify(JNIEnv* env, jobject job) {
JNIEXPORT jstring JNICALL Java_com_example_plugin_CPP_1lib_Verify(JNIEnv* env, jobject job) {
//Friend(env, job, (jlong)1930893235).SendMsg("H");
return tools.str2jstring(env, "2333");//验证机制
}
Expand All @@ -87,16 +87,17 @@ void SendLog(JNIEnv* env, jobject job, string log) {
* 参数:env 必备,job 必备,senderid qq号,sendername 发送者昵称,HeadImageDownloadUrl 发送者头像地址,message 发送的消息
* 返回值: void
*/
void JNICALL Java_com_example_plugin_CPP_1lib_PrivateMessage
JNIEXPORT void JNICALL Java_com_example_plugin_CPP_1lib_PrivateMessage
(JNIEnv* env, jobject job, jlong SenderId, jstring Message) {
Friend object(env,job, SenderId);
string result = "我还在测试中";//default is no reply
if (object.id== 1930893235) {
object.SendMsg("Hi");//发送消息 Hi
SendLog(env, job, "OKOK");//发送日志
return;
object.SendMsg("Hi"+object.GetNick());//发送消息 Hi
SendLog(env, job, "Send MSG");//发送日志
}
else {
object.SendMsg(result);
}
object.SendMsg(result);
}
/**
* 名称:Java_com_example_plugin_CPP_1lib_GroupMessage
Expand All @@ -107,7 +108,7 @@ void JNICALL Java_com_example_plugin_CPP_1lib_PrivateMessage
ernick:jstring 发送者昵称,sendergroupname:jstring 发送者群名称,senderid:jlong qq号,message:jstring 信息
* 返回值:void
**/
void JNICALL Java_com_example_plugin_CPP_1lib_GroupMessage
JNIEXPORT void JNICALL Java_com_example_plugin_CPP_1lib_GroupMessage
(JNIEnv* env, jobject job, jlong GroupId, jstring GroupName, jlong GroupOwnerId, jstring SenderNick, jstring SenderGroupName, jlong SenderId, jstring Message){
Group object(env, job, GroupId);
Friend Sender(env, job, SenderId);
Expand Down
5 changes: 2 additions & 3 deletions mirai-demo/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ Friend::Friend (JNIEnv* env, jobject job,jlong id){
*/
this->java_first = env->FindClass("com/example/plugin/CPP_lib");
this->Send_Msg_id = env->GetStaticMethodID(java_first, "SendPrivateMSG", "(Ljava/lang/String;J)V");
this->Nick_Name_id = env->GetStaticMethodID(java_first, "GetNick", "(J)Ljava/lang/String");
//this->Nick_Name_id = env->GetStaticMethodID(java_first, "GetNick", "(J)Ljava/lang/String");
this->jid = id;
this->id = (long)id;
this->env = env;
//this->nick=this->GetNick();
}
Friend::~Friend() {
this->env->DeleteLocalRef(java_first);
delete(this->env);
}
Group::Group(JNIEnv* env, jobject job, jlong id) {
this->java_first = env->FindClass("com/example/plugin/CPP_lib");
Expand All @@ -39,7 +38,7 @@ Group::Group(JNIEnv* env, jobject job, jlong id) {
}
Group::~Group() {
env->DeleteLocalRef(java_first);
delete(this->env);

}
string Tools::jstring2str(JNIEnv* env, jstring jstr)
{
Expand Down

0 comments on commit 09c636d

Please sign in to comment.