Completed
Push — master ( 7bf2c4...ed6650 )
by Danilo
03:26
created

Bot::initBot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace PhpBotFramework;
4
5
use PhpBotFramework\Exceptions\BotException;
6
7
use PhpBotFramework\Entities\InlineKeyboard;
8
9
class Bot extends Core\BaseBot {
10
11
    use Commands\MessageCommand,
12
        Commands\MessageRegexCommand,
13
        Commands\CallbackCommand,
14
        Database\LongPolling,
15
        Database\DatabaseHandler,
16
        Localization\File,
17
        Localization\Language,
18
        Localization\LocalizatedString,
19
        Utilities\BotState;
20
21
    /**
22
     * \addtogroup Bot Bot
23
     * \brief Properties and methods to handle the TelegramBot.
24
     * \details Here are listed all the properties and methods that will help the developer create the basic bot functions.
25
     * @{
26
     */
27
28
    /** \brief Store the inline keyboard */
29
    public $keyboard;
30
31
    /** \brief Pdo reference */
32
    public $pdo;
33
34
    /** \brief Redis connection */
35
    public $redis;
36
37
    /**
38
     * \brief Construct an empty bot.
39
     * \details Construct a bot that can handle updates, localization, database connection and handling, redis database.
40
     */
41
    public function __construct(string $token) {
42
43
        // Parent constructor
44
        parent::__construct($token);
45
46
        // Initialize to an empty array
47
        $this->_message_commands = [];
48
        $this->_callback_commands = [];
49
50
        $this->keyboard = new InlineKeyboard($this);
51
52
    }
53
54
    /** \brief Descruct the bot. */
55
    public function __destruct() {
56
57
        // Close redis connection if it is open
58
        if (isset($this->redis)) {
59
60
            $this->redis->close();
61
62
        }
63
64
        // Close database connection if it is open
65
        if (isset($this->pdo)) {
66
67
            $this->pdo = null;
68
69
        }
70
71
    }
72
73
    /** @} */
74
75
    /** @} */
76
77
78
}
79