cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
GroupEvents.hpp
浏览该文件的文档.
1// Copyright (C) 2022 Numendacil and contributors
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU Affero General Public License as
5// published by the Free Software Foundation, either version 3 of the
6// License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU Affero General Public License for more details.
12//
13// You should have received a copy of the GNU Affero General Public License
14// along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16#ifndef MIRAI_GROUP_EVENTS_HPP_
17#define MIRAI_GROUP_EVENTS_HPP_
18
19#include <optional>
20#include <string>
21
24
25#include "IEvent.hpp"
26
27namespace Mirai
28{
29
30// TODO: add a base class for all GroupSettingChangeEvent
31
32/**
33 * @brief 群聊开启/关闭匿名聊天事件
34 *
35 * Member Variable | Default Value
36 * --------------- | -------------
37 * `GroupAllowAnonymousChatEvent::group_` | `Group{}`
38 * `GroupAllowAnonymousChatEvent::origin_` | `false`
39 * `GroupAllowAnonymousChatEvent::current_` | `false`
40 * `GroupAllowAnonymousChatEvent::operator_` | `std::nullopt`
41 */
42class GroupAllowAnonymousChatEvent final : public IEvent<GroupAllowAnonymousChatEvent>
43{
45private:
46 Group group_;
47 bool origin_ = false;
48 bool current_ = false;
49 std::optional<GroupMember> operator_ = std::nullopt;
50
51 static constexpr EventTypes TYPE_ = EventTypes::GroupAllowAnonymousChat;
52
53public:
54 /// 获取群聊信息
55 Group GetGroup() const { return this->group_; }
56 /// 原本匿名聊天是否开启
57 bool GetOriginal() const { return this->origin_; }
58 /// 现在匿名聊天是否开启
59 bool GetCurrent() const { return this->current_; }
60 /// 获取操作员信息,为Bot时返回 `std::nullopt`
61 std::optional<GroupMember> GetOperator() const { return this->operator_; }
62
63 struct Serializable;
64};
65
66/**
67 * @brief 群聊开启/关闭坦白说事件
68 *
69 * Member Variable | Default Value
70 * --------------- | -------------
71 * `GroupAllowConfessTalkEvent::group_` | `Group{}`
72 * `GroupAllowConfessTalkEvent::origin_` | `false`
73 * `GroupAllowConfessTalkEvent::current_` | `false`
74 * `GroupAllowConfessTalkEvent::ByBot_` | `false`
75 */
76class GroupAllowConfessTalkEvent final : public IEvent<GroupAllowConfessTalkEvent>
77{
79private:
80 Group group_;
81 bool origin_ = false;
82 bool current_ = false;
83 bool ByBot_ = false; // 无法获得操作员
84
85 static constexpr EventTypes TYPE_ = EventTypes::GroupAllowConfessTalk;
86
87public:
88 /// 获取群聊信息
89 Group GetGroup() const { return this->group_; }
90 /// 原本坦白说是否开启
91 bool GetOriginal() const { return this->origin_; }
92 /// 现在坦白说是否开启
93 bool GetCurrent() const { return this->current_; }
94 /// 操作员是否为Bot自己(无法获得具体操作员信息)
95 bool isByBot() const { return this->ByBot_; }
96
97 struct Serializable;
98};
99
100/**
101 * @brief 群聊开启/关闭允许群成员邀请好友加群事件
102 *
103 * Member Variable | Default Value
104 * --------------- | -------------
105 * `GroupAllowMemberInviteEvent::group_` | `Group{}`
106 * `GroupAllowMemberInviteEvent::origin_` | `false`
107 * `GroupAllowMemberInviteEvent::current_` | `false`
108 * `GroupAllowMemberInviteEvent::operator_` | `std::nullopt`
109 */
110class GroupAllowMemberInviteEvent final : public IEvent<GroupAllowMemberInviteEvent>
111{
113private:
114 Group group_;
115 bool origin_ = false;
116 bool current_ = false;
117 std::optional<GroupMember> operator_ = std::nullopt;
118
119 static constexpr EventTypes TYPE_ = EventTypes::GroupAllowMemberInvite;
120
121public:
122 /// 获取群聊信息
123 Group GetGroup() const { return this->group_; }
124 /// 原本是否允许群成员邀请好友加群
125 bool GetOriginal() const { return this->origin_; }
126 /// 现在是否允许群成员邀请好友加群
127 bool GetCurrent() const { return this->current_; }
128 /// 获取操作员信息,为Bot时返回 `std::nullopt`
129 std::optional<GroupMember> GetOperator() const { return this->operator_; }
130
131 struct Serializable;
132};
133
134/**
135 * @brief 入群公告更改事件
136 *
137 * Member Variable | Default Value
138 * --------------- | -------------
139 * `GroupEntranceAnnouncementChangeEvent::group_` | `Group{}`
140 * `GroupEntranceAnnouncementChangeEvent::origin_` | `""`
141 * `GroupEntranceAnnouncementChangeEvent::current_` | `""`
142 * `GroupEntranceAnnouncementChangeEvent::operator_` | `std::nullopt`
143 *
144 * @attention DEPRECATED, mirai 2.12 后该事件将不会被触发 (https://github.com/mamoe/mirai/issues/1873)
145 */
146class GroupEntranceAnnouncementChangeEvent final : public IEvent<GroupEntranceAnnouncementChangeEvent>
147{
149private:
150 Group group_;
151 std::string origin_;
152 std::string current_;
153 std::optional<GroupMember> operator_ = std::nullopt;
154
156
157public:
158 /// 获取群聊信息
159 Group GetGroup() const { return this->group_; }
160 /// 获取更改前的入群公告
161 std::string GetOriginal() const { return this->origin_; }
162 /// 获取当前入群公告
163 std::string GetCurrent() const { return this->current_; }
164 /// 获取操作员信息,为Bot时返回 `std::nullopt`
165 std::optional<GroupMember> GetOperator() const { return this->operator_; }
166
167 struct Serializable;
168};
169
170/**
171 * @brief 群聊名称更改事件
172 *
173 * Member Variable | Default Value
174 * --------------- | -------------
175 * `GroupNameChangeEvent::group_` | `Group{}`
176 * `GroupNameChangeEvent::origin_` | `""`
177 * `GroupNameChangeEvent::current_` | `""`
178 * `GroupNameChangeEvent::operator_` | `std::nullopt`
179 */
180class GroupNameChangeEvent final : public IEvent<GroupNameChangeEvent>
181{
183private:
184 Group group_;
185 std::string origin_;
186 std::string current_;
187 std::optional<GroupMember> operator_ = std::nullopt;
188
189 static constexpr EventTypes TYPE_ = EventTypes::GroupNameChange;
190
191public:
192 /// 获取群聊信息
193 Group GetGroup() const { return this->group_; }
194 /// 获取更改前的群聊名称
195 std::string GetOriginal() const { return this->origin_; }
196 /// 获取当前的群聊名称
197 std::string GetCurrent() const { return this->current_; }
198 /// 获取操作员信息,为Bot时返回 `std::nullopt`
199 std::optional<GroupMember> GetOperator() const { return this->operator_; }
200
201 struct Serializable;
202};
203
204
205
206/**
207 * @brief 群聊消息事件
208 *
209 * Member Variable | Default Value
210 * --------------- | -------------
211 * `GroupMessageEvent::sender_` | `GroupMember{}`
212 * `GroupMessageEvent::message_` | `MessageChain{}`
213 */
214class GroupMessageEvent final : public IEvent<GroupMessageEvent>
215{
217
218private:
219 GroupMember sender_;
220 MessageChain message_;
221
222 static constexpr EventTypes TYPE_ = EventTypes::GroupMessage;
223
224public:
225 /// 获取发送者资料
226 GroupMember GetSender() const { return this->sender_; }
227 /// 获取消息内容
228 MessageChain GetMessage() const { return this->message_; }
229
230 // TODO: add helper methods for quick reply
231
232 struct Serializable;
233};
234
235
236
237/**
238 * @brief 群聊开启/关闭全体禁言事件
239 *
240 * Member Variable | Default Value
241 * --------------- | -------------
242 * `BotGroupPermissionChangeEvent::group_` | `Group{}`
243 * `BotGroupPermissionChangeEvent::origin_` | `false`
244 * `BotGroupPermissionChangeEvent::current_` | `false`
245 * `BotGroupPermissionChangeEvent::operator_` | `std::nullopt`
246 */
247class GroupMuteAllEvent final : public IEvent<GroupMuteAllEvent>
248{
250private:
251 Group group_;
252 bool origin_ = false;
253 bool current_ = false;
254 std::optional<GroupMember> operator_ = std::nullopt;
255
256 static constexpr EventTypes TYPE_ = EventTypes::GroupMuteAll;
257
258public:
259 /// 获取群聊信息
260 Group GetGroup() const { return this->group_; }
261 /// 原本是否处于全员禁言状态
262 bool GetOriginal() const { return this->origin_; }
263 /// 现在是否处于全员禁言
264 bool GetCurrent() const { return this->current_; }
265 /// 获取操作员信息,为Bot时返回 `std::nullopt`
266 std::optional<GroupMember> GetOperator() const { return this->operator_; }
267
268 struct Serializable;
269};
270
271
272
273/**
274 * @brief 群消息撤回事件
275 *
276 * Member Variable | Default Value
277 * --------------- | -------------
278 * `GroupRecallEvent::AuthorId_` | `0_qq`
279 * `GroupRecallEvent::MessageId_` | `0`
280 * `GroupRecallEvent::time_` | `0`
281 * `GroupRecallEvent::group_` | `Group{}`
282 * `GroupRecallEvent::operator_` | `std::nullopt`
283 */
284class GroupRecallEvent final : public IEvent<GroupRecallEvent>
285{
287private:
288 QQ_t AuthorId_;
289 MessageId_t MessageId_ = 0;
290 std::time_t time_ = 0;
291 Group group_;
292 std::optional<GroupMember> operator_ = std::nullopt;
293
294 static constexpr EventTypes TYPE_ = EventTypes::GroupRecall;
295
296public:
297 /// 获取被撤回消息的发送者QQ
298 QQ_t GetSender() const { return this->AuthorId_; }
299 /// 获取被撤回消息的消息id
300 MessageId_t GetMessageId() const { return this->MessageId_; }
301 /// 获取被撤回消息的发送时间
302 std::time_t GetSendTime() const { return this->time_; }
303 /// 获取群聊信息
304 Group GetGroup() const { return this->group_; }
305 /// 获取操作员信息,为Bot时返回 `std::nullopt`
306 std::optional<GroupMember> GetOperator() const { return this->operator_; }
307
308 struct Serializable;
309};
310
311
312
313/**
314 * @brief 群聊消息同步事件
315 *
316 * Member Variable | Default Value
317 * --------------- | -------------
318 * `GroupSyncMessageEvent::subject_` | `Group{}`
319 * `GroupSyncMessageEvent::message_` | `MessageChain{}`
320 */
321class GroupSyncMessageEvent final : public IEvent<GroupSyncMessageEvent>
322{
324
325private:
326 Group subject_;
327 MessageChain message_;
328
329 static constexpr EventTypes TYPE_ = EventTypes::GroupSyncMessage;
330
331public:
332 /// 获取目标群聊信息
333 Group GetGroup() const { return this->subject_; }
334 /// 获取消息内容
335 MessageChain GetMessage() const { return this->message_; }
336
337 struct Serializable;
338};
339
340
341
342#define DECLARE_TYPE_ENUM(event_type) \
343 template<> struct GetEventType<event_type::GetType()> \
344 { \
345 using type = event_type; \
346 }
347
357
358#undef DECLARE_TYPE_ENUM
359
360} // namespace Mirai
361
362
363#endif
群聊开启/关闭匿名聊天事件
Definition: GroupEvents.hpp:43
bool GetCurrent() const
现在匿名聊天是否开启
Definition: GroupEvents.hpp:59
std::optional< GroupMember > GetOperator() const
获取操作员信息,为Bot时返回 std::nullopt
Definition: GroupEvents.hpp:61
Group GetGroup() const
获取群聊信息
Definition: GroupEvents.hpp:55
bool GetOriginal() const
原本匿名聊天是否开启
Definition: GroupEvents.hpp:57
群聊开启/关闭坦白说事件
Definition: GroupEvents.hpp:77
Group GetGroup() const
获取群聊信息
Definition: GroupEvents.hpp:89
bool isByBot() const
操作员是否为Bot自己(无法获得具体操作员信息)
Definition: GroupEvents.hpp:95
bool GetCurrent() const
现在坦白说是否开启
Definition: GroupEvents.hpp:93
bool GetOriginal() const
原本坦白说是否开启
Definition: GroupEvents.hpp:91
群聊开启/关闭允许群成员邀请好友加群事件
bool GetCurrent() const
现在是否允许群成员邀请好友加群
std::optional< GroupMember > GetOperator() const
获取操作员信息,为Bot时返回 std::nullopt
Group GetGroup() const
获取群聊信息
bool GetOriginal() const
原本是否允许群成员邀请好友加群
std::string GetOriginal() const
获取更改前的入群公告
std::string GetCurrent() const
获取当前入群公告
std::optional< GroupMember > GetOperator() const
获取操作员信息,为Bot时返回 std::nullopt
Group GetGroup() const
获取群聊信息
群聊消息事件
GroupMember GetSender() const
获取发送者资料
MessageChain GetMessage() const
获取消息内容
群聊开启/关闭全体禁言事件
Group GetGroup() const
获取群聊信息
bool GetOriginal() const
原本是否处于全员禁言状态
std::optional< GroupMember > GetOperator() const
获取操作员信息,为Bot时返回 std::nullopt
bool GetCurrent() const
现在是否处于全员禁言
群聊名称更改事件
std::string GetCurrent() const
获取当前的群聊名称
std::optional< GroupMember > GetOperator() const
获取操作员信息,为Bot时返回 std::nullopt
std::string GetOriginal() const
获取更改前的群聊名称
Group GetGroup() const
获取群聊信息
群消息撤回事件
std::time_t GetSendTime() const
获取被撤回消息的发送时间
QQ_t GetSender() const
获取被撤回消息的发送者QQ
MessageId_t GetMessageId() const
获取被撤回消息的消息id
Group GetGroup() const
获取群聊信息
std::optional< GroupMember > GetOperator() const
获取操作员信息,为Bot时返回 std::nullopt
群聊消息同步事件
MessageChain GetMessage() const
获取消息内容
Group GetGroup() const
获取目标群聊信息
Common interface for all event types
Definition: IEvent.hpp:34
消息链对象,由一系列消息元素组成
QQ号码类型
Definition: BasicTypes.hpp:71
所有mirai相关的对象的命名空间
int64_t MessageId_t
消息id类型,用于撤回消息和引用消息
Definition: BasicTypes.hpp:35
DECLARE_TYPE_ENUM(BotOfflineEventActive)
群员资料
Definition: BasicTypes.hpp:362
群聊资料
Definition: BasicTypes.hpp:333