cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
ForwardMessage.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_FORWARD_MESSAGE_HPP_
17#define MIRAI_FORWARD_MESSAGE_HPP_
18
19#include <ctime>
20#include <optional>
21#include <utility>
22#include <vector>
23
25
26#include "IMessage.hpp"
27
28namespace Mirai
29{
30
31/**
32 * @brief 合并转发消息
33 *
34 * 可以使用类似于STL容器的方式访问各元素
35 *
36 * Member Variable | Default Value
37 * --------------- | -------------
38 * `ForwardMessage::NodeList_` | `{}`
39 * `ForwardMessage::title_` | `std::nullopt`
40 * `ForwardMessage::brief_` | `std::nullopt`
41 * `ForwardMessage::source_` | `std::nullopt`
42 * `ForwardMessage::preview_` | `std::nullopt`
43 * `ForwardMessage::summary_` | `std::nullopt`
44 */
45class ForwardMessage final: public IMessageImpl<ForwardMessage>
46{
48
49public:
50 class Node;
51
52protected:
53 using NodeList = std::vector<Node>;
55
56 std::optional<std::string> title_;
57 std::optional<std::string> brief_;
58 std::optional<std::string> source_;
59 std::optional<std::vector<std::string>> preview_;
60 std::optional<std::string> summary_;
61
63 static constexpr bool SUPPORT_SEND_ = true;
64
65 bool isValid_() const final;
66
67public:
70 ForwardMessage& operator= (const ForwardMessage&);
74
75 /// 获取合并转发消息的标题("xxx的聊天记录"),为空代表默认值
76 std::optional<std::string> GetDisplayTitle() const
77 {
78 return this->title_;
79 }
80
81 /// 获取合并转发消息的简略信息("[聊天记录]"),为空代表默认值
82 std::optional<std::string> GetDisplayBrief() const
83 {
84 return this->brief_;
85 }
86
87 /// 获取合并转发消息的来源显示("聊天记录"),为空代表默认值
88 std::optional<std::string> GetDisplaySource() const
89 {
90 return this->source_;
91 }
92
93 /// 获取合并转发消息的内容预览,为空代表默认值
94 std::optional<std::vector<std::string>> GetDisplayPreview() const
95 {
96 return this->preview_;
97 }
98
99 /// 获取合并转发消息的内容总结("查看x条转发消息"),为空代表默认值
100 std::optional<std::string> GetDisplaySummary() const
101 {
102 return this->summary_;
103 }
104
105
106 /// 设置合并转发消息的标题("xxx的聊天记录")
107 void SetDisplayTitle(std::string title)
108 {
109 this->title_ = std::move(title);
110 }
111
112 /// 设置合并转发消息的简略信息("[聊天记录]")
113 void SetDisplayBrief(std::string brief)
114 {
115 this->brief_ = std::move(brief);
116 }
117
118 /// 设置合并转发消息的来源显示("聊天记录")
119 void SetDisplaySource(std::string source)
120 {
121 this->source_ = std::move(source);
122 }
123
124 /// 设置合并转发消息的内容预览
125 void SetDisplayPreview(std::vector<std::string> preview)
126 {
127 this->preview_ = std::move(preview);
128 }
129
130 /// 设置合并转发消息的内容总结("查看x条转发消息")
131 void SetDisplaySummary(std::string summary)
132 {
133 this->summary_ = std::move(summary);
134 }
135
136
137 /**
138 * @brief STL-like interface
139 *
140 */
141 ///@{
142
143 // I hate this
144
145 using value_type = NodeList::value_type;
146 using allocator_type = NodeList::allocator_type;
147 using size_type = NodeList::size_type;
148 using difference_type = NodeList::difference_type;
149 using reference = NodeList::reference;
150 using const_reference = NodeList::const_reference;
151 using pointer = NodeList::pointer;
152 using const_pointer = NodeList::const_pointer;
153 using reverse_iterator = NodeList::reverse_iterator;
154 using const_reverse_iterator = NodeList::const_reverse_iterator;
155 using iterator = NodeList::iterator;
156 using const_iterator = NodeList::const_iterator;
157
158 bool empty() const noexcept;
159 size_type size() const noexcept;
160 void reserve(size_type new_cap);
161 void shrink_to_fit() noexcept;
162 size_type max_size() const noexcept;
163 size_type capacity() const noexcept;
164
167 const_reference operator[](size_type n) const noexcept;
168 reference operator[](size_type n) noexcept;
169 const_reference back() const;
170 reference back();
171 const_reference front() const;
173
174 void clear() noexcept;
178 template<class InputIt> iterator insert(const_iterator pos, InputIt first, InputIt last)
179 {
180 return this->NodeList_.insert(pos, std::forward<InputIt>(first), std::forward<InputIt>(last));
181 }
182 iterator insert(const_iterator pos, std::initializer_list<value_type> ilist);
183 template<class... Args > iterator emplace(const_iterator pos, Args&&... args)
184 {
185 return this->NodeList_.emplace(pos, std::forward<Args>(args)...);
186 }
189 void push_back(const_reference node);
190 void push_back(value_type&& node);
191 template< class... Args > reference emplace_back(Args&&... args)
192 {
193 return this->NodeList_.emplace_back(std::forward<Args>(args)...);
194 }
195 void pop_back();
196 void resize(size_type count);
197 void resize(size_type count, const value_type& value);
198
199 iterator begin() noexcept;
200 const_iterator begin() const noexcept;
201 const_iterator cbegin() const noexcept;
202 iterator end() noexcept;
203 const_iterator end() const noexcept;
204 const_iterator cend() const noexcept;
205 reverse_iterator rbegin() noexcept;
206 const_reverse_iterator crbegin() const noexcept;
207 reverse_iterator rend() noexcept;
208 const_reverse_iterator crend() const noexcept;
209
210 ///@}
211
212 struct Serializable;
213};
214
216
217template<> struct GetType<ForwardMessage::GetType()>
218{
220};
221
222} // namespace Mirai
223
224
225#endif
转发消息节点,代表一条转发消息
合并转发消息
std::optional< std::string > GetDisplayTitle() const
获取合并转发消息的标题("xxx的聊天记录"),为空代表默认值
size_type size() const noexcept
STL-like interface
NodeList::const_reference const_reference
STL-like interface
size_type capacity() const noexcept
STL-like interface
iterator insert(const_iterator pos, const_reference value)
STL-like interface
iterator begin() noexcept
STL-like interface
void SetDisplaySource(std::string source)
设置合并转发消息的来源显示("聊天记录")
void pop_back()
STL-like interface
const_iterator cend() const noexcept
STL-like interface
void push_back(const_reference node)
STL-like interface
NodeList::pointer pointer
STL-like interface
reverse_iterator rend() noexcept
STL-like interface
void shrink_to_fit() noexcept
STL-like interface
void SetDisplaySummary(std::string summary)
设置合并转发消息的内容总结("查看x条转发消息")
NodeList::iterator iterator
STL-like interface
std::optional< std::string > source_
bool empty() const noexcept
STL-like interface
NodeList::allocator_type allocator_type
STL-like interface
const_reverse_iterator crbegin() const noexcept
STL-like interface
NodeList::const_pointer const_pointer
STL-like interface
void resize(size_type count)
STL-like interface
static constexpr MessageTypes TYPE_
void SetDisplayTitle(std::string title)
设置合并转发消息的标题("xxx的聊天记录")
const_reference front() const
STL-like interface
const_reference at(size_type n) const
STL-like interface
std::optional< std::string > GetDisplaySource() const
获取合并转发消息的来源显示("聊天记录"),为空代表默认值
size_type max_size() const noexcept
STL-like interface
iterator erase(const_iterator pos)
STL-like interface
std::optional< std::string > summary_
static constexpr bool SUPPORT_SEND_
const_iterator cbegin() const noexcept
STL-like interface
std::optional< std::vector< std::string > > preview_
std::optional< std::string > brief_
bool isValid_() const final
void SetDisplayBrief(std::string brief)
设置合并转发消息的简略信息("[聊天记录]")
std::optional< std::string > title_
NodeList::const_iterator const_iterator
STL-like interface
std::optional< std::vector< std::string > > GetDisplayPreview() const
获取合并转发消息的内容预览,为空代表默认值
void reserve(size_type new_cap)
STL-like interface
NodeList::value_type value_type
STL-like interface
NodeList::size_type size_type
STL-like interface
NodeList::difference_type difference_type
STL-like interface
std::optional< std::string > GetDisplayBrief() const
获取合并转发消息的简略信息("[聊天记录]"),为空代表默认值
NodeList::reverse_iterator reverse_iterator
STL-like interface
iterator emplace(const_iterator pos, Args &&... args)
STL-like interface
void SetDisplayPreview(std::vector< std::string > preview)
设置合并转发消息的内容预览
reverse_iterator rbegin() noexcept
STL-like interface
const_reference back() const
STL-like interface
std::vector< Node > NodeList
void clear() noexcept
STL-like interface
reference emplace_back(Args &&... args)
STL-like interface
std::optional< std::string > GetDisplaySummary() const
获取合并转发消息的内容总结("查看x条转发消息"),为空代表默认值
const_reverse_iterator crend() const noexcept
STL-like interface
iterator end() noexcept
STL-like interface
NodeList::reference reference
STL-like interface
NodeList::const_reverse_iterator const_reverse_iterator
STL-like interface
CRTP helper layer
Definition: IMessage.hpp:78
所有mirai相关的对象的命名空间
STL namespace
用于类型之间转换的辅助模板