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

Commit 30ef546

Browse files
committed
适配 mah v2.5.0 其他客户端同步消息;
1 parent 1fb4bb9 commit 30ef546

File tree

7 files changed

+234
-2
lines changed

7 files changed

+234
-2
lines changed

examples/RepeatMessage.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// 按需引用头文件
55
// 你也可以使用 #include <mirai.h> 引用所有头文件(可能导致编译缓慢)
66
#include <mirai/MiraiBot.hpp>
7+
#include <mirai/events/OtherClientMessage.hpp>
8+
#include <mirai/events/FriendSyncMessage.hpp>
79
using namespace std;
810
using namespace Cyan;
911

@@ -55,7 +57,17 @@ int main(int argc, char* argv[])
5557
[&](Message m)
5658
{
5759
cout << int64_t(m.Sender) << " 发来一条消息." << m.MessageChain.ToString() << endl;
58-
m.Reply(m.MessageChain);
60+
// m.Reply(m.MessageChain);
61+
});
62+
63+
bot.On<OtherClientMessage>([&](OtherClientMessage m)
64+
{
65+
cout << m.MessageChain.ToString() << endl;
66+
});
67+
68+
bot.On<FriendSyncMessage>([&](FriendSyncMessage m)
69+
{
70+
cout << m.MessageChain.ToString() << endl;
5971
});
6072

6173
bot.On<LostConnection>([&](LostConnection e)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
#ifndef mirai_cpp_events_FriendSyncMessage_hpp_H_
3+
#define mirai_cpp_events_FriendSyncMessage_hpp_H_
4+
5+
#include "mirai/third-party/nlohmann/json.hpp"
6+
#include "mirai/defs/QQType.hpp"
7+
#include "mirai/defs/MessageChain.hpp"
8+
#include "mirai/defs/Friend.hpp"
9+
#include "EventBase.hpp"
10+
11+
namespace Cyan
12+
{
13+
/**
14+
* \brief Bot在其他客户端发送给好友的消息
15+
*/
16+
class FriendSyncMessage : public EventBase
17+
{
18+
public:
19+
Cyan::MessageChain MessageChain;
20+
Friend_t Subject;
21+
22+
static MiraiEvent GetMiraiEvent()
23+
{
24+
return MiraiEvent::FriendSyncMessage;
25+
}
26+
27+
MessageId_t MessageId() const
28+
{
29+
return (this->MessageChain).MessageId();
30+
}
31+
32+
int64_t Timestamp() const
33+
{
34+
return (this->MessageChain).Timestamp();
35+
}
36+
37+
virtual bool Set(const json& j) override
38+
{
39+
this->MessageChain.Set(j["messageChain"]);
40+
Subject.Set(j["subject"]);
41+
return true;
42+
}
43+
virtual json ToJson() const override
44+
{
45+
json j = json::object();
46+
j["messageChain"] = this->MessageChain.ToJson();
47+
j["subject"] = this->Subject.ToJson();
48+
return j;
49+
}
50+
};
51+
}
52+
53+
#endif
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
#ifndef mirai_cpp_events_GroupSyncMessage_hpp_H_
3+
#define mirai_cpp_events_GroupSyncMessage_hpp_H_
4+
5+
#include "mirai/third-party/nlohmann/json.hpp"
6+
#include "mirai/defs/QQType.hpp"
7+
#include "mirai/defs/MessageChain.hpp"
8+
#include "mirai/defs/Group.hpp"
9+
#include "EventBase.hpp"
10+
11+
namespace Cyan
12+
{
13+
/**
14+
* \brief Bot在其他客户端发送给群组的消息
15+
*/
16+
class GroupSyncMessage : public EventBase
17+
{
18+
public:
19+
Cyan::MessageChain MessageChain;
20+
Group_t Subject;
21+
22+
static MiraiEvent GetMiraiEvent()
23+
{
24+
return MiraiEvent::GroupSyncMessage;
25+
}
26+
27+
MessageId_t MessageId() const
28+
{
29+
return (this->MessageChain).MessageId();
30+
}
31+
32+
int64_t Timestamp() const
33+
{
34+
return (this->MessageChain).Timestamp();
35+
}
36+
37+
virtual bool Set(const json& j) override
38+
{
39+
this->MessageChain.Set(j["messageChain"]);
40+
Subject.Set(j["subject"]);
41+
return true;
42+
}
43+
virtual json ToJson() const override
44+
{
45+
json j = json::object();
46+
j["messageChain"] = this->MessageChain.ToJson();
47+
j["subject"] = this->Subject.ToJson();
48+
return j;
49+
}
50+
};
51+
}
52+
53+
#endif

include/mirai/events/MiraiEvent.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ namespace Cyan
5050
MemberSpecialTitleChangeEvent, // 群头衔改动事件
5151
BotGroupPermissionChangeEvent, // bot 群权限改变事件
5252
MemberPermissionChangeEvent, // 群成员权限改变事件
53-
MemberHonorChangeEvent // 群成员称号改变事件
53+
MemberHonorChangeEvent, // 群成员称号改变事件
54+
FriendSyncMessage, // Bot在其他客户端发送给好友的消息
55+
GroupSyncMessage, // Bot在其他客户端发送给群组的消息
56+
TempSyncMessage, // Bot在其他客户端发送给群成员的临时消息
57+
StrangerSyncMessage // Bot在其他客户端发送给陌生人的消息
5458
};
5559

5660
MiraiEvent MiraiEventStr(const std::string& miraiEvent);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
#ifndef mirai_cpp_events_StrangerSyncMessage_hpp_H_
3+
#define mirai_cpp_events_StrangerSyncMessage_hpp_H_
4+
5+
#include "mirai/third-party/nlohmann/json.hpp"
6+
#include "mirai/defs/QQType.hpp"
7+
#include "mirai/defs/MessageChain.hpp"
8+
#include "mirai/defs/Friend.hpp"
9+
#include "EventBase.hpp"
10+
11+
namespace Cyan
12+
{
13+
/**
14+
* \brief Bot在其他客户端发送给好友的消息
15+
*/
16+
class StrangerSyncMessage : public EventBase
17+
{
18+
public:
19+
Cyan::MessageChain MessageChain;
20+
Friend_t Subject;
21+
22+
static MiraiEvent GetMiraiEvent()
23+
{
24+
return MiraiEvent::StrangerSyncMessage;
25+
}
26+
27+
MessageId_t MessageId() const
28+
{
29+
return (this->MessageChain).MessageId();
30+
}
31+
32+
int64_t Timestamp() const
33+
{
34+
return (this->MessageChain).Timestamp();
35+
}
36+
37+
virtual bool Set(const json& j) override
38+
{
39+
this->MessageChain.Set(j["messageChain"]);
40+
Subject.Set(j["subject"]);
41+
return true;
42+
}
43+
virtual json ToJson() const override
44+
{
45+
json j = json::object();
46+
j["messageChain"] = this->MessageChain.ToJson();
47+
j["subject"] = this->Subject.ToJson();
48+
return j;
49+
}
50+
};
51+
}
52+
53+
#endif
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
#ifndef mirai_cpp_events_TempSyncMessage_hpp_H_
3+
#define mirai_cpp_events_TempSyncMessage_hpp_H_
4+
5+
#include "mirai/third-party/nlohmann/json.hpp"
6+
#include "mirai/defs/QQType.hpp"
7+
#include "mirai/defs/MessageChain.hpp"
8+
#include "mirai/defs/GroupMember.hpp"
9+
#include "EventBase.hpp"
10+
11+
namespace Cyan
12+
{
13+
/**
14+
* \brief Bot在其他客户端发送给群组的消息
15+
*/
16+
class TempSyncMessage : public EventBase
17+
{
18+
public:
19+
Cyan::MessageChain MessageChain;
20+
GroupMember Subject;
21+
22+
static MiraiEvent GetMiraiEvent()
23+
{
24+
return MiraiEvent::TempSyncMessage;
25+
}
26+
27+
MessageId_t MessageId() const
28+
{
29+
return (this->MessageChain).MessageId();
30+
}
31+
32+
int64_t Timestamp() const
33+
{
34+
return (this->MessageChain).Timestamp();
35+
}
36+
37+
virtual bool Set(const json& j) override
38+
{
39+
this->MessageChain.Set(j["messageChain"]);
40+
Subject.Set(j["subject"]);
41+
return true;
42+
}
43+
virtual json ToJson() const override
44+
{
45+
json j = json::object();
46+
j["messageChain"] = this->MessageChain.ToJson();
47+
j["subject"] = this->Subject.ToJson();
48+
return j;
49+
}
50+
};
51+
}
52+
53+
#endif

include/mirai/events/events.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "TempMessage.hpp"
1010
#include "StrangerMessage.hpp"
1111
#include "OtherClientMessage.hpp"
12+
#include "FriendSyncMessage.hpp"
13+
#include "GroupSyncMessage.hpp"
14+
#include "TempSyncMessage.hpp"
15+
#include "StrangerSyncMessage.hpp"
1216
// 机器人相关事件
1317
#include "BotOnlineEvent.hpp"
1418
#include "BotOfflineEventActive.hpp"

0 commit comments

Comments
 (0)