cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
ImageMessage.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_IMAGE_MESSAGE_HPP_
17#define MIRAI_IMAGE_MESSAGE_HPP_
18
19#include <string>
20#include <utility>
21
24
25#include "IMessage.hpp"
26
27namespace Mirai
28{
29
30/**
31 * @brief 图片类消息
32 *
33 * Middleware for image related messages
34 */
35template <class MessageImpl>
36class ImageMessageImpl : public IMessageImpl<MessageImpl>
37{
38protected:
40
41 void clear_() noexcept { this->image_ = {}; }
42
43 bool isValid_() const override { return this->image_.valid(); }
44
45public:
46 ImageMessageImpl() = default;
47 ImageMessageImpl(MiraiImage image) : image_(std::move(image)) {}
48 ImageMessageImpl(std::string ImageId, std::string url, std::string path, std::string base64)
49 : image_(ImageId, url, path, base64)
50 {
51 }
52
53 /**
54 * @brief 获取消息中的图片
55 *
56 * @return `MiraiImage`
57 */
58 MiraiImage GetImage() const { return this->image_; }
59
60 /**
61 * @brief 设置图片id
62 *
63 * 发送图片只需要id、链接、路径、base64编码中的一个,因此该方法会清空其它的属性
64 * @param ImageId 图片id
65 */
66 MessageImpl& SetImageId(std::string ImageId)
67 {
68 this->clear_();
69 this->image_.id = std::move(ImageId);
70 return *static_cast<MessageImpl*>(this);
71 }
72
73 /**
74 * @brief 设置图片链接
75 *
76 * 发送图片只需要id、链接、路径、base64编码中的一个,因此该方法会清空其它的属性
77 * @param url 图片链接
78 */
79 MessageImpl& SetUrl(std::string url)
80 {
81 this->clear_();
82 this->image_.url = std::move(url);
83 return *static_cast<MessageImpl*>(this);
84 }
85
86 /**
87 * @brief 设置图片路径
88 *
89 * 发送图片只需要id、链接、路径、base64编码中的一个,因此该方法会清空其它的属性
90 * @param path 图片路径
91 */
92 MessageImpl& SetPath(std::string path)
93 {
94 this->clear_();
95 this->image_.path = std::move(path);
96 return *static_cast<MessageImpl*>(this);
97 }
98
99 /**
100 * @brief 设置图片base64编码
101 *
102 * 发送图片只需要id、链接、路径、base64编码中的一个,因此该方法会清空其它的属性
103 * @param base64 图片base64编码
104 */
105 MessageImpl& SetBase64(std::string base64)
106 {
107 this->clear_();
108 this->image_.base64 = std::move(base64);
109 return *static_cast<MessageImpl*>(this);
110 }
111
112 /// 由 `MiraiImage` 设置图片内容
113 MessageImpl& SetImage(MiraiImage image)
114 {
115 this->clear_();
116 this->image_ = std::move(image);
117 return *static_cast<MessageImpl*>(this);
118 }
119
120 struct Serializable;
121};
122
123
124
125/**
126 * @brief 图片消息
127 *
128 * Member Variable | Default Value
129 * --------------- | -------------
130 * `ImageMessage::image_` | `MiraiImage{}`
131 */
132class ImageMessage final : public ImageMessageImpl<ImageMessage>
133{
135
136protected:
138 static constexpr bool SUPPORT_SEND_ = true;
139
140public:
142};
143
144template<> struct GetType<ImageMessage::GetType()>
145{
147};
148
149
150
151/**
152 * @brief 闪照消息
153 *
154 * Member Variable | Default Value
155 * --------------- | -------------
156 * `FlashImageMessage::image_` | `MiraiImage{}`
157 */
158class FlashImageMessage final : public ImageMessageImpl<FlashImageMessage>
159{
161
162protected:
164 static constexpr bool SUPPORT_SEND_ = true;
165
166public:
168};
169
170template<> struct GetType<FlashImageMessage::GetType()>
171{
173};
174
175} // namespace Mirai
176
177
178#endif
static constexpr MessageTypes TYPE_
static constexpr bool SUPPORT_SEND_
CRTP helper layer
Definition: IMessage.hpp:78
MessageImpl & SetImageId(std::string ImageId)
设置图片id
MiraiImage GetImage() const
获取消息中的图片
ImageMessageImpl(MiraiImage image)
MessageImpl & SetBase64(std::string base64)
设置图片base64编码
ImageMessageImpl(std::string ImageId, std::string url, std::string path, std::string base64)
bool isValid_() const override
void clear_() noexcept
MessageImpl & SetPath(std::string path)
设置图片路径
MessageImpl & SetImage(MiraiImage image)
由 MiraiImage 设置图片内容
MessageImpl & SetUrl(std::string url)
设置图片链接
static constexpr MessageTypes TYPE_
static constexpr bool SUPPORT_SEND_
所有mirai相关的对象的命名空间
STL namespace
用于类型之间转换的辅助模板
std::string id
图片id,从mirai获得
Definition: MediaTypes.hpp:204
std::string base64
图片base64编码
Definition: MediaTypes.hpp:210
std::string url
图片链接
Definition: MediaTypes.hpp:206
std::string path
图片路径
Definition: MediaTypes.hpp:208
bool valid() const
检查对象能否用于发送
Definition: MediaTypes.hpp:233