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

Commit 03ae53f

Browse files
committed
支持群全体禁言事件;
1 parent 7cf42de commit 03ae53f

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

examples/Mute.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ int main()
5050
bot.SendMessage(e.Member.Group.GID, mc);
5151
});
5252

53+
bot.On<GroupMuteAllEvent>([&](GroupMuteAllEvent e)
54+
{
55+
// 机器人的操作不可访问 Operator
56+
if (e.OperatorIsBot())
57+
{
58+
cout << "机器人群禁言操作" << endl;
59+
return;
60+
}
61+
if(e.Current)
62+
cout << e.Operator.MemberName << " 开启了全群禁言." << endl;
63+
else
64+
cout << e.Operator.MemberName << " 关闭了全群禁言." << endl;
65+
66+
});
67+
5368
try
5469
{
5570
bot.MuteAll(1029259687_gid);

include/events/events.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "friend_recall_event.hpp"
1919
// 群组相关事件
2020
#include "group_recall_event.hpp"
21+
#include "group_mute_all_event.hpp"
2122
#include "join_request_event.hpp"
2223
#include "member_join_event.hpp"
2324
#include "member_leave_kick.hpp"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#pragma once
2+
#ifndef mirai_cpp_events_group_mute_all_event_hpp_H_
3+
#define mirai_cpp_events_group_mute_all_event_hpp_H_
4+
5+
#include <nlohmann/json.hpp>
6+
#include "event_interface.hpp"
7+
#include "defs/group.hpp"
8+
#include "defs/group_member.hpp"
9+
10+
namespace Cyan
11+
{
12+
// 群全体禁言事件
13+
class GroupMuteAllEvent : public EventBase
14+
{
15+
public:
16+
bool Origin;
17+
bool Current;
18+
Group_t Group;
19+
GroupMember_t Operator;
20+
21+
static MiraiEvent GetMiraiEvent()
22+
{
23+
return MiraiEvent::GroupMuteAllEvent;
24+
}
25+
26+
bool OperatorIsBot() const
27+
{
28+
return operator_is_null_;
29+
}
30+
31+
virtual bool Set(const json& j) override
32+
{
33+
this->Origin = j["origin"].get<bool>();
34+
this->Current = j["current"].get<bool>();
35+
this->Group.Set(j["group"]);
36+
if (!j["operator"].is_null())
37+
{
38+
this->Operator.Set(j["operator"]);
39+
this->operator_is_null_ = false;
40+
}
41+
return true;
42+
}
43+
virtual json ToJson() const override
44+
{
45+
json j = json::object();
46+
j["type"] = "GroupMuteAllEvent";
47+
j["origin"] = this->Origin;
48+
j["current"] = this->Current;
49+
j["group"] = this->Group.ToJson();
50+
if (!operator_is_null_)
51+
j["operator"] = this->Operator.ToJson();
52+
else
53+
j["operator"] = nullptr;
54+
return j;
55+
}
56+
57+
private:
58+
bool operator_is_null_ = true;
59+
};
60+
61+
}
62+
63+
#endif // !mirai_cpp_events_group_mute_all_event_hpp_H_

include/events/mirai_event.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace Cyan
6262
if (miraiEvent == "BotLeaveEventActive") return MiraiEvent::BotLeaveEventActive;
6363
if (miraiEvent == "BotLeaveEventKick") return MiraiEvent::BotLeaveEventKick;
6464
if (miraiEvent == "GroupNameChangeEvent") return MiraiEvent::GroupNameChangeEvent;
65+
if (miraiEvent == "GroupMuteAllEvent") return MiraiEvent::GroupMuteAllEvent;
6566
return MiraiEvent::Default;
6667
}
6768

0 commit comments

Comments
 (0)