cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
AudioMessage.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_AUDIO_MESSAGE_HPP_
17#define MIRAI_AUDIO_MESSAGE_HPP_
18
19#include <string>
20#include <utility>
21
23
24#include "IMessage.hpp"
25
26namespace Mirai
27{
28
29/**
30 * @brief 语音消息
31 *
32 * Member Variable | Default Value
33 * --------------- | -------------
34 * `AudioMessage::audio_` | `MiraiAudio{}`
35 */
36class AudioMessage final : public IMessageImpl<AudioMessage>
37{
39
40private:
41 MiraiAudio audio_{};
42
43 void clear_() noexcept { this->audio_ = {}; }
44
45 bool isValid_() const final { return this->audio_.valid(); }
46
47 static constexpr MessageTypes TYPE_ = MessageTypes::AUDIO;
48 static constexpr bool SUPPORT_SEND_ = true;
49
50public:
51 AudioMessage() = default;
52 AudioMessage(MiraiAudio audio) : audio_(std::move(audio)) {}
53 AudioMessage(std::string AudioId, std::string url, std::string path, std::string base64)
54 : audio_{std::move(AudioId), std::move(url), std::move(path), std::move(base64)}
55 {}
56
57 /**
58 * @brief 获取消息中的音频内容
59 *
60 * @return MiraiAudio
61 */
62 MiraiAudio GetAudio() const { return this->audio_; }
63
64 /**
65 * @brief 设置音频id
66 *
67 * 发送音频只需要id、链接、路径、base64编码中的一个,因此该方法会清空其它的属性
68 * @param AudioId 音频id
69 */
70 AudioMessage& SetAudioId(std::string AudioId)
71 {
72 this->clear_();
73 this->audio_.id = std::move(AudioId);
74 return *this;
75 }
76
77 /**
78 * @brief 设置音频链接
79 *
80 * 发送音频只需要id、链接、路径、base64编码中的一个,因此该方法会清空其它的属性
81 * @param url 音频链接
82 */
83 AudioMessage& SetUrl(std::string url)
84 {
85 this->clear_();
86 this->audio_.url = std::move(url);
87 return *this;
88 }
89
90 /**
91 * @brief 设置音频路径
92 *
93 * 发送音频只需要id、链接、路径、base64编码中的一个,因此该方法会清空其它的属性
94 * @param path 音频路径
95 */
96 AudioMessage& SetPath(std::string path)
97 {
98 this->clear_();
99 this->audio_.path = std::move(path);
100 return *this;
101 }
102
103 /**
104 * @brief 设置音频内容的base64编码
105 *
106 * 发送音频只需要id、链接、路径、base64编码中的一个,因此该方法会清空其它的属性
107 * @param base64 音频base64编码
108 */
109 AudioMessage& SetBase64(std::string base64)
110 {
111 this->clear_();
112 this->audio_.base64 = std::move(base64);
113 return *this;
114 }
115
116 /// 由 `MiraiAudio` 设置音频内容
118 {
119 this->audio_ = std::move(audio);
120 return *this;
121 }
122
123 struct Serializable;
124};
125
126template<> struct GetType<AudioMessage::GetType()>
127{
129};
130
131} // namespace Mirai
132
133
134#endif
AudioMessage(MiraiAudio audio)
AudioMessage & SetAudio(MiraiAudio audio)
由 MiraiAudio 设置音频内容
AudioMessage & SetAudioId(std::string AudioId)
设置音频id
AudioMessage & SetBase64(std::string base64)
设置音频内容的base64编码
AudioMessage & SetUrl(std::string url)
设置音频链接
AudioMessage(std::string AudioId, std::string url, std::string path, std::string base64)
AudioMessage & SetPath(std::string path)
设置音频路径
MiraiAudio GetAudio() const
获取消息中的音频内容
AudioMessage()=default
CRTP helper layer
Definition: IMessage.hpp:78
所有mirai相关的对象的命名空间
STL namespace
用于类型之间转换的辅助模板
std::string base64
音频base64编码
Definition: MediaTypes.hpp:266
bool valid() const
检查对象能否用于发送
Definition: MediaTypes.hpp:280
std::string path
音频路径
Definition: MediaTypes.hpp:264
std::string id
音频id,从mirai获得
Definition: MediaTypes.hpp:260
std::string url
音频链接
Definition: MediaTypes.hpp:262