1 | <?php |
||
28 | class CallbackCommand extends BasicCommand |
||
29 | { |
||
30 | /** @} */ |
||
31 | |||
32 | public static $type = 'callback_query'; |
||
33 | |||
34 | public static $object_class = 'PhpBotFramework\Entities\CallbackQuery'; |
||
35 | |||
36 | public static $priority = 1; |
||
37 | |||
38 | private $data; |
||
39 | |||
40 | /** |
||
41 | * \brief Add a function that will be executed everytime a callback query contains a string as data |
||
42 | * \details Use this syntax: |
||
43 | * |
||
44 | * $bot->addCallbackCommand("menu", function($bot, $callback_query) { |
||
45 | * $bot->editMessageText($callback_query['message']['message_id'], "This is the menu"); |
||
46 | * }); |
||
47 | * |
||
48 | * @param string $data The string that will trigger this function. |
||
49 | * @param callable $script The function that will be triggered by the callback query if it contains |
||
50 | * the $data string. Must take an object(the bot) and an array(the callback query received). |
||
51 | */ |
||
52 | public function __construct(string $data, callable $script) |
||
53 | { |
||
54 | $this->data = $data; |
||
55 | $this->script = $script; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * \brief (<i>Internal</i>) Process the callback query and check if it triggers a command of this type. |
||
60 | * @param array $callback_query Callback query to process. |
||
61 | * @return bool True if the callback query triggered a command. |
||
62 | */ |
||
63 | public function checkCommand(array $callback_query) : bool |
||
74 | |||
75 | /** @} */ |
||
76 | |||
77 | /** @} */ |
||
78 | } |
||
79 |