This repository was archived by the owner on Aug 16, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed
Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,13 @@ int main()
4949 for (const auto & arg : e.Args )
5050 cout << arg << " " ;
5151 cout << endl;
52+
53+ // 检查指令的发送者是不是 Manager
54+ if (e.SenderIsManager ())
55+ {
56+ bot.SendMessage (e.GroupId , MessageChain ().Plain (" 执行指令: " ).Plain (e.CommandName ));
57+ }
58+
5259 });
5360
5461 // 发送指令
Original file line number Diff line number Diff line change 44
55#include < string>
66#include < vector>
7+ #include " mirai/exported.h"
78#include " mirai/third-party/nlohmann/json.hpp"
89#include " mirai/defs/qq_types.hpp"
910#include " event_interface.hpp"
@@ -16,7 +17,7 @@ namespace Cyan
1617 /* *
1718 * \brief 指令事件
1819 */
19- class Command : public EventBase
20+ class EXPORTED Command : public EventBase
2021 {
2122 public:
2223 string CommandName;
@@ -29,6 +30,12 @@ namespace Cyan
2930 return MiraiEvent::Command;
3031 }
3132
33+ /* *
34+ * @brief 检查发送指令的人是不是 Manager (控制台的指令也返回true)
35+ * @return 是否为Manager
36+ */
37+ bool SenderIsManager ();
38+
3239 virtual bool Set (const json& j) override
3340 {
3441 CommandName = j[" name" ].get <string>();
Original file line number Diff line number Diff line change @@ -137,4 +137,14 @@ namespace Cyan
137137 }
138138 }
139139
140+ bool Command::SenderIsManager ()
141+ {
142+ // 控制台发来的指令,算作是Manager
143+ if (this ->Sender .ToInt64 () == 0 ) return true ;
144+ vector<QQ_t> managers = this ->GetMiraiBot ().GetManagers ();
145+ auto it = std::find_if (managers.begin (), managers.end (),
146+ [&](QQ_t q) { return q.ToInt64 () == this ->Sender .ToInt64 (); });
147+ return it != managers.end ();
148+ }
149+
140150}
You can’t perform that action at this time.
0 commit comments