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

Commit 9661c4b

Browse files
committed
支持获取、删除群公告;
1 parent 30ef546 commit 9661c4b

File tree

6 files changed

+153
-1
lines changed

6 files changed

+153
-1
lines changed

examples/RepeatMessage.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ int main(int argc, char* argv[])
5353

5454
cout << "Bot Working..." << endl;
5555

56+
auto result = bot.GetGroupAnnouncement(767473146_gid);
57+
for (auto&& item : result)
58+
{
59+
cout << item.Content << endl;
60+
}
61+
5662
bot.On<Message>(
5763
[&](Message m)
5864
{

include/mirai/MiraiBot.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,28 @@ namespace Cyan
380380
*/
381381
void SetGroupConfig(const GID_t& group, const GroupConfig& groupConfig);
382382

383+
/**
384+
* @brief 获取群公告
385+
* @param group 群(GID_t)
386+
* @param offset 分页偏移
387+
* @param size 分页大小
388+
* @return std::vector<Announcement>
389+
*/
390+
std::vector<GroupAnnouncement> GetGroupAnnouncement(const GID_t& group, int offset = 0, int size = 10);
391+
392+
/**
393+
* @brief 删除群公告
394+
* @param group 群(GID_t)
395+
* @param announcementId 群公告ID
396+
*/
397+
void DeleteGroupAnnoencement(const GID_t& group, const string& announcementId);
398+
399+
/**
400+
* @brief 删除群公告
401+
* @param announcement 群公告对象
402+
*/
403+
void DeleteGroupAnnoencement(const GroupAnnouncement& announcement);
404+
383405
/**
384406
* \brief 根据消息ID(MessageId)获取对应的好友消息
385407
* \param mid 消息ID(MessageId)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#pragma once
2+
#ifndef mirai_cpp_defs_Announcement_hpp_H_
3+
#define mirai_cpp_defs_Announcement_hpp_H_
4+
5+
#include "mirai/third-party/nlohmann/json.hpp"
6+
#include "mirai/defs/QQType.hpp"
7+
#include "mirai/defs/Group.hpp"
8+
#include "ISerializable.hpp"
9+
10+
namespace Cyan
11+
{
12+
/**
13+
* @brief 群通告
14+
*/
15+
class GroupAnnouncement : public ISerializable
16+
{
17+
public:
18+
/**
19+
* @brief 群组
20+
*/
21+
Group_t Group;
22+
23+
/**
24+
* @brief 群公告内容
25+
*/
26+
string Content;
27+
28+
/**
29+
* @brief 发送者 QQ
30+
*/
31+
QQ_t SenderQQ;
32+
33+
/**
34+
* @brief 群公告唯一Id
35+
*/
36+
string AnnouncementId;
37+
38+
/**
39+
* @brief 是否所有群成员已确认
40+
*/
41+
bool AllConfirmed;
42+
43+
/**
44+
* @brief 已经确认的人数
45+
*/
46+
int ConfirmedMembersCount;
47+
48+
/**
49+
* @brief 发布时间
50+
*/
51+
int64_t PublicationTime;
52+
53+
virtual bool Set(const json& j) override
54+
{
55+
Group.Set(j["group"]);
56+
Content = j["content"].get<string>();
57+
SenderQQ = (QQ_t)j["senderId"].get<int64_t>();
58+
AnnouncementId = j["fid"].get<string>();
59+
AllConfirmed = j["allConfirmed"].get<bool>();
60+
ConfirmedMembersCount = j["confirmedMembersCount"].get<int>();
61+
PublicationTime = j["publicationTime"].get<int64_t>();
62+
return true;
63+
}
64+
virtual json ToJson() const override
65+
{
66+
return
67+
{
68+
{ "group", Group.ToJson() },
69+
{ "content", Content },
70+
{ "senderId", SenderQQ.ToInt64() },
71+
{ "fid", AnnouncementId },
72+
{ "allConfirmed", AllConfirmed },
73+
{ "confirmedMembersCount", ConfirmedMembersCount },
74+
{ "publicationTime", PublicationTime }
75+
};
76+
}
77+
};
78+
79+
}
80+
81+
#endif

include/mirai/defs/GroupFile.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace Cyan
5757

5858
virtual bool Set(const json& j) override
5959
{
60-
Size = j["size"].get<int64_t>();
60+
Size = j["size"].get<int>();
6161
Name = j["name"].get<string>();
6262
Id = j["id"].get<string>();
6363
Path = j["path"].get<string>();

include/mirai/defs/defs.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
#include "MessageChain.hpp"
1313
#include "Profile.hpp"
1414
#include "FileDownloadInfo.hpp"
15+
#include "GroupAnnouncement.hpp"
1516

1617
#endif // !mirai_cpp_defs_defs_hpp_H_

src/MiraiBot.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,48 @@ namespace Cyan
890890
ParseOrThrowException(res);
891891
}
892892

893+
std::vector<GroupAnnouncement> MiraiBot::GetGroupAnnouncement(const GID_t& group, int offset, int size)
894+
{
895+
stringstream api_url;
896+
api_url
897+
<< "/anno/list?sessionKey="
898+
<< pmem->sessionKey
899+
<< "&id="
900+
<< int64_t(group)
901+
<< "&offset="
902+
<< offset
903+
<< "&size="
904+
<< size;
905+
auto res = pmem->httpClient->Get(api_url.str().data());
906+
json re_json = ParseOrThrowException(res);
907+
vector<GroupAnnouncement> result;
908+
for (const auto& item : re_json["data"])
909+
{
910+
GroupAnnouncement tmp;
911+
tmp.Set(item);
912+
result.emplace_back(std::move(tmp));
913+
}
914+
return result;
915+
}
916+
917+
void MiraiBot::DeleteGroupAnnoencement(const GID_t& group, const string& announcementId)
918+
{
919+
json data =
920+
{
921+
{ "sessionKey", pmem->sessionKey },
922+
{ "id", int64_t(group) },
923+
{ "fid", announcementId }
924+
};
925+
926+
auto res = pmem->httpClient->Post("/anno/delete", data.dump(), CONTENT_TYPE.c_str());
927+
ParseOrThrowException(res);
928+
}
929+
930+
void MiraiBot::DeleteGroupAnnoencement(const GroupAnnouncement& announcement)
931+
{
932+
return DeleteGroupAnnoencement(announcement.Group.GID, announcement.AnnouncementId);
933+
}
934+
893935
GroupConfig MiraiBot::GetGroupConfig(const GID_t& group)
894936
{
895937
stringstream api_url;

0 commit comments

Comments
 (0)