cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
MediaTypes.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_TYPES_MEDIA_TYPES_HPP_
17#define MIRAI_TYPES_MEDIA_TYPES_HPP_
18
19#include <ctime>
20#include <memory>
21#include <optional>
22#include <string>
23#include <utility>
24
26
27
28namespace Mirai
29{
30
31/**
32 * @brief 文件基础信息
33 *
34 * Member Variable | Default Value
35 * --------------- | -------------
36 * `FileInfo::sha1` | `""`
37 * `FileInfo::md5` | `""`
38 * `FileInfo::UploadTime` | `0`
39 * `FileInfo::LastModifyTime` | `0`
40 * `FileInfo::UploaderId` | `0_qq`
41 */
43{
44 /// 文件SHA1
45 std::string sha1;
46 /// 文件MD5
47 std::string md5;
48 /// 文件上传时间
49 std::time_t UploadTime = 0;
50 /// 文件修改时间
51 std::time_t LastModifyTime = 0;
52 /// 上传者QQ
54};
55
56/**
57 * @brief 群文件信息
58 *
59 * 可能为文件夹,此时 `GroupFileInfo::isFile = false` 且
60 * `GroupFileInfo::file` 为空。'GroupFileInfo::DownloadUrl'
61 * 只有当请求了下载信息时才会被设置。
62 *
63 * Member Variable | Default Value
64 * --------------- | -------------
65 * `GroupFileInfo::id` | `""`
66 * `GroupFileInfo::path` | `""`
67 * `GroupFileInfo::name` | `""`
68 * `GroupFileInfo::parent` | `nullptr`
69 * `GroupFileInfo::isFile` | `false`
70 * `GroupFileInfo::size` | `size`
71 * `GroupFileInfo::contact` | `Group{}`
72 * `GroupFileInfo::file` | `std::nullopt`
73 * `GroupFIleInfo::DownloadUrl` | `std::nullopt`
74 */
76{
77 /// 文件id,唯一标识符
78 std::string id;
79 /// 文件路径
80 std::string path;
81 /// 文件名称
82 std::string name;
83 /// 文件父目录
84 std::unique_ptr<GroupFileInfo> parent;
85 bool isFile = false;
86 int64_t size = 0;
87 /// 文件所在的群聊
89
90 /// 文件信息
91 std::optional<FileInfo> file = std::nullopt;
92 /// 文件下载链接
93 std::optional<std::string> DownloadUrl = std::nullopt;
94};
95
96/**
97 * @brief 文件路径
98 *
99 * 类似于Union的结构,可由文件id或者文件位置 `/path/to/file` 指定。
100 * 由于文件名可以不唯一,推荐尽量使用id。
101 *
102 * Member Variable | Default Value
103 * --------------- | -------------
104 * `FilePath::dir_` | `""`
105 * `FilePath::isPath_` | `false`
106 */
108{
109protected:
110 std::string dir_;
111 bool isPath_ = false;
112
113public:
114 /**
115 * @brief 构造函数
116 *
117 */
118 FilePath() = default;
119
120 /**
121 * @brief 构造函数
122 *
123 * @param dir 文件路径,可能为id或文件名路径
124 * @param isPath 是否为文件名路径
125 */
126 FilePath(std::string dir, bool isPath = false) : dir_(std::move(dir)), isPath_(isPath) {}
127
128 /**
129 * @brief 构造函数
130 * @param file `GroupFileInfo` 对象
131 */
132 FilePath(const GroupFileInfo& file) : dir_(file.id) {}
133
134 /**
135 * @brief 判定是否为文件名路径
136 *
137 * @return `bool`
138 */
139 bool isPath() const { return this->isPath_; }
140
141 /**
142 * @brief 获取文件名路径
143 *
144 * 仅当 `isPath()` 为 `true` 时有效,否则返回空字符串
145 * @return 文件名路径
146 */
147 std::string GetPath() const { return this->isPath_ ? this->dir_ : ""; }
148
149 /**
150 * @brief 获取文件id
151 *
152 * 仅当 `isPath()` 为 `false` 时有效,否则返回空字符串
153 * @return 文件id
154 */
155 std::string GetId() const { return this->isPath_ ? "" : this->dir_; }
156
157 /**
158 * @brief 设置文件名路径
159 *
160 * @param path 文件名路径
161 * @return Reference to *this
162 */
163 FilePath& SetPath(const std::string& path)
164 {
165 this->isPath_ = true;
166 this->dir_ = path;
167 return *this;
168 }
169
170 /**
171 * @brief 设置文件id
172 *
173 * @param id 文件名id
174 * @return Reference to *this
175 */
176 FilePath& SetId(const std::string& id)
177 {
178 this->isPath_ = false;
179 this->dir_ = id;
180 return *this;
181 }
182};
183
184/**
185 * @brief Mirai图片
186 *
187 * 发送时可以指定图片id,图片链接,图片路径或图片的base64编码,
188 * 优先级为 id > url > path > base64,所以设置某一项属性前最好确保前面的域为空。
189 * Member Variable | Default Value
190 * --------------- | -------------
191 * `MiraiImage::id` | `""`
192 * `MiraiImage::url` | `""`
193 * `MiraiImage::path` | `""`
194 * `MiraiImage::base64` | `""`
195 * `MiraiImage::width` | `0`
196 * `MiraiImage::height` | `0`
197 * `MiraiImage::size` | `0`
198 * `MiraiImage::ImageType` | `""`
199 * `MiraiImage::isEmoji` | `false`
200 */
202{
203 /// 图片id,从mirai获得
204 std::string id;
205 /// 图片链接
206 std::string url;
207 /// 图片路径
208 std::string path;
209 /// 图片base64编码
210 std::string base64;
211 /// 图片宽度
212 int width = 0;
213 /// 图片长度
214 int height = 0;
215 /// 图片大小
216 int64_t size = 0;
217 /// 图片类型(JPEG,PNG,……)
218 std::string
219 ImageType; // TODO: replace with enum, see https://github.com/mamoe/mirai/blob/dev/mirai-core-api/src/commonMain/kotlin/message/data/Image.kt#L493
220 /// 是否为表情
221 bool isEmoji = false;
222
223 MiraiImage(std::string id = {}, std::string url = {}, std::string path = {}, std::string base64 = {})
224 : id(std::move(id)), url(std::move(url)), path(std::move(path)), base64(std::move(base64))
225 {
226 }
227
228 /**
229 * @brief 检查对象能否用于发送
230 *
231 * @return `bool`
232 */
233 bool valid() const
234 {
235 return !(this->id.empty() && this->url.empty() && this->path.empty() && this->base64.empty());
236 }
237};
238
242
243/**
244 * @brief Mirai语音
245 *
246 * 发送时可以指定语音id,语音链接,语音路径或语音的base64编码,
247 * 优先级为 id > url > path > base64,所以设置某一项属性前最好确保前面的域为空。
248 * 只支持amr或silk格式的音频。
249 * Member Variable | Default Value
250 * --------------- | -------------
251 * `MiraiAudio::id` | `""`
252 * `MiraiAudio::url` | `""`
253 * `MiraiAudio::path` | `""`
254 * `MiraiAudio::base64` | `""`
255 * `MiraiAudio::length` | `0`
256 */
258{
259 /// 音频id,从mirai获得
260 std::string id;
261 /// 音频链接
262 std::string url;
263 /// 音频路径
264 std::string path;
265 /// 音频base64编码
266 std::string base64;
267 /// 音频长度
268 int64_t length = 0;
269
270 MiraiAudio(std::string id = {}, std::string url = {}, std::string path = {}, std::string base64 = {})
271 : id(std::move(id)), url(std::move(url)), path(std::move(path)), base64(std::move(base64))
272 {
273 }
274
275 /**
276 * @brief 检查对象能否用于发送
277 *
278 * @return `bool`
279 */
280 bool valid() const
281 {
282 return !(this->id.empty() && this->url.empty() && this->path.empty() && this->base64.empty());
283 }
284};
285
286// only group audio uploads are supported for now
288
289} // namespace Mirai
290
291#endif
文件路径
Definition: MediaTypes.hpp:108
FilePath & SetPath(const std::string &path)
设置文件名路径
Definition: MediaTypes.hpp:163
FilePath(std::string dir, bool isPath=false)
构造函数
Definition: MediaTypes.hpp:126
bool isPath() const
判定是否为文件名路径
Definition: MediaTypes.hpp:139
std::string GetId() const
获取文件id
Definition: MediaTypes.hpp:155
FilePath & SetId(const std::string &id)
设置文件id
Definition: MediaTypes.hpp:176
std::string dir_
Definition: MediaTypes.hpp:110
FilePath()=default
构造函数
FilePath(const GroupFileInfo &file)
构造函数
Definition: MediaTypes.hpp:132
std::string GetPath() const
获取文件名路径
Definition: MediaTypes.hpp:147
QQ号码类型
Definition: BasicTypes.hpp:71
所有mirai相关的对象的命名空间
STL namespace
文件基础信息
Definition: MediaTypes.hpp:43
std::string sha1
文件SHA1
Definition: MediaTypes.hpp:45
QQ_t UploaderId
上传者QQ
Definition: MediaTypes.hpp:53
std::time_t UploadTime
文件上传时间
Definition: MediaTypes.hpp:49
std::string md5
文件MD5
Definition: MediaTypes.hpp:47
std::time_t LastModifyTime
文件修改时间
Definition: MediaTypes.hpp:51
群文件信息
Definition: MediaTypes.hpp:76
std::string id
文件id,唯一标识符
Definition: MediaTypes.hpp:78
Group contact
文件所在的群聊
Definition: MediaTypes.hpp:88
std::string name
文件名称
Definition: MediaTypes.hpp:82
std::string path
文件路径
Definition: MediaTypes.hpp:80
std::optional< std::string > DownloadUrl
文件下载链接
Definition: MediaTypes.hpp:93
std::unique_ptr< GroupFileInfo > parent
文件父目录
Definition: MediaTypes.hpp:84
std::optional< FileInfo > file
文件信息
Definition: MediaTypes.hpp:91
群聊资料
Definition: BasicTypes.hpp:333
MiraiAudio(std::string id={}, std::string url={}, std::string path={}, std::string base64={})
Definition: MediaTypes.hpp:270
std::string base64
音频base64编码
Definition: MediaTypes.hpp:266
bool valid() const
检查对象能否用于发送
Definition: MediaTypes.hpp:280
int64_t length
音频长度
Definition: MediaTypes.hpp:268
std::string path
音频路径
Definition: MediaTypes.hpp:264
std::string id
音频id,从mirai获得
Definition: MediaTypes.hpp:260
std::string url
音频链接
Definition: MediaTypes.hpp:262
std::string id
图片id,从mirai获得
Definition: MediaTypes.hpp:204
int height
图片长度
Definition: MediaTypes.hpp:214
std::string base64
图片base64编码
Definition: MediaTypes.hpp:210
std::string url
图片链接
Definition: MediaTypes.hpp:206
std::string path
图片路径
Definition: MediaTypes.hpp:208
bool isEmoji
是否为表情
Definition: MediaTypes.hpp:221
bool valid() const
检查对象能否用于发送
Definition: MediaTypes.hpp:233
int width
图片宽度
Definition: MediaTypes.hpp:212
std::string ImageType
图片类型(JPEG,PNG,……)
Definition: MediaTypes.hpp:219
int64_t size
图片大小
Definition: MediaTypes.hpp:216
MiraiImage(std::string id={}, std::string url={}, std::string path={}, std::string base64={})
Definition: MediaTypes.hpp:223