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

Commit db30afc

Browse files
authored
Merge pull request #88 from cyanray/dev/cyanray
更新: 完善QQ_t和GID_t
2 parents 0e3fd73 + 2fb541c commit db30afc

File tree

2 files changed

+52
-22
lines changed

2 files changed

+52
-22
lines changed

include/mirai/defs/qq_types.hpp

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,73 @@
33
#define mirai_cpp_defs_qq_types_hpp_H_
44

55
#include <exception>
6+
#include <iostream>
67
#include "serializable.hpp"
78
#include "mirai/exported.h"
89

910
namespace Cyan
1011
{
11-
// QQ 号码类型
12-
class QQ_t
12+
// QQ_t 和 GID_t 的基类型
13+
class UID_t
1314
{
1415
public:
15-
QQ_t() :QQ(-1) {}
16-
explicit QQ_t(int64_t qq) :QQ(qq) {}
17-
operator int64_t() const { return QQ; }
18-
int64_t ToInt64() const { return QQ; }
19-
private:
20-
int64_t QQ;
16+
int64_t ToInt64() const
17+
{
18+
return data_;
19+
}
20+
explicit operator int64_t() const
21+
{
22+
return data_;
23+
}
24+
bool operator==(const UID_t& a) const
25+
{
26+
return this->data_ == a.data_;
27+
}
28+
bool operator!=(const UID_t& a) const
29+
{
30+
return !operator==(a);
31+
}
32+
virtual ~UID_t() = default;
33+
protected:
34+
explicit UID_t(int64_t id) : data_(id) {}
35+
virtual void __avoiding_object_slicing() const = 0;
36+
int64_t data_;
2137
};
22-
23-
inline QQ_t operator "" _qq(unsigned long long int v)
38+
39+
// 储存 QQ 号码的类型
40+
class QQ_t : public UID_t
2441
{
25-
return QQ_t(int64_t(v));
26-
}
42+
public:
43+
QQ_t() : UID_t(-1) {}
44+
explicit QQ_t(int64_t id) : UID_t(id) {}
45+
private:
46+
virtual void __avoiding_object_slicing() const override {}
47+
};
2748

28-
// 群号码类型
29-
class GID_t
49+
// 储存群号码的类型
50+
class GID_t : public UID_t
3051
{
3152
public:
32-
GID_t() :GID(-1) {}
33-
explicit GID_t(int64_t gid) :GID(gid) {}
34-
operator int64_t() const { return GID; }
35-
int64_t ToInt64() const { return GID; }
53+
GID_t() : UID_t(-1) {}
54+
explicit GID_t(int64_t id) : UID_t(id) {}
3655
private:
37-
int64_t GID;
56+
virtual void __avoiding_object_slicing() const override {}
3857
};
3958

40-
inline GID_t operator "" _gid(unsigned long long int v)
59+
inline GID_t operator ""_gid(unsigned long long int id)
60+
{
61+
return (GID_t)(id);
62+
}
63+
64+
inline QQ_t operator ""_qq(unsigned long long int id)
65+
{
66+
return (QQ_t)(id);
67+
}
68+
69+
inline std::ostream& operator<<(std::ostream& o, const UID_t& uid)
4170
{
42-
return GID_t(int64_t(v));
71+
o << (int64_t)(uid);
72+
return o;
4373
}
4474

4575
// 消息 ID

include/mirai/events/command_event.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Cyan
4040
{
4141
CommandName = j["name"].get<string>();
4242
Sender = (QQ_t)(j["friend"].get<int64_t>());
43-
GroupId = (GID_t)(QQ_t)(j["group"].get<int64_t>());
43+
GroupId = (GID_t)(j["group"].get<int64_t>());
4444
Args = j["args"].get<vector<string>>();
4545
return true;
4646
}

0 commit comments

Comments
 (0)