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
|
|
|
|