cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
DiceMessage.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_DICE_MESSAGE_HPP_
17#define MIRAI_DICE_MESSAGE_HPP_
18
19#include <string>
20
21#include "IMessage.hpp"
22
23namespace Mirai
24{
25
26/**
27 * @brief 骰子消息
28 *
29 * Member Variable | Default Value
30 * --------------- | -------------
31 * `DiceMessage::value_` | `-1`
32 */
33class DiceMessage final : public IMessageImpl<DiceMessage>
34{
36
37protected:
38 int value_ = -1;
39
40 bool isValid_() const final { return this->value_ > 0 && this->value_ <= 6; }
41
43 static constexpr bool SUPPORT_SEND_ = true;
44
45public:
46 DiceMessage() = default;
47 DiceMessage(int value)
48 {
49 if (value > 0 && value <= 6) this->value_ = value;
50 else
51 this->value_ = -1;
52 }
53
54 bool operator==(const DiceMessage& rhs) { return this->value_ == rhs.value_; }
55
56 bool operator!=(const DiceMessage& rhs) { return !(*this == rhs); }
57
58 /// 获取骰子点数
59 int GetValue() const { return this->value_; }
60
61 /// 设置骰子点数,不在1~6之间的值将不会被设置
63 {
64 if (value > 0 && value <= 6) this->value_ = value;
65 return *this;
66 }
67
68 struct Serializable;
69};
70
71template<> struct GetType<DiceMessage::GetType()>
72{
74};
75
76} // namespace Mirai
77
78
79#endif
骰子消息
Definition: DiceMessage.hpp:34
bool operator==(const DiceMessage &rhs)
Definition: DiceMessage.hpp:54
bool isValid_() const final
Definition: DiceMessage.hpp:40
DiceMessage()=default
int GetValue() const
获取骰子点数
Definition: DiceMessage.hpp:59
DiceMessage & SetValue(int value)
设置骰子点数,不在1~6之间的值将不会被设置
Definition: DiceMessage.hpp:62
static constexpr MessageTypes TYPE_
Definition: DiceMessage.hpp:42
static constexpr bool SUPPORT_SEND_
Definition: DiceMessage.hpp:43
DiceMessage(int value)
Definition: DiceMessage.hpp:47
bool operator!=(const DiceMessage &rhs)
Definition: DiceMessage.hpp:56
CRTP helper layer
Definition: IMessage.hpp:78
所有mirai相关的对象的命名空间
用于类型之间转换的辅助模板