cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
FaceMessage.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_FACE_MESSAGE_HPP_
17#define MIRAI_FACE_MESSAGE_HPP_
18
19#include <string>
20
21#include "IMessage.hpp"
22
23namespace Mirai
24{
25
26/**
27 * @brief QQ表情类消息
28 *
29 * Middleware for face related messages
30 */
31template <class Message>
32class FaceMessageImpl : public IMessageImpl<Message>
33{
34protected:
35 int64_t id_ = -1;
36 std::string name_{};
37
38 bool isValid_() const override { return this->id_ != -1 || !this->name_.empty(); }
39
40public:
41 FaceMessageImpl() = default;
42 FaceMessageImpl(int64_t id) : id_(id) {}
43 FaceMessageImpl(std::string name) : name_(std::move(name)) {}
44
45 bool operator==(const FaceMessageImpl& rhs) { return (id_ >= 0) ? this->id_ == rhs.id_ : this->name_ == rhs.name_; }
46
47 bool operator!=(const FaceMessageImpl& rhs) { return !(*this == rhs); }
48
49 /// 获取表情id
50 int64_t GetId() const { return this->id_; }
51
52 /// 获取表情名称
53 std::string GetName() const { return this->name_; }
54
55 /// 设置表情id
56 Message& SetId(int64_t id)
57 {
58 this->id_ = id;
59 return *static_cast<Message*>(this);
60 }
61
62 /// 设置表情名称。这一操作会清除已设置的id。
63 Message& SetName(std::string name)
64 {
65 this->id_ = -1;
66 this->name_ = std::move(name);
67 return *static_cast<Message*>(this);
68 }
69
70 struct Serializable;
71};
72
73
74
75/**
76 * @brief QQ表情消息
77 *
78 * 表情可以通过 `id` 或 `name` 发送,优先级 `id` > `name`
79 *
80 * Member Variable | Default Value
81 * --------------- | -------------
82 * `FaceMessage::id_` | `-1`
83 * `FaceMessage::name_` | `""`
84 */
85class FaceMessage final : public FaceMessageImpl<FaceMessage>
86{
88
89protected:
91 static constexpr bool SUPPORT_SEND_ = true;
92
93public:
95};
96
97template<> struct GetType<FaceMessage::GetType()>
98{
100};
101
102
103
104/**
105 * @brief QQ商店表情消息
106 *
107 * 仅用于接收,发送时将会被无视
108 *
109 * Member Variable | Default Value
110 * --------------- | -------------
111 * `MarketFaceMessage::id_` | `-1`
112 * `MarketFaceMessage::name_` | `""`
113 */
114class MarketFaceMessage final : public FaceMessageImpl<MarketFaceMessage>
115{
117
118protected:
119 bool isValid_() const final { return true; }
120
122 static constexpr bool SUPPORT_SEND_ = false;
123
124public:
126};
127
128template<> struct GetType<MarketFaceMessage::GetType()>
129{
131};
132
133} // namespace Mirai
134
135
136#endif
QQ表情类消息
Definition: FaceMessage.hpp:33
std::string GetName() const
获取表情名称
Definition: FaceMessage.hpp:53
bool isValid_() const override
Definition: FaceMessage.hpp:38
FaceMessageImpl(std::string name)
Definition: FaceMessage.hpp:43
int64_t GetId() const
获取表情id
Definition: FaceMessage.hpp:50
Message & SetId(int64_t id)
设置表情id
Definition: FaceMessage.hpp:56
Message & SetName(std::string name)
设置表情名称。这一操作会清除已设置的id。
Definition: FaceMessage.hpp:63
bool operator!=(const FaceMessageImpl &rhs)
Definition: FaceMessage.hpp:47
FaceMessageImpl(int64_t id)
Definition: FaceMessage.hpp:42
bool operator==(const FaceMessageImpl &rhs)
Definition: FaceMessage.hpp:45
QQ表情消息
Definition: FaceMessage.hpp:86
static constexpr MessageTypes TYPE_
Definition: FaceMessage.hpp:90
static constexpr bool SUPPORT_SEND_
Definition: FaceMessage.hpp:91
CRTP helper layer
Definition: IMessage.hpp:78
QQ商店表情消息
static constexpr bool SUPPORT_SEND_
bool isValid_() const final
static constexpr MessageTypes TYPE_
所有mirai相关的对象的命名空间
STL namespace
用于类型之间转换的辅助模板