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

Commit 8208970

Browse files
authored
Merge pull request #39 from cyanray/dev/cyanray
新增: Command.SenderIsManager();
2 parents a9d1a19 + 4f6336a commit 8208970

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

examples/Command.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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
// 发送指令

include/mirai/events/command_event.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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>();

src/event_func.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)