cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
BotEvents.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_BOT_EVENTS_HPP_
17#define MIRAI_BOT_EVENTS_HPP_
18
19#include <optional>
20#include <string>
21
23
24#include "IEvent.hpp"
25
26namespace Mirai
27{
28
29/**
30 * @brief 与Bot账号相关的事件
31 *
32 * Middleware for bot account related events
33 *
34 * Member Variable | Default Value
35 * --------------- | -------------
36 * `BotAccountEvent::qq_` | `0_qq`
37 */
38template <class Event>
39class BotAccountEvent : public IEvent<Event>
40{
41protected:
43
44public:
45 /// 获取BotQQ
46 QQ_t GetQQ() const { return this->qq_; }
47
48 struct Serializable;
49};
50
51/**
52 * @brief Bot主动下线事件
53 *
54 */
55class BotOfflineEventActive final : public BotAccountEvent<BotOfflineEventActive>
56{
58private:
59 static constexpr EventTypes TYPE_ = EventTypes::BotOfflineActive;
60};
61
62/**
63 * @brief Bot掉线事件
64 *
65 * 网络原因或服务器原因导致的掉线
66 */
67class BotOfflineEventDropped final : public BotAccountEvent<BotOfflineEventDropped>
68{
70private:
71 static constexpr EventTypes TYPE_ = EventTypes::BotOfflineDropped;
72};
73
74/**
75 * @brief Bot强制下线事件
76 *
77 * 通常是因为在相同平台的其它设备登录了Bot被挤下线
78 */
79class BotOfflineEventForce final : public BotAccountEvent<BotOfflineEventForce>
80{
82private:
83 static constexpr EventTypes TYPE_ = EventTypes::BotOfflineForce;
84};
85
86/**
87 * @brief Bot上线事件
88 *
89 */
90class BotOnlineEvent final : public BotAccountEvent<BotOnlineEvent>
91{
93private:
94 static constexpr EventTypes TYPE_ = EventTypes::BotOnline;
95};
96
97/**
98 * @brief Bot重新登录事件
99 *
100 */
101class BotReloginEvent final : public BotAccountEvent<BotReloginEvent>
102{
104private:
105 static constexpr EventTypes TYPE_ = EventTypes::BotRelogin;
106};
107
108
109
110/**
111 * @brief Bot群聊权限改变事件
112 *
113 * Member Variable | Default Value
114 * --------------- | -------------
115 * `BotGroupPermissionChangeEvent::group_` | `Group{}`
116 * `BotGroupPermissionChangeEvent::origin_` | `PERMISSION::ENUM_END`
117 * `BotGroupPermissionChangeEvent::current_` | `PERMISSION::ENUM_END`
118 */
119class BotGroupPermissionChangeEvent final : public IEvent<BotGroupPermissionChangeEvent>
120{
122private:
123 Group group_{};
126
127 static constexpr EventTypes TYPE_ = EventTypes::BotGroupPermissionChange;
128
129public:
130 /// 获取群聊信息
131 Group GetGroup() const { return this->group_; }
132 /// 获取Bot更改前的权限
133 PERMISSION GetOriginal() const { return this->origin_; }
134 /// 获取Bot当前权限
135 PERMISSION GetCurrent() const { return this->current_; }
136
137 struct Serializable;
138};
139
140
141
142/**
143 * @brief Bot被邀请加群事件
144 *
145 * Member Variable | Default Value
146 * --------------- | -------------
147 * `BotInvitedJoinGroupRequestEvent::EventId_` | `0`
148 * `BotInvitedJoinGroupRequestEvent::FromId_` | `0_qq`
149 * `BotInvitedJoinGroupRequestEvent::GroupId_` | `0_gid`
150 * `BotInvitedJoinGroupRequestEvent::GroupName_` | `""`
151 * `BotInvitedJoinGroupRequestEvent::nickname_` | `""`
152 * `BotInvitedJoinGroupRequestEvent::message_` | `""`
153 */
154class BotInvitedJoinGroupRequestEvent final : public IEvent<BotInvitedJoinGroupRequestEvent>
155{
157
158private:
159 int64_t EventId_ = 0;
160 QQ_t FromId_{};
161 GID_t GroupId_{};
162 std::string GroupName_{};
163 std::string nickname_{};
164 std::string message_{};
165
166 static constexpr EventTypes TYPE_ = EventTypes::BotInvitedJoinGroupRequest;
167
168public:
169 /// 获取事件id,唯一标识符
170 int64_t GetEventId() const { return this->EventId_; }
171 /// 获取邀请人QQ
172 QQ_t GetUserId() const { return this->FromId_; }
173 /// 获取邀请人昵称
174 std::string GetNickname() const { return this->nickname_; }
175 /// 获取群聊id
176 GID_t GetGroupId() const { return this->GroupId_; }
177 /// 获取群聊名称
178 std::string GetGroupName() const { return this->GroupName_; }
179 /// 获取邀请信息
180 std::string GetMessage() const { return this->message_; }
181
182 // TODO: add helper methods for quick response
183
184 struct Serializable;
185};
186
187
188
189/**
190 * @brief Bot加入群聊事件
191 *
192 * Member Variable | Default Value
193 * --------------- | -------------
194 * `BotJoinGroupEvent::group_` | `Group{}`
195 * `BotJoinGroupEvent::inviter_` | `std::nullopt`
196 */
197class BotJoinGroupEvent final : public IEvent<BotJoinGroupEvent>
198{
200private:
201 Group group_{};
202 std::optional<GroupMember> inviter_ = std::nullopt;
203
204 static constexpr EventTypes TYPE_ = EventTypes::BotJoinGroup;
205
206public:
207 /// 获取群聊信息
208 Group GetGroup() const { return this->group_; }
209 /// 获取邀请人信息,若无则返回 `std::nullopt`
210 std::optional<GroupMember> GetInviter() const { return this->inviter_; }
211
212 struct Serializable;
213};
214
215
216
217/**
218 * @brief Bot退群相关事件
219 *
220 * Middleware for all bot leave group events
221 * Member Variable | Default Value
222 * --------------- | -------------
223 * `BotLeaveEvent::group_` | `Group{}`
224 */
225template <class Event>
226class BotLeaveEvent : public IEvent<Event>
227{
228protected:
230
231public:
232 /// 获取群聊信息
233 Group GetGroup() const { return this->group_; }
234
235 struct Serializable;
236};
237
238/**
239 * @brief Bot主动退群事件
240 *
241 * Member Variable | Default Value
242 * --------------- | -------------
243 * `BotLeaveEventActive::group_` | `Group{}`
244 */
245class BotLeaveEventActive final : public BotLeaveEvent<BotLeaveEventActive>
246{
248private:
249 static constexpr EventTypes TYPE_ = EventTypes::BotLeaveActive;
250};
251
252/**
253 * @brief 群聊解散导致Bot退群事件
254 *
255 * Member Variable | Default Value
256 * --------------- | -------------
257 * `BotLeaveEventDisband::group_` | `Group{}`
258 * `BotLeaveEventDisband::operator_` | `GroupMember{}`
259 */
260class BotLeaveEventDisband final : public BotLeaveEvent<BotLeaveEventDisband>
261{
263private:
264 GroupMember operator_;
265
266 static constexpr EventTypes TYPE_ = EventTypes::BotLeaveDisband;
267
268public:
269 /// 获取操作员(群主)信息
270 GroupMember GetOperator() const { return this->operator_; }
271
272 struct Serializable;
273};
274
275/**
276 * @brief Bot被踢出群聊事件
277 *
278 * Member Variable | Default Value
279 * --------------- | -------------
280 * `BotLeaveEventKick::group_` | `Group{}`
281 * `BotLeaveEventKick::operator_` | `std::optional<GroupMember>{}`
282 */
283class BotLeaveEventKick final : public BotLeaveEvent<BotLeaveEventKick>
284{
286private:
287 std::optional<GroupMember> operator_ = std::nullopt;
288
289 static constexpr EventTypes TYPE_ = EventTypes::BotLeaveKick;
290
291public:
292 /// 获取操作员信息,若无则返回 `std::nullopt`
293 std::optional<GroupMember> GetOperator() const { return this->operator_; }
294
295 struct Serializable;
296};
297
298
299
300/**
301 * @brief Bot被禁言事件
302 *
303 * Member Variable | Default Value
304 * --------------- | -------------
305 * `BotMuteEvent::operator_` | `GroupMember{}`
306 * `BotMuteEvent::duration_` | `0`
307 */
308class BotMuteEvent final : public IEvent<BotMuteEvent>
309{
311protected:
313 std::time_t duration_ = 0;
314
316
317public:
318 /// 获取操作员信息
319 GroupMember GetOperator() const { return this->operator_; }
320 /// 获取禁言时间
321 std::chrono::seconds GetMuteTime() const { return std::chrono::seconds(this->duration_); }
322
323 struct Serializable;
324};
325
326
327
328/**
329 * @brief Bot被取消禁言事件
330 *
331 * Member Variable | Default Value
332 * --------------- | -------------
333 * `BotUnmuteEvent::operator_` | `GroupMember{}`
334 */
335class BotUnmuteEvent final : public IEvent<BotUnmuteEvent>
336{
338private:
339 GroupMember operator_;
340 static constexpr EventTypes TYPE_ = EventTypes::BotUnmute;
341
342public:
343 /// 获取操作员信息
344 GroupMember GetOperator() const { return this->operator_; }
345
346 struct Serializable;
347};
348
349
350#define DECLARE_TYPE_ENUM(event_type) \
351 template<> struct GetEventType<event_type::GetType()> \
352 { \
353 using type = event_type; \
354 }
355
369
370#undef DECLARE_TYPE_ENUM
371
372
373} // namespace Mirai
374
375
376#endif
与Bot账号相关的事件
Definition: BotEvents.hpp:40
QQ_t GetQQ() const
获取BotQQ
Definition: BotEvents.hpp:46
Bot群聊权限改变事件
Definition: BotEvents.hpp:120
Group GetGroup() const
获取群聊信息
Definition: BotEvents.hpp:131
PERMISSION GetOriginal() const
获取Bot更改前的权限
Definition: BotEvents.hpp:133
PERMISSION GetCurrent() const
获取Bot当前权限
Definition: BotEvents.hpp:135
std::string GetMessage() const
获取邀请信息
Definition: BotEvents.hpp:180
QQ_t GetUserId() const
获取邀请人QQ
Definition: BotEvents.hpp:172
GID_t GetGroupId() const
获取群聊id
Definition: BotEvents.hpp:176
std::string GetGroupName() const
获取群聊名称
Definition: BotEvents.hpp:178
int64_t GetEventId() const
获取事件id,唯一标识符
Definition: BotEvents.hpp:170
std::string GetNickname() const
获取邀请人昵称
Definition: BotEvents.hpp:174
Bot加入群聊事件
Definition: BotEvents.hpp:198
Group GetGroup() const
获取群聊信息
Definition: BotEvents.hpp:208
std::optional< GroupMember > GetInviter() const
获取邀请人信息,若无则返回 std::nullopt
Definition: BotEvents.hpp:210
Bot主动退群事件
Definition: BotEvents.hpp:246
群聊解散导致Bot退群事件
Definition: BotEvents.hpp:261
GroupMember GetOperator() const
获取操作员(群主)信息
Definition: BotEvents.hpp:270
Bot被踢出群聊事件
Definition: BotEvents.hpp:284
std::optional< GroupMember > GetOperator() const
获取操作员信息,若无则返回 std::nullopt
Definition: BotEvents.hpp:293
Bot退群相关事件
Definition: BotEvents.hpp:227
Group GetGroup() const
获取群聊信息
Definition: BotEvents.hpp:233
Bot被禁言事件
Definition: BotEvents.hpp:309
GroupMember operator_
Definition: BotEvents.hpp:312
static constexpr EventTypes TYPE_
Definition: BotEvents.hpp:315
GroupMember GetOperator() const
获取操作员信息
Definition: BotEvents.hpp:319
std::time_t duration_
Definition: BotEvents.hpp:313
std::chrono::seconds GetMuteTime() const
获取禁言时间
Definition: BotEvents.hpp:321
Bot主动下线事件
Definition: BotEvents.hpp:56
Bot强制下线事件
Definition: BotEvents.hpp:80
Bot上线事件
Definition: BotEvents.hpp:91
Bot重新登录事件
Definition: BotEvents.hpp:102
Bot被取消禁言事件
Definition: BotEvents.hpp:336
GroupMember GetOperator() const
获取操作员信息
Definition: BotEvents.hpp:344
群聊号码类型
Definition: BasicTypes.hpp:88
Common interface for all event types
Definition: IEvent.hpp:34
QQ号码类型
Definition: BasicTypes.hpp:71
所有mirai相关的对象的命名空间
PERMISSION
群成员权限
Definition: BasicTypes.hpp:185
DECLARE_TYPE_ENUM(BotOfflineEventActive)
群员资料
Definition: BasicTypes.hpp:362
群聊资料
Definition: BasicTypes.hpp:333