1 #ifndef CPPGRAM_MESSAGE_COMMAND_HPP 2 #define CPPGRAM_MESSAGE_COMMAND_HPP 5 #include "cppgram/types/update.hpp" 20 typedef std::function<void( T &, const types::Message & )> MessageClosure;
29 : command(
"/" + command )
40 virtual void callClosure( T &bot,
const types::Update &update )
42 bot.setChatId( update.message->chat.id );
43 script( bot, update.message.value() );
53 virtual bool isValid(
const types::Update &update )
56 if ( update.message->entities.size() == 0 )
76 std::string entity_text = update.message->text->substr( 0, entity.
length );
79 if ( entity_text.find( command ) != std::string::npos )
89 const EUpdate type = EUpdate::eMessage;
95 MessageClosure script;
int offset
Offset in UTF-16 code units to the start of the entity.
Definition: message_entity.hpp:33
virtual bool isValid(const types::Update &update)
Does the update trigger this command?
Definition: message_command.hpp:53
EMessageEntity type
Type of the entity.
Definition: message_entity.hpp:30
Triggered by bot command in messages.
Definition: message_command.hpp:17
Entity in the message.
Definition: message_entity.hpp:24
Abstract class for bot commands.
Definition: command_handler.hpp:15
int length
Length of the entity in UTF-16 code units.
Definition: message_entity.hpp:33
main namespace for Cppgram
virtual void callClosure(T &bot, const types::Update &update)
Forward the update to another function.
Definition: message_command.hpp:40
MessageCommand(std::string &command, MessageClosure script)
Construct a message command.
Definition: message_command.hpp:28