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\CommandHandler, |
12
|
|
|
Commands\MessageCommand, |
13
|
|
|
Commands\MessageRegexCommand, |
14
|
|
|
Commands\CallbackCommand, |
15
|
|
|
Database\LongPolling, |
16
|
|
|
Database\DatabaseHandler, |
17
|
|
|
Utilities\BotState, |
18
|
|
|
Utilities\Localization; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* \addtogroup Bot Bot |
22
|
|
|
* \brief Properties and methods to handle the TelegramBot. |
23
|
|
|
* \details Here are listed all the properties and methods that will help the developer create the basic bot functions. |
24
|
|
|
* @{ |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
/** \brief Store the inline keyboard */ |
28
|
|
|
public $keyboard; |
29
|
|
|
|
30
|
|
|
/** \brief Pdo reference */ |
31
|
|
|
public $pdo; |
32
|
|
|
|
33
|
|
|
/** \brief Redis connection */ |
34
|
|
|
public $redis; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* \brief Construct an empty bot. |
38
|
|
|
* \details Construct a bot that can handle updates, localization, database connection and handling, redis database. |
39
|
|
|
*/ |
40
|
|
|
public function __construct(string $token) { |
41
|
|
|
|
42
|
|
|
// Parent constructor |
43
|
|
|
parent::__construct($token); |
44
|
|
|
|
45
|
|
|
// Initialize to an empty array |
46
|
|
|
$this->_message_commands = []; |
47
|
|
|
$this->_callback_commands = []; |
48
|
|
|
|
49
|
|
|
$this->keyboard = new InlineKeyboard($this); |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** \brief Descruct the bot. */ |
54
|
|
|
public function __destruct() { |
55
|
|
|
|
56
|
|
|
// Close redis connection if it is open |
57
|
|
|
if (isset($this->redis)) { |
58
|
|
|
|
59
|
|
|
$this->redis->close(); |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// Close database connection if it is open |
64
|
|
|
if (isset($this->pdo)) { |
65
|
|
|
|
66
|
|
|
$this->pdo = null; |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* \addtogroup Core Core(Internal) |
74
|
|
|
* @{ |
75
|
|
|
*/ |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* \brief Init variables to skip parsing commands if there aren't any. |
79
|
|
|
* \details Called internnaly by |
80
|
|
|
* - <code>getUpdatesLocal</code> |
81
|
|
|
* - <code>getUpdatesRedis</code> |
82
|
|
|
* - <code>getUpdatesDatabase</code> |
83
|
|
|
* - <code>processWebhookUpdate</code> |
84
|
|
|
*/ |
85
|
|
|
private function initBot() { |
86
|
|
|
|
87
|
|
|
// Are there message commands? |
88
|
|
|
$this->_message_commands_set = !empty($this->_message_commands); |
|
|
|
|
89
|
|
|
|
90
|
|
|
// Are there callback commands? |
91
|
|
|
$this->_callback_commands_set = !empty($this->_callback_commands); |
|
|
|
|
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.