@@ -255,6 +255,31 @@ namespace Cyan
255255 }
256256
257257
258+ MiraiVoice MiraiBot::UploadGroupVoice (const string& filename)
259+ {
260+ string voice_data = ReadFile (filename);
261+ httplib::MultipartFormDataItems items =
262+ {
263+ { " sessionKey" , sessionKey_, " " , " " },
264+ { " type" , " group" , " " , " " },
265+ { " voice" , voice_data, std::to_string (rand ()) + " .amr" , " application/octet-stream" }
266+ };
267+
268+ auto res = http_client_.Post (" /uploadVoice" , items);
269+
270+ if (!res)
271+ throw runtime_error (" 网络错误" );
272+ if (res->status != 200 )
273+ throw std::runtime_error (" [mirai-http-api error]: " + res->body );
274+ json re_json = json::parse (res->body );
275+ MiraiVoice result;
276+ result.Id = re_json[" voiceId" ].get <string>();
277+ if (!re_json[" url" ].is_null ())
278+ result.Url = re_json[" url" ].get <string>();
279+ result.Path = re_json[" path" ].get <string>();
280+ return result;
281+ }
282+
258283 vector<Friend_t> MiraiBot::GetFriendList ()
259284 {
260285 auto res = http_client_.Get ((" /friendList?sessionKey=" + sessionKey_).data ());
@@ -628,9 +653,9 @@ namespace Cyan
628653 }
629654
630655 MiraiBot& MiraiBot::RegisterCommand (
631- const string& commandName,
632- const vector<string> alias,
633- const string& description,
656+ const string& commandName,
657+ const vector<string> alias,
658+ const string& description,
634659 const string& helpMessage)
635660 {
636661 json data =
0 commit comments