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

CallbackCommand   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A addCallbackCommand() 0 8 1
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