This repository was archived by the owner on Aug 16, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 15 files changed +440
-4
lines changed
Expand file tree Collapse file tree 15 files changed +440
-4
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,20 @@ int main()
3737 MessageChain ().Plain (" 👴 出狱了!" ));
3838 });
3939
40+ bot.On <BotJoinGroupEvent>(
41+ [&](BotJoinGroupEvent e)
42+ {
43+ MiraiBot::SleepSeconds (5 );
44+ bot.SendMessage (e.Group .GID , MessageChain ().Plain (" 👴 进群了!都来欢迎 👴!" ));
45+ });
46+
47+ // 似乎没有效果
48+ bot.On <BotLeaveEventKick>(
49+ [&](BotLeaveEventKick e)
50+ {
51+ cout << " 👴被踢出群了: " << int64_t (e.Group .GID ) << endl;
52+ });
53+
4054 bot.On <BotOnlineEvent>(
4155 [&](BotOnlineEvent e)
4256 {
Original file line number Diff line number Diff line change @@ -27,4 +27,6 @@ api_exe(RecallEvent)
2727api_exe(MessageType)
2828api_exe(FetchEventsViaHTTP)
2929api_exe(CompareMessage)
30- api_exe(GroupMemberInfo)
30+ api_exe(GroupMemberInfo)
31+ api_exe(GroupNameChange)
32+ api_exe(GroupConfig)
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ // 使用静态库必须要在引入 mirai.h 前定义这个宏
3+ #define MIRAICPP_STATICLIB
4+ #include < mirai.h>
5+
6+ int main ()
7+ {
8+ using namespace std ;
9+ using namespace Cyan ;
10+ system (" chcp 65001" );
11+ MiraiBot bot (" 127.0.0.1" , 539 );
12+ while (true )
13+ {
14+ try
15+ {
16+ bot.Auth (" INITKEY7A3O1a9v" , 1589588851_qq);
17+ break ;
18+ }
19+ catch (const std::exception& ex)
20+ {
21+ cout << ex.what () << endl;
22+ }
23+ MiraiBot::SleepSeconds (1 );
24+ }
25+ cout << " 成功登录 bot。" << endl;
26+
27+
28+ GroupConfig group_config = bot.GetGroupConfig (1029259687_gid);
29+
30+ group_config.Name = " New Name 2" ;
31+
32+ bot.SetGroupConfig (1029259687_gid, group_config);
33+
34+ cout << group_config.Name << endl;
35+
36+
37+ bot.EventLoop ();
38+
39+
40+ return 0 ;
41+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1010#include " group_member.hpp"
1111#include " message_chain.hpp"
1212#include " group_member_info.hpp"
13+ #include " group_config.hpp"
1314
1415#endif // !mirai_cpp_defs_defs_hpp_H_
Original file line number Diff line number Diff line change 1+ #pragma once
2+ #ifndef mirai_cpp_defs_group_config_hpp_H_
3+ #define mirai_cpp_defs_group_config_hpp_H_
4+
5+ #include < nlohmann/json.hpp>
6+ #include " serializable.hpp"
7+
8+ namespace Cyan
9+ {
10+ // ȺÉèÖÃ
11+ class GroupConfig : public Serializable
12+ {
13+ public:
14+ string Name;
15+ string Announcement;
16+ bool ConfessTalk;
17+ bool AllowMemberInvite;
18+ bool AutoApprove;
19+ bool AnonymousChat;
20+ virtual bool Set (const json& j) override
21+ {
22+ Name = j[" name" ].get <string>();
23+ Announcement = j[" announcement" ].get <string>();
24+ ConfessTalk = j[" confessTalk" ].get <bool >();
25+ AllowMemberInvite = j[" allowMemberInvite" ].get <bool >();
26+ AutoApprove = j[" autoApprove" ].get <bool >();
27+ AnonymousChat = j[" anonymousChat" ].get <bool >();
28+ return true ;
29+ }
30+ virtual json ToJson () const override
31+ {
32+ json j = json::object ();
33+ j[" name" ] = Name;
34+ j[" announcement" ] = Announcement;
35+ j[" confessTalk" ] = ConfessTalk;
36+ j[" allowMemberInvite" ] = AllowMemberInvite;
37+ j[" autoApprove" ] = AutoApprove;
38+ j[" anonymousChat" ] = AnonymousChat;
39+ return j;
40+ }
41+ };
42+
43+ }
44+
45+ #endif // !mirai_cpp_defs_group_config_hpp_H_
Original file line number Diff line number Diff line change 1+ #pragma once
2+ #ifndef mirai_cpp_events_bot_join_group_hpp_H_
3+ #define mirai_cpp_events_bot_join_group_hpp_H_
4+
5+ #include < nlohmann/json.hpp>
6+ #include " defs/qq_types.hpp"
7+ #include " defs/group.hpp"
8+ #include " event_interface.hpp"
9+
10+ namespace Cyan
11+ {
12+ // bot 加入新群事件
13+ class BotJoinGroupEvent : public EventBase
14+ {
15+ public:
16+ Group_t Group;
17+
18+ static MiraiEvent GetMiraiEvent ()
19+ {
20+ return MiraiEvent::BotJoinGroupEvent;
21+ }
22+
23+ virtual void SetMiraiBot (MiraiBot* bot) override
24+ {
25+ this ->bot_ = bot;
26+ }
27+
28+ virtual bool Set (const json& j) override
29+ {
30+ this ->Group .Set (j[" group" ]);
31+ return true ;
32+ }
33+ virtual json ToJson () const override
34+ {
35+ json j = json::object ();
36+ j[" type" ] = " BotJoinGroupEvent" ;
37+ j[" group" ] = this ->Group .ToJson ();
38+ return j;
39+ }
40+
41+ private:
42+ MiraiBot* bot_;
43+ };
44+
45+ }
46+
47+ #endif // !mirai_cpp_events_bot_join_group_hpp_H_
Original file line number Diff line number Diff line change 1+ #pragma once
2+ #ifndef mirai_cpp_events_bot_leave_active_hpp_H_
3+ #define mirai_cpp_events_bot_leave_active_hpp_H_
4+
5+ #include < nlohmann/json.hpp>
6+ #include " defs/qq_types.hpp"
7+ #include " defs/group.hpp"
8+ #include " event_interface.hpp"
9+
10+ namespace Cyan
11+ {
12+ // bot 主动退群
13+ class BotLeaveEventActive : public EventBase
14+ {
15+ public:
16+ Group_t Group;
17+
18+ static MiraiEvent GetMiraiEvent ()
19+ {
20+ return MiraiEvent::BotLeaveEventActive;
21+ }
22+
23+ virtual void SetMiraiBot (MiraiBot* bot) override
24+ {
25+ this ->bot_ = bot;
26+ }
27+
28+ virtual bool Set (const json& j) override
29+ {
30+ this ->Group .Set (j[" group" ]);
31+ return true ;
32+ }
33+ virtual json ToJson () const override
34+ {
35+ json j = json::object ();
36+ j[" type" ] = " BotLeaveEventActive" ;
37+ j[" group" ] = this ->Group .ToJson ();
38+ return j;
39+ }
40+
41+ private:
42+ MiraiBot* bot_;
43+ };
44+
45+ }
46+
47+ #endif // !mirai_cpp_events_bot_leave_active_hpp_H_
Original file line number Diff line number Diff line change 1+ #pragma once
2+ #ifndef mirai_cpp_events_bot_leave_kick_hpp_H_
3+ #define mirai_cpp_events_bot_leave_kick_hpp_H_
4+
5+ #include < nlohmann/json.hpp>
6+ #include " defs/qq_types.hpp"
7+ #include " defs/group.hpp"
8+ #include " event_interface.hpp"
9+
10+ namespace Cyan
11+ {
12+ // bot 被踢出群
13+ class BotLeaveEventKick : public EventBase
14+ {
15+ public:
16+ Group_t Group;
17+
18+ static MiraiEvent GetMiraiEvent ()
19+ {
20+ return MiraiEvent::BotLeaveEventKick;
21+ }
22+
23+ virtual void SetMiraiBot (MiraiBot* bot) override
24+ {
25+ this ->bot_ = bot;
26+ }
27+
28+ virtual bool Set (const json& j) override
29+ {
30+ this ->Group .Set (j[" group" ]);
31+ return true ;
32+ }
33+ virtual json ToJson () const override
34+ {
35+ json j = json::object ();
36+ j[" type" ] = " BotLeaveEventKick" ;
37+ j[" group" ] = this ->Group .ToJson ();
38+ return j;
39+ }
40+
41+ private:
42+ MiraiBot* bot_;
43+ };
44+
45+ }
46+
47+ #endif // !mirai_cpp_events_bot_leave_kick_hpp_H_
Original file line number Diff line number Diff line change 44
55#include < nlohmann/json.hpp>
66#include " defs/qq_types.hpp"
7- #include " defs/serializable.hpp"
8- #include " defs/message_chain.hpp"
97#include " defs/group_member.hpp"
108#include " event_interface.hpp"
119
You can’t perform that action at this time.
0 commit comments