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

Commit

Permalink
fix(cpp): fix MemberJoinRequestEvent
Browse files Browse the repository at this point in the history
#91


Former-commit-id: d7a049a277553cd08849dbea60d83a973a9b0f80 [formerly 3889a1c9c4435c1ee4a0262abc8bd7da4ffe4057]
Former-commit-id: e72c0f3f3b53262318e3c8d7c961827bc2879ac1
  • Loading branch information
Nambers committed Oct 21, 2021
1 parent 7db2d47 commit c85d766
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ set_target_properties(MiraiCP PROPERTIES OUTPUT_NAME MiraiCP)
add_library(
MiraiCP_Test
SHARED
include/test/test.cpp)
include/test/test.cpp
include/test/test2.cpp)
set_target_properties(MiraiCP_Test PROPERTIES OUTPUT_NAME MiraiCP)
add_subdirectory(include/test)
#---测试相关---
Expand Down
22 changes: 18 additions & 4 deletions cpp/include/miraiCP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,9 +1437,18 @@ LightApp风格1
void p(std::vector<Message>* v, T1 h, T2 ... args){
static_assert(std::is_base_of_v<SingleMessage, T1>, "只支持SingleMessage子类");
v->push_back(Message(h));
Logger::logger.info(((SingleMessage)h).toMiraiCode());
p(v,args...);
}
template<class... T2>
void p(std::vector<Message>* v, std::string h, T2 ... args){
v->push_back(Message(PlainText(h)));
p(v, args...);
}
template<class... T2>
void p(std::vector<Message>* v, const char* h, T2 ... args){
v->push_back(Message(PlainText(h)));
p(v, args...);
}
std::vector<Message> content;
MessageSource quoteAndSend0(const std::string& msg, QQID groupid = -1, JNIEnv* env = ThreadManager::getEnv(__FILE__, __LINE__)){
json obj;
Expand Down Expand Up @@ -1826,6 +1835,11 @@ LightApp风格1
return sendMsg0(msg.toMiraiCode(), retryTime, true, env);
}

template<class ... T>
MessageSource sendMessage(T ... val){
return this->sendMessage(MessageChain(val...), 3, ThreadManager::getEnv(__FILE__, __LINE__));
}

/// @brief 发送一条Message
/// @detail 支持
/// - std::string: 相当于发送PlainText(str), 不会反序列化miraicode
Expand Down Expand Up @@ -2963,7 +2977,7 @@ LightApp风格1
public:
/// 申请的群, 如果不存在就表明广播这个事件的时候机器人已经退出该群
std::optional<Group> group;
/// 邀请人, 如果不支持表明这个邀请人退出了群
/// 邀请人, 如果不存在表明这个邀请人退出了群或没有邀请人为主动进群
std::optional<Member> inviter;
MemberJoinRequestEvent(std::optional<Group> g, std::optional<Member> i, QQID botid, const std::string& source):BotEvent(botid), group(std::move(g)), inviter(std::move(i)), source(source){};
/// 通过
Expand Down Expand Up @@ -4074,7 +4088,7 @@ jstring Event(JNIEnv *env, jobject, jstring content) {
case 15: {
std::optional<Group> a;
std::optional<Member> b;
Contact temp = Contact::deserializationFromString(j["group"]);
Contact temp = Contact::deserializationFromJson(j["group"]);
if(temp.id() == 0)
a = std::nullopt;
else
Expand All @@ -4084,7 +4098,7 @@ jstring Event(JNIEnv *env, jobject, jstring content) {
b = std::nullopt;
else
b = Member(temp);
Event::processor.broadcast(MemberJoinRequestEvent(a, b, temp.botid(), j["source"]));
Event::processor.broadcast(MemberJoinRequestEvent(a, b, temp.botid(), j["requestData"]));
break;
}
default:
Expand Down
7 changes: 5 additions & 2 deletions cpp/include/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ class Main:public CPPPlugin {
});
// 群事件
Event::processor.registerEvent<MemberJoinEvent>([](MemberJoinEvent e) {
e.group.sendMessage(e.group.getOwner().at().toMiraiCode() + std::to_string(e.member.id()) + "加入了群聊");
e.group.sendMessage(e.group.getOwner().at(), std::to_string(e.member.id()), "加入了群聊");
});
Event::processor.registerEvent<MemberLeaveEvent>([](MemberLeaveEvent e) {
e.group.sendMessage(e.group.getOwner().at().toMiraiCode() + std::to_string(e.memberid) + "退出了群聊");
e.group.sendMessage(e.group.getOwner().at(), std::to_string(e.memberid), "退出了群聊");
});
Event::processor.registerEvent<TimeOutEvent>([](const TimeOutEvent& e){
Logger::logger.info(e.msg);
Expand All @@ -183,6 +183,9 @@ class Main:public CPPPlugin {
Logger::logger.info(e.from.id());
Logger::logger.info(e.target.id());
});
Event::processor.registerEvent<MemberJoinRequestEvent>([](MemberJoinRequestEvent e){
e.accept();
});
}

void onDisable() override {
Expand Down

0 comments on commit c85d766

Please sign in to comment.