cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
JsonMessage.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_JSON_MESSAGE_HPP_
17#define MIRAI_JSON_MESSAGE_HPP_
18
19#include <string>
20
21#include "IMessage.hpp"
22
23namespace Mirai
24{
25
26/**
27 * @brief JSON消息
28 *
29 * Member Variable | Default Value
30 * --------------- | -------------
31 * `JsonMessage::content_` | `""`
32 */
33class JsonMessage final : public IMessageImpl<JsonMessage>
34{
36
37protected:
38 std::string content_{};
39
41 static constexpr bool SUPPORT_SEND_ = true;
42
43 bool isValid_() const final { return !this->content_.empty(); }
44
45public:
46 JsonMessage() = default;
47 JsonMessage(std::string content) : content_(std::move(content)) {}
48
49 bool operator==(const JsonMessage& rhs) { return this->content_ == rhs.content_; }
50
51 bool operator!=(const JsonMessage& rhs) { return !(*this == rhs); }
52
53 /// 获取消息内容
54 std::string GetContent() const { return this->content_; }
55
56 /// 设置消息内容
57 JsonMessage& SetContent(std::string content)
58 {
59 this->content_ = std::move(content);
60 return *this;
61 }
62
63 struct Serializable;
64};
65
66template<> struct GetType<JsonMessage::GetType()>
67{
69};
70
71} // namespace Mirai
72
73
74#endif
CRTP helper layer
Definition: IMessage.hpp:78
JsonMessage(std::string content)
Definition: JsonMessage.hpp:47
bool operator==(const JsonMessage &rhs)
Definition: JsonMessage.hpp:49
bool operator!=(const JsonMessage &rhs)
Definition: JsonMessage.hpp:51
static constexpr bool SUPPORT_SEND_
Definition: JsonMessage.hpp:41
static constexpr MessageTypes TYPE_
Definition: JsonMessage.hpp:40
std::string GetContent() const
获取消息内容
Definition: JsonMessage.hpp:54
bool isValid_() const final
Definition: JsonMessage.hpp:43
std::string content_
Definition: JsonMessage.hpp:38
JsonMessage & SetContent(std::string content)
设置消息内容
Definition: JsonMessage.hpp:57
JsonMessage()=default
所有mirai相关的对象的命名空间
STL namespace
用于类型之间转换的辅助模板