Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit a9c486f

Browse files
authored
Merge pull request #136 from Numendacil/dev/numendacil
1. 添加查询非好友账号信息接口GetUserProfile() 2. 增加商店表情消息MarketFaceMessage 3. 更正MiraiCode.hpp一处字符串乱码 4. 修改了ImageMessage和VoiceMessage的Set()与ToJson()
2 parents 39390fa + a5b996e commit a9c486f

File tree

9 files changed

+121
-12
lines changed

9 files changed

+121
-12
lines changed

CMakePresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"version": 2,
33
"configurePresets": [
44
{

include/mirai/MiraiBot.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22
#ifndef mirai_cpp__mirai_bot_hpp_H_
33
#define mirai_cpp__mirai_bot_hpp_H_
44
// std libraries
@@ -280,6 +280,13 @@ namespace Cyan
280280
*/
281281
Profile GetGroupMemberProfile(const GID_t& gid, const QQ_t& memberQQ);
282282

283+
/**
284+
* @brief 获取QQ用户的个人简介
285+
* @param qq 用户QQ
286+
* @return Profile
287+
*/
288+
Profile GetUserProfile(const QQ_t& qq);
289+
283290
/**
284291
* \brief 设置群成员的群名片
285292
* \param gid 群组(GID_t)

include/mirai/messages/ImageMessage.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ namespace Cyan
6161
{
6262
if (json["type"].is_null() || json["type"].get<string>() != this->GetType())
6363
throw std::runtime_error("给定的json不正确");
64+
65+
imageId_ = "";
66+
url_ = "";
67+
path_ = "";
68+
base64_ = "";
69+
6470
if (!json["imageId"].is_null())
6571
imageId_ = json["imageId"].get<string>();
6672
if (!json["url"].is_null())
@@ -76,10 +82,10 @@ namespace Cyan
7682
return
7783
{
7884
{ "type", GetType() },
79-
{ "imageId", imageId_ },
80-
{ "url", url_ },
81-
{ "path", path_ },
82-
{ "base64", base64_ }
85+
{ "imageId", imageId_.empty()? nullptr : imageId_ },
86+
{ "url", url_.empty()? nullptr : url_ },
87+
{ "path", path_.empty()? nullptr : path_ },
88+
{ "base64", base64_.empty()? nullptr : base64_ }
8389
};
8490
}
8591
virtual ~ImageMessage() {}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#pragma once
2+
#ifndef mirai_cpp_defs_messages_marketface_message_hpp_H_
3+
#define mirai_cpp_defs_messages_marketface_message_hpp_H_
4+
#include <utility>
5+
#include "mirai/defs/IMessage.hpp"
6+
7+
namespace Cyan
8+
{
9+
class MarketFaceMessage : public IMessage
10+
{
11+
public:
12+
MarketFaceMessage() : id_(0), name_() {}
13+
MarketFaceMessage(const int& id) : id_(id), name_() {}
14+
MarketFaceMessage(const string& name) : id_(0), name_(name) {}
15+
template<int N>
16+
MarketFaceMessage(const char(&name)[N]) : id_(0), name_(name,N) {}
17+
MarketFaceMessage(const MarketFaceMessage& m) :id_(m.id_), name_(m.name_) {}
18+
MarketFaceMessage(MarketFaceMessage&& m) noexcept
19+
{
20+
std::swap(this->id_,m.id_);
21+
std::swap(this->name_, m.name_);
22+
}
23+
virtual const string& GetType() const override
24+
{
25+
return type_;
26+
}
27+
virtual bool operator==(const IMessage& m) const override
28+
{
29+
if (auto m_ptr = dynamic_cast<const MarketFaceMessage*>(&m))
30+
{
31+
return m_ptr->id_ == this->id_;
32+
}
33+
return false;
34+
}
35+
virtual bool operator!=(const IMessage& m) const override
36+
{
37+
return !(*this == m);
38+
}
39+
virtual bool Set(const json& json) override
40+
{
41+
if (json["type"].is_null() || json["type"].get<string>() != this->GetType())
42+
throw std::runtime_error("给定的json不正确");
43+
id_ = json["id"].get<int>();
44+
name_ = json["name"].get<string>();
45+
return true;
46+
}
47+
virtual json ToJson() const override
48+
{
49+
return
50+
{
51+
{ "type", type_ },
52+
{ "id", id_ },
53+
{ "name",name_ }
54+
};
55+
}
56+
virtual ~MarketFaceMessage() {}
57+
58+
int FaceId() const { return id_; }
59+
void FaceId(int id) { this->id_ = id; }
60+
61+
string Name() const { return name_; }
62+
void Name(const string& n) { this->name_ = n; }
63+
64+
private:
65+
const string type_ = "MarketFace";
66+
int id_;
67+
string name_;
68+
};
69+
70+
}
71+
#endif
72+

include/mirai/messages/MiraiCode.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace Cyan
3939
virtual bool Set(const json& json) override
4040
{
4141
if (json["type"].is_null() || json["type"].get<string>() != this->GetType())
42-
throw std::runtime_error("¸ø¶¨µÄjson²»ÕýÈ·");
42+
throw std::runtime_error("给定的json不正确");
4343
code_ = json["code"].get<string>();
4444
return true;
4545
}

include/mirai/messages/VoiceMessage.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ namespace Cyan
6363
{
6464
if (json["type"].is_null() || json["type"].get<string>() != this->GetType())
6565
throw std::runtime_error("给定的json不正确");
66+
67+
voiceId_ = "";
68+
url_ = "";
69+
path_ = "";
70+
base64_ = "";
71+
length_ = 0;
72+
6673
if (!json["voiceId"].is_null())
6774
voiceId_ = json["voiceId"].get<string>();
6875
if (!json["url"].is_null())
@@ -80,10 +87,10 @@ namespace Cyan
8087
return
8188
{
8289
{ "type", type_ },
83-
{ "voiceId", voiceId_ },
84-
{ "url", url_ },
85-
{ "path", path_ },
86-
{ "base64", base64_ },
90+
{ "voiceId", voiceId_.empty()? nullptr : voiceId_ },
91+
{ "url", url_.empty()? nullptr : url_ },
92+
{ "path", path_.empty()? nullptr : path_ },
93+
{ "base64", base64_.empty()? nullptr : base64_ },
8794
{ "length", length_ }
8895
};
8996
}

include/mirai/messages/messages.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "mirai/messages/AtAllMessage.hpp"
77
#include "mirai/messages/AtMessage.hpp"
88
#include "mirai/messages/DiceMessage.hpp"
9+
#include "mirai/messages/MarketFaceMessage.hpp"
910
#include "mirai/messages/FaceMessage.hpp"
1011
#include "mirai/messages/FileMessage.hpp"
1112
#include "mirai/messages/FlashImageMessage.hpp"

src/MessageChain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Cyan
1818
reflection.Register<AppMessage>("App");
1919
reflection.Register<JsonMessage>("Json");
2020
reflection.Register<XmlMessage>("Xml");
21+
reflection.Register<MarketFaceMessage>("MarketFace");
2122
reflection.Register<FaceMessage>("Face");
2223
reflection.Register<PokeMessage>("Poke");
2324
reflection.Register<QuoteMessage>("Quote");

src/MiraiBot.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
1+
#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
22

33
#include <iostream>
44
#include <queue>
@@ -650,6 +650,21 @@ namespace Cyan
650650
return result;
651651
}
652652

653+
Profile MiraiBot::GetUserProfile(const QQ_t& qq)
654+
{
655+
stringstream api_url;
656+
api_url
657+
<< "/userProfile?sessionKey="
658+
<< pmem->sessionKey
659+
<< "&target="
660+
<< int64_t(qq);
661+
auto res = pmem->httpClient->Get(api_url.str().data());
662+
json re_json = ParseOrThrowException(res);
663+
Profile result;
664+
result.Set(re_json);
665+
return result;
666+
}
667+
653668
void MiraiBot::SetGroupMemberName(const GID_t& gid, const QQ_t& memberId, const string& name)
654669
{
655670
auto member_info = this->GetGroupMemberInfo(gid, memberId);

0 commit comments

Comments
 (0)