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

Commit 9486069

Browse files
committed
支持群名称改变事件;
1 parent ec91582 commit 9486069

File tree

5 files changed

+108
-2
lines changed

5 files changed

+108
-2
lines changed

examples/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ api_exe(RecallEvent)
2727
api_exe(MessageType)
2828
api_exe(FetchEventsViaHTTP)
2929
api_exe(CompareMessage)
30-
api_exe(GroupMemberInfo)
30+
api_exe(GroupMemberInfo)
31+
api_exe(GroupNameChange)

examples/GroupNameChange.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <iostream>
2+
#include <ctime>
3+
// 使用静态库必须要在引入 mirai.h 前定义这个宏
4+
#define MIRAICPP_STATICLIB
5+
#include <mirai.h>
6+
7+
int main()
8+
{
9+
using namespace std;
10+
using namespace Cyan;
11+
system("chcp 65001");
12+
MiraiBot bot("127.0.0.1", 539);
13+
while (true)
14+
{
15+
try
16+
{
17+
bot.Auth("INITKEY7A3O1a9v", 1589588851_qq);
18+
break;
19+
}
20+
catch (const std::exception& ex)
21+
{
22+
cout << ex.what() << endl;
23+
}
24+
MiraiBot::SleepSeconds(1);
25+
}
26+
cout << "成功登录 bot。" << endl;
27+
28+
bot.On<GroupNameChangeEvent>(
29+
[&](GroupNameChangeEvent e)
30+
{
31+
cout << e.OriginName << ", " << e.CurrentName << endl;
32+
});
33+
34+
bot.EventLoop();
35+
return 0;
36+
}

include/events/events.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "bot_join_group.hpp"
2929
#include "bot_leave_active.hpp"
3030
#include "bot_leave_kick.hpp"
31+
#include "group_name_change.hpp"
3132
// 一些定义
3233
#include "event_processer.hpp"
3334
#include "events_name.hpp"

include/events/events_name.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Cyan
2222
BotMuteEvent, // Bot被禁言
2323
BotUnmuteEvent, // Bot被取消禁言
2424
BotJoinGroupEvent, // Bot加入了一个新群
25-
GroupNameChangeEvent, // TODO:某个群名称改变
25+
GroupNameChangeEvent, // 某个群名称改变
2626
GroupMuteAllEvent, // 群全员禁言
2727
MemberJoinEvent, // 新人入群事件
2828
MemberLeaveEventKick, // 成员被踢出群(该成员不是Bot)
@@ -59,6 +59,7 @@ namespace Cyan
5959
if (miraiEvent == "BotJoinGroupEvent") return MiraiEvent::BotJoinGroupEvent;
6060
if (miraiEvent == "BotLeaveEventActive") return MiraiEvent::BotLeaveEventActive;
6161
if (miraiEvent == "BotLeaveEventKick") return MiraiEvent::BotLeaveEventKick;
62+
if (miraiEvent == "GroupNameChangeEvent") return MiraiEvent::GroupNameChangeEvent;
6263
return MiraiEvent::Default;
6364
}
6465

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#pragma once
2+
#ifndef mirai_cpp_events_group_name_change_hpp_H_
3+
#define mirai_cpp_events_group_name_change_hpp_H_
4+
5+
#include <nlohmann/json.hpp>
6+
#include "defs/qq_types.hpp"
7+
#include "defs/group.hpp"
8+
#include "defs/group_member.hpp"
9+
#include "event_interface.hpp"
10+
11+
namespace Cyan
12+
{
13+
// 群名称被改变
14+
class GroupNameChangeEvent : public EventBase
15+
{
16+
public:
17+
string OriginName;
18+
string CurrentName;
19+
Group_t Group;
20+
GroupMember_t Operator;
21+
22+
static MiraiEvent GetMiraiEvent()
23+
{
24+
return MiraiEvent::GroupNameChangeEvent;
25+
}
26+
27+
virtual void SetMiraiBot(MiraiBot* bot) override
28+
{
29+
this->bot_ = bot;
30+
}
31+
32+
bool OperatorIsBot() const
33+
{
34+
return operator_is_null_;
35+
}
36+
37+
virtual bool Set(const json& j) override
38+
{
39+
this->OriginName = j["origin"].get<string>();
40+
this->CurrentName = j["current"].get<string>();
41+
this->Group.Set(j["group"]);
42+
if (!j["operator"].is_null())
43+
{
44+
this->Operator.Set(j["operator"]);
45+
this->operator_is_null_ = false;
46+
}
47+
return true;
48+
}
49+
virtual json ToJson() const override
50+
{
51+
json j = json::object();
52+
j["type"] = "GroupNameChangeEvent";
53+
j["origin"] = this->OriginName;
54+
j["current"] = this->CurrentName;
55+
j["group"] = this->Group.ToJson();
56+
j["operator"] = this->Operator.ToJson();
57+
return j;
58+
}
59+
60+
private:
61+
MiraiBot* bot_;
62+
bool operator_is_null_ = true;
63+
};
64+
65+
}
66+
67+
#endif // !mirai_cpp_events_group_name_change_hpp_H_

0 commit comments

Comments
 (0)