@@ -81,6 +81,15 @@ namespace Cyan
8181 return *this ;
8282 }
8383
84+ template <class T ,class ... Args>
85+ MessageChain& Add (Args&&... args)
86+ {
87+ static_assert (std::is_base_of<IMessage, T>::value, " 只能接受 IMessage 的派生类" );
88+ std::shared_ptr<IMessage> m_ptr (new T (args...));
89+ messages_.push_back (m_ptr);
90+ return *this ;
91+ }
92+
8493 template <class T >
8594 void Remove (const T& m)
8695 {
@@ -109,17 +118,17 @@ namespace Cyan
109118
110119 MessageChain& At (const QQ_t qq)
111120 {
112- return this ->Add ( AtMessage (qq) );
121+ return this ->Add < AtMessage> (qq);
113122 }
114123
115124 MessageChain& AtAll ()
116125 {
117- return this ->Add ( AtAllMessage () );
126+ return this ->Add < AtAllMessage>( );
118127 }
119128
120129 MessageChain& Face (int faceID)
121130 {
122- return this ->Add ( FaceMessage (faceID) );
131+ return this ->Add < FaceMessage> (faceID);
123132 }
124133
125134 MessageChain& Face (const string& name)
@@ -131,45 +140,45 @@ namespace Cyan
131140
132141 MessageChain& Plain (const string& plainText)
133142 {
134- return this ->Add ( PlainMessage (plainText) );
143+ return this ->Add < PlainMessage> (plainText);
135144 }
136145
137146 template <typename T>
138147 MessageChain& Plain (const T& val)
139148 {
140149 std::stringstream ss;
141150 ss << val;
142- return this ->Add ( PlainMessage (ss.str () ));
151+ return this ->Add < PlainMessage> (ss.str ());
143152 }
144153
145154 MessageChain& Image (const MiraiImage& Image)
146155 {
147- return this ->Add ( ImageMessage (Image) );
156+ return this ->Add < ImageMessage> (Image);
148157 }
149158
150159 MessageChain& FlashImage (const MiraiImage& Image)
151160 {
152- return this ->Add ( FlashImageMessage (Image) );
161+ return this ->Add < FlashImageMessage> (Image);
153162 }
154163
155164 MessageChain& Xml (const string& xml_str)
156165 {
157- return this ->Add ( XmlMessage (xml_str) );
166+ return this ->Add < XmlMessage> (xml_str);
158167 }
159168
160169 MessageChain& Json (const string& json_str)
161170 {
162- return this ->Add ( JsonMessage (json_str) );
171+ return this ->Add < JsonMessage> (json_str);
163172 }
164173
165174 MessageChain& App (const string& app_str)
166175 {
167- return this ->Add ( AppMessage (app_str) );
176+ return this ->Add < AppMessage> (app_str);
168177 }
169178
170179 MessageChain& Poke (PokeType poke)
171180 {
172- return this ->Add ( PokeMessage (poke) );
181+ return this ->Add < PokeMessage> (poke);
173182 }
174183
175184 string GetPlainText () const ;
0 commit comments