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