cpp-mirai-client  v2.6.1
cpp client for mirai-api-http
CommandExecutedEvent.hpp
浏览该文件的文档.
1// Copyright (C) 2022 Numendacil and contributors
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU Affero General Public License as
5// published by the Free Software Foundation, either version 3 of the
6// License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU Affero General Public License for more details.
12//
13// You should have received a copy of the GNU Affero General Public License
14// along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16#ifndef MIRAI_COMMAND_EXECUTED_EVENT_HPP_
17#define MIRAI_COMMAND_EXECUTED_EVENT_HPP_
18
19#include <optional>
20#include <string>
21
24
25#include "IEvent.hpp"
26
27namespace Mirai
28{
29
30/**
31 * @brief 命令执行事件
32 *
33 * Member Variable | Default Value
34 * --------------- | -------------
35 * `CommandExecutedEvent::sender_` | `""`
36 * `CommandExecutedEvent::friend_` | `std::nullopt`
37 * `CommandExecutedEvent::member_` | `std::nullopt`
38 * `CommandExecutedEvent::args_` | `MessageChain{}`
39 */
40class CommandExecutedEvent final : public IEvent<CommandExecutedEvent>
41{
43private:
44 std::string name_;
45 std::optional<User> friend_ = std::nullopt;
46 std::optional<GroupMember> member_ = std::nullopt;
47 MessageChain args_;
48
49 static constexpr EventTypes TYPE_ = EventTypes::CommandExecuted;
50
51public:
52 /// 获取命令名称(不含前缀 `/` )
53 std::string GetName() const { return this->name_; }
54 /// 获取发送者类型
56 {
57 return this->friend_ ? CommandSender::FRIEND : (this->member_ ? CommandSender::MEMBER : CommandSender::CONSOLE);
58 }
59 /// 获取好友发送者QQ,非好友发送时返回 `std::nullopt`
60 std::optional<User> GetFriendSender() const { return this->friend_; }
61 /// 获取群成员发送者资料,非群聊发送时返回 `std::nullopt`
62 std::optional<GroupMember> GetMemberSender() const { return this->member_; }
63 /// 获取命令参数内容
64 MessageChain GetCommandArgs() const { return this->args_; }
65
66 struct Serializable;
67};
68
69template<>
71{
73};
74
75} // namespace Mirai
76
77
78#endif
std::string GetName() const
获取命令名称(不含前缀 / )
CommandSender GetSenderType() const
获取发送者类型
MessageChain GetCommandArgs() const
获取命令参数内容
std::optional< GroupMember > GetMemberSender() const
获取群成员发送者资料,非群聊发送时返回 std::nullopt
std::optional< User > GetFriendSender() const
获取好友发送者QQ,非好友发送时返回 std::nullopt
Common interface for all event types
Definition: IEvent.hpp:34
消息链对象,由一系列消息元素组成
所有mirai相关的对象的命名空间
CommandSender
指令发送者类型
Definition: BasicTypes.hpp:287
用于类型之间转换的辅助模板
Definition: EventTypes.hpp:107
用于类型之间转换的辅助模板