Completed
Pull Request — master (#20)
by
unknown
03:12
created

CallbackCommand::addCallbackCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace PhpBotFramework\Commands;
4
5
trait CallbackCommand {
6
7
    /**
8
     * \addtogroup Commands
9
     * @{
10
     */
11
12
    /** \brief Store the command triggered on callback query. */
13
    protected $_callback_commands;
14
15
    /** \brief Does the bot has message commands? Set by initBot. */
16
    protected $_callback_commands_set;
17
18
    /**
19
     * \brief Add a function that will be executed everytime a callback query contains a string as data
20
     * \details Use this syntax:
21
     *
22
     *     addMessageCommand("menu", function($bot, $callback_query) {
23
     *         $bot->editMessageText($callback_query['message']['message_id'], "This is the menu"); });
24
     * @param $data The string that will trigger this function.
25
     * @param $script The function that will be triggered by the callback query if it contains the $data string. Must take an object(the bot) and an array(the callback query received).
26
     */
27
    public function addCallbackCommand(string $data, callable $script) {
28
29
        $this->_callback_commands[] = [
30
            'data' => $data,
31
            'script' => $script,
32
        ];
33
34
    }
35
36
    /** @} */
37
38
}
39