cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
BasicTypes.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_TYPES_BASIC_TYPES_HPP_
17#define MIRAI_TYPES_BASIC_TYPES_HPP_
18
19#include <chrono>
20#include <ctime>
21#include <string>
22#include <utility>
23
24#ifdef IGNORE // Oh well, Windows.h again
25#undef IGNORE
26#endif
27
28namespace Mirai
29{
30
31/**
32 * @brief 消息id类型,用于撤回消息和引用消息
33 *
34 */
35using MessageId_t = int64_t;
36
37/**
38 * @brief Base class for QQ_t and GID_t
39 *
40 * 不允许实例化,仅作为基类提供基本功能
41 */
42class UID_t
43{
44protected:
45 int64_t number_ = 0;
46
47 constexpr UID_t() = default;
48 constexpr explicit UID_t(int64_t num) : number_{num} {}
49
50public:
51 constexpr explicit operator int64_t() const { return this->number_; }
52 std::string to_string() const { return std::to_string(this->number_); }
53
54 constexpr bool operator<(const UID_t& uid) const { return this->number_ < uid.number_; }
55 constexpr bool operator==(const UID_t& uid) const { return this->number_ == uid.number_; }
56
57 constexpr bool operator!=(const UID_t& uid) const { return !(*this == uid); }
58 constexpr bool operator>(const UID_t& uid) const { return uid < *this; }
59 constexpr bool operator>=(const UID_t& uid) const { return !(*this < uid); }
60 constexpr bool operator<=(const UID_t& uid) const { return !(uid < *this); }
61
62 struct Serializable;
63};
64
65/**
66 * @brief QQ号码类型
67 *
68 * 本质上为 `int64_t` ,但禁止隐式转换
69 */
70class QQ_t : public UID_t
71{
72public:
73 constexpr QQ_t() : UID_t() {}
74 constexpr explicit QQ_t(int64_t num) : UID_t(num) {}
75};
76
77constexpr inline QQ_t operator""_qq(unsigned long long num)
78{
79 return QQ_t(static_cast<int64_t>(num));
80}
81
82/**
83 * @brief 群聊号码类型
84 *
85 * 本质上为 `int64_t` ,但禁止隐式转换
86 */
87class GID_t : public UID_t
88{
89public:
90 constexpr GID_t() : UID_t() {}
91 constexpr explicit GID_t(int64_t num) : UID_t(num) {}
92};
93
94inline constexpr GID_t operator""_gid(unsigned long long num)
95{
96 return GID_t(static_cast<int64_t>(num));
97}
98
99
100// *********************************************
101// ************ ENUM DECLARATIONS **************
102// *********************************************
103
104
105/**
106 * @brief 处理好友申请的操作
107 *
108 * Value | Operation
109 * ---------|----------
110 * `ACCEPT` | 同意好友申请
111 * `REFUSE` | 拒绝好友申请
112 * `BLACKLIST` | 拒绝并拉黑,不再接收此人的申请
113 */
115{
116 ACCEPT = 0,
117 REFUSE,
119};
120
121/**
122 * @brief 处理用户入群申请的操作
123 *
124 * Value | Operation
125 * ---------|----------
126 * `ACCEPT` | 同意入群申请
127 * `REFUSE` | 拒绝入群申请
128 * `IGNORE` | 忽略入群申请
129 * `REFUSE_BLACKLIST` | 拒绝并拉黑,不再接收此人的申请
130 * `IGNORE_BLACKLIST` | 忽略并拉黑,不再接收此人的申请
131 */
133{
134 ACCEPT = 0,
135 REFUSE,
136 IGNORE,
139};
140
141/**
142 * @brief 处理被邀请入群的操作
143 *
144 * Value | Operation
145 * ---------|----------
146 * `ACCEPT` | 同意邀请
147 * `REFUSE` | 拒绝拒绝邀请
148 */
150{
151 ACCEPT = 0,
152 REFUSE
153};
154
155/**
156 * @brief QQ用户性别
157 *
158 * Value | Operation
159 * ---------|----------
160 * `MALE` | 男性
161 * `FEMALE` | 女性
162 * `UNKNOWN` | 未知性别
163 */
164enum class SEX
165{
166 MALE = 0,
167 FEMALE,
168 UNKNOWN,
169
170 // Used for counting
172};
173
174/**
175 * @brief 群成员权限
176 *
177 * `ENUM_END` 为保留字段,使用时出现说明数据不合法
178 * Value | Operation
179 * ---------|----------
180 * `OWNER` | 群主
181 * `ADMINISTRATOR` | 管理员
182 * `MEMBER` | 普通成员
183 */
184enum class PERMISSION
185{
186 OWNER = 0,
188 MEMBER,
189
190 // Used for counting
192};
193
194/**
195 * @brief 头像戳一戳消息的发送环境
196 *
197 * `ENUM_END` 为保留字段,使用时出现说明数据不合法
198 * Value | Operation
199 * ---------|----------
200 * `FRIEND` | 好友发送
201 * `GROUP` | 群聊发送
202 * `STRANGER` | 陌生人发送
203 */
204enum class NudgeType
205{
206 FRIEND = 0,
207 GROUP,
208 STRANGER,
209
210 // Used for counting
212};
213
214/**
215 * @brief 音乐卡片类型
216 *
217 * `ENUM_END` 为保留字段,使用时出现说明数据不合法
218 */
220{
222 QQMUSIC,
223 MIGUMUSIC,
225 KUWOMUSIC,
226
227 // Used for counting
229};
230
231/**
232 * @brief 戳一戳(原窗口抖动)类型
233 *
234 * `ENUM_END` 为保留字段,使用时出现说明数据不合法
235 */
236enum class PokeType
237{
238 CHUOYICHUO = 0, // 戳一戳
239 BIXIN, // 比心
240 DIANZAN, // 点赞
241 XINSUI, // 心碎
242 LIULIULIU, // 666
243 FANGDAZHAO, // 放大招
244 GOUYIN, // 勾引
245 BAOBEIQIU, // 宝贝球 (SVIP)
246 ROSE, // 玫瑰花 (SVIP)
247 ZHAOHUANSHU, // 召唤术 (SVIP)
248 RANGNIPI, // 让你皮 (SVIP)
249 JIEYIN, // 结印 (SVIP)
250 SHOULEI, // 手雷 (SVIP)
251 ZHUAYIXIA, // 抓一下 (SVIP)
252 SUIPING, // 碎屏 (SVIP)
253 QIAOMEN, // 敲门 (SVIP)
254
255 // Used for counting
257};
258
259/**
260 * @brief 群称号改变类型
261 *
262 * `ENUM_END` 为保留字段,使用时出现说明数据不合法
263 * Value | Operation
264 * ---------|----------
265 * `ACHIEVE` | 获得称号
266 * `LOSE` | 失去称号
267 */
269{
270 ACHIEVE = 0,
271 LOSE,
272
273 // Used for counting
275};
276
277/**
278 * @brief 指令发送者类型
279 *
280 * Value | Operation
281 * ---------|----------
282 * `FRIEND` | 好友
283 * `MEMBER` | 群聊
284 * `CONSOLE` | 控制台 (MCL)
285 */
287{
288 FRIEND = 0,
289 MEMBER,
290 CONSOLE
291};
292
293
294// *********************************************
295// ********** ENUM DECLARATIONS END ************
296// *********************************************
297
298
299/**
300 * @brief QQ用户
301 *
302 * 最基础的用户资料,需要更详细的内容请使用 `UserProfile` 类
303 */
304struct User
305{
306 /// 用户QQ号
308 /// 用户昵称
309 std::string nickname;
310 /// 用户备注(仅对好友有效)
311 std::string remark;
312
313 User(QQ_t id = 0_qq, std::string nickname = "", std::string remark = "")
314 : id(id), nickname(std::move(nickname)), remark(std::move(remark))
315 {
316 }
317
318 /**
319 * @brief 判定两用户是否为同一人
320 *
321 * 仅判断QQ号
322 */
323 bool operator==(const User& rhs) const { return this->id == rhs.id; }
324
325 struct Serializable;
326};
327
328/**
329 * @brief 群聊资料
330 *
331 */
332struct Group
333{
334 /// 群聊号码
336 /// 群聊名称
337 std::string name;
338 /// Bot在群聊中的权限
340
341 Group(GID_t id = 0_gid, std::string name = "", PERMISSION permission = PERMISSION::ENUM_END)
342 : id(id), name(std::move(name)), permission(permission)
343 {
344 }
345
346 /**
347 * @brief 判定两群聊是否为同一群
348 *
349 * 仅判断群号
350 */
351 bool operator==(const Group& rhs) const { return this->id == rhs.id; }
352
353 struct Serializable;
354};
355
356/**
357 * @brief 群员资料
358 *
359 * 仅含有与群聊相关的部分,个人资料请使用 `User` 与 `UserProfile` 类
360 */
362{
363 /// 群员id
365 /// 群员名片
366 std::string MemberName;
367 /// 群员权限
369 /// 群头衔
370 std::string SpecialTitle;
371 /// 入群时间
372 std::time_t JoinTimestamp = 0;
373 /// 最后一次发言时间
374 std::time_t LastSpeakTimestamp = 0;
375 /// 剩余禁言时间
376 std::chrono::seconds MuteTimeRemaining = std::chrono::seconds(0);
377 /// 群聊资料
379
381 std::string SpecialTitle = "", std::time_t JoinTimestamp = 0, std::time_t LastSpeakTimestamp = 0,
382 std::chrono::seconds MuteTimeRemaining = std::chrono::seconds(0), Group group = {})
383 : id(id)
384 , MemberName(std::move(MemberName))
386 , SpecialTitle(std::move(SpecialTitle))
390 , group(std::move(group))
391 {
392 }
393
394 /**
395 * @brief 判定两群员是否为同一人
396 *
397 * 仅判断群号与QQ号
398 */
399 bool operator==(const GroupMember& rhs) const { return this->id == rhs.id && this->group == rhs.group; }
400
401 struct Serializable;
402};
403
404/**
405 * @brief QQ用户资料
406 *
407 */
409{
410 /// QQ昵称
411 std::string nickname;
412 /// QQ邮箱
413 std::string email;
414 /// 年龄
415 int age = 0;
416 /// QQ等级
417 int level = 0;
418 /// QQ签名
419 std::string sign;
420 /// 性别
422
423 UserProfile(std::string nickname = "", std::string email = "", int age = 0, int level = 0, std::string sign = "",
425 : nickname(std::move(nickname))
426 , email(std::move(email))
427 , age(age)
428 , level(level)
429 , sign(std::move(sign))
430 , sex(sex)
431 {
432 }
433
434 /**
435 * @brief 比较用户资料是否相同
436 *
437 * 等价与所有成员变量分别判断相等。由于用户资料可能巧合,因此不保证真的为同一人
438 */
439 bool operator==(const UserProfile& rhs) const
440 {
441 return this->nickname == rhs.nickname && this->email == rhs.email && this->age == rhs.age
442 && this->level == rhs.level && this->sign == rhs.sign && this->sex == rhs.sex;
443 }
444
445 struct Serializable;
446};
447
448/**
449 * @brief 设备类型
450 *
451 */
453{
454 /// 设备id,唯一标识符
455 int64_t id = 0;
456 /// 设备平台
457 std::string platform; // TODO:replace with enum
458
459 ClientDevice(int64_t id = 0, std::string platform = "") : id(id), platform(std::move(platform)) {}
460
461 /**
462 * @brief 判断设备是否相同
463 *
464 */
465 bool operator==(const ClientDevice& rhs) const { return this->id == rhs.id && this->platform == rhs.platform; }
466
467 struct Serializable;
468};
469
470} // namespace Mirai
471
472namespace std
473{
474
475template<> struct hash<Mirai::GID_t>
476{
477 std::size_t operator()(const Mirai::GID_t& t) const { return hash<int64_t>{}((int64_t)t); }
478};
479
480template<> struct hash<Mirai::QQ_t>
481{
482 std::size_t operator()(const Mirai::QQ_t& t) const { return hash<int64_t>{}((int64_t)t); }
483};
484
485} // namespace std
486
487
488#endif
群聊号码类型
Definition: BasicTypes.hpp:88
constexpr GID_t()
Definition: BasicTypes.hpp:90
constexpr GID_t(int64_t num)
Definition: BasicTypes.hpp:91
QQ号码类型
Definition: BasicTypes.hpp:71
constexpr QQ_t(int64_t num)
Definition: BasicTypes.hpp:74
constexpr QQ_t()
Definition: BasicTypes.hpp:73
Base class for QQ_t and GID_t
Definition: BasicTypes.hpp:43
constexpr bool operator>(const UID_t &uid) const
Definition: BasicTypes.hpp:58
int64_t number_
Definition: BasicTypes.hpp:45
constexpr UID_t()=default
constexpr bool operator>=(const UID_t &uid) const
Definition: BasicTypes.hpp:59
constexpr bool operator<(const UID_t &uid) const
Definition: BasicTypes.hpp:54
constexpr UID_t(int64_t num)
Definition: BasicTypes.hpp:48
constexpr bool operator==(const UID_t &uid) const
Definition: BasicTypes.hpp:55
std::string to_string() const
Definition: BasicTypes.hpp:52
constexpr bool operator<=(const UID_t &uid) const
Definition: BasicTypes.hpp:60
constexpr bool operator!=(const UID_t &uid) const
Definition: BasicTypes.hpp:57
所有mirai相关的对象的命名空间
CommandSender
指令发送者类型
Definition: BasicTypes.hpp:287
SEX
QQ用户性别
Definition: BasicTypes.hpp:165
NewFriendRequestOp
处理好友申请的操作
Definition: BasicTypes.hpp:115
NudgeType
头像戳一戳消息的发送环境
Definition: BasicTypes.hpp:205
std::string to_string(EventTypes type)
BotInvitedJoinGroupRequestOp
处理被邀请入群的操作
Definition: BasicTypes.hpp:150
HonorChangeType
群称号改变类型
Definition: BasicTypes.hpp:269
PERMISSION
群成员权限
Definition: BasicTypes.hpp:185
int64_t MessageId_t
消息id类型,用于撤回消息和引用消息
Definition: BasicTypes.hpp:35
MusicShareType
音乐卡片类型
Definition: BasicTypes.hpp:220
MemberJoinRequestOp
处理用户入群申请的操作
Definition: BasicTypes.hpp:133
PokeType
戳一戳(原窗口抖动)类型
Definition: BasicTypes.hpp:237
STL namespace
int64_t id
设备id,唯一标识符
Definition: BasicTypes.hpp:455
bool operator==(const ClientDevice &rhs) const
判断设备是否相同
Definition: BasicTypes.hpp:465
std::string platform
设备平台
Definition: BasicTypes.hpp:457
ClientDevice(int64_t id=0, std::string platform="")
Definition: BasicTypes.hpp:459
群员资料
Definition: BasicTypes.hpp:362
Group group
群聊资料
Definition: BasicTypes.hpp:378
bool operator==(const GroupMember &rhs) const
判定两群员是否为同一人
Definition: BasicTypes.hpp:399
GroupMember(QQ_t id=0_qq, std::string MemberName="", PERMISSION permission=PERMISSION::ENUM_END, std::string SpecialTitle="", std::time_t JoinTimestamp=0, std::time_t LastSpeakTimestamp=0, std::chrono::seconds MuteTimeRemaining=std::chrono::seconds(0), Group group={})
Definition: BasicTypes.hpp:380
std::string SpecialTitle
群头衔
Definition: BasicTypes.hpp:370
std::string MemberName
群员名片
Definition: BasicTypes.hpp:366
QQ_t id
群员id
Definition: BasicTypes.hpp:364
std::time_t LastSpeakTimestamp
最后一次发言时间
Definition: BasicTypes.hpp:374
std::chrono::seconds MuteTimeRemaining
剩余禁言时间
Definition: BasicTypes.hpp:376
PERMISSION permission
群员权限
Definition: BasicTypes.hpp:368
std::time_t JoinTimestamp
入群时间
Definition: BasicTypes.hpp:372
群聊资料
Definition: BasicTypes.hpp:333
std::string name
群聊名称
Definition: BasicTypes.hpp:337
GID_t id
群聊号码
Definition: BasicTypes.hpp:335
PERMISSION permission
Bot在群聊中的权限
Definition: BasicTypes.hpp:339
Group(GID_t id=0_gid, std::string name="", PERMISSION permission=PERMISSION::ENUM_END)
Definition: BasicTypes.hpp:341
bool operator==(const Group &rhs) const
判定两群聊是否为同一群
Definition: BasicTypes.hpp:351
QQ用户资料
Definition: BasicTypes.hpp:409
bool operator==(const UserProfile &rhs) const
比较用户资料是否相同
Definition: BasicTypes.hpp:439
UserProfile(std::string nickname="", std::string email="", int age=0, int level=0, std::string sign="", SEX sex=SEX::ENUM_END)
Definition: BasicTypes.hpp:423
std::string sign
QQ签名
Definition: BasicTypes.hpp:419
int level
QQ等级
Definition: BasicTypes.hpp:417
std::string email
QQ邮箱
Definition: BasicTypes.hpp:413
std::string nickname
QQ昵称
Definition: BasicTypes.hpp:411
QQ用户
Definition: BasicTypes.hpp:305
bool operator==(const User &rhs) const
判定两用户是否为同一人
Definition: BasicTypes.hpp:323
std::string nickname
用户昵称
Definition: BasicTypes.hpp:309
std::string remark
用户备注(仅对好友有效)
Definition: BasicTypes.hpp:311
QQ_t id
用户QQ号
Definition: BasicTypes.hpp:307
User(QQ_t id=0_qq, std::string nickname="", std::string remark="")
Definition: BasicTypes.hpp:313
std::size_t operator()(const Mirai::GID_t &t) const
Definition: BasicTypes.hpp:477
std::size_t operator()(const Mirai::QQ_t &t) const
Definition: BasicTypes.hpp:482