1 | <?php |
||
35 | class BasicBot extends Core\CoreBot |
||
36 | { |
||
37 | use \PhpBotFramework\Commands\CommandHandler; |
||
38 | |||
39 | /** @internal |
||
40 | * \brief True if the bot is using webhook? */ |
||
41 | protected $_is_webhook; |
||
42 | |||
43 | /** |
||
44 | * \brief Construct an empty base bot. |
||
45 | * \details Construct a base bot that can handle updates. |
||
46 | */ |
||
47 | 1 | public function __construct(string $token) |
|
48 | { |
||
49 | 1 | parent::__construct($token); |
|
50 | |||
51 | // Add alias for entity classes |
||
52 | 1 | class_alias('PhpBotFramework\Entities\Message', 'PhpBotFramework\Entities\EditedMessage'); |
|
53 | 1 | class_alias('PhpBotFramework\Entities\Message', 'PhpBotFramework\Entities\ChannelPost'); |
|
54 | 1 | class_alias('PhpBotFramework\Entities\Message', 'PhpBotFramework\Entities\EditedChannelPost'); |
|
55 | 1 | } |
|
56 | |||
57 | /** @} */ |
||
58 | |||
59 | /** |
||
60 | * \addtogroup Bot |
||
61 | * @{ |
||
62 | */ |
||
63 | |||
64 | /** |
||
65 | * \brief Get update and process it. |
||
66 | * \details Call this method if user is using webhook. |
||
67 | * It'll get bot's update from php::\input, check it and then process it using <b>processUpdate</b>. |
||
68 | */ |
||
69 | public function processWebhookUpdate() |
||
76 | |||
77 | /** |
||
78 | * \brief Get updates received by the bot, and hold the offset in $offset. |
||
79 | * \details Get the <code>update_id</code> of the first update to parse, set it in $offset and |
||
80 | * then it start an infinite loop where it processes updates and keep $offset on the update_id of the last update received. |
||
81 | * Each processUpdate() method call is surrounded by a try/catch. |
||
82 | * @see getUpdates |
||
83 | * @param int $limit <i>Optional</i>. Limits the number of updates to be retrieved. Values between 1—100 are accepted. |
||
84 | * @param int $timeout <i>Optional</i>. Timeout in seconds for long polling. |
||
85 | */ |
||
86 | public function getUpdatesLocal(int $limit = 100, int $timeout = 60) |
||
111 | |||
112 | /** @} */ |
||
113 | |||
114 | /** |
||
115 | * @internal |
||
116 | * \brief Dispatch each update to the right method (processMessage, processCallbackQuery, etc). |
||
117 | * \details Set $chat_id for each update, $text, $data and $query are set for each update that contains them. |
||
118 | * @param array $update Reference to the update received. |
||
119 | * @return int The id of the update processed. |
||
120 | */ |
||
121 | 3 | protected function processUpdate(array $update) : int |
|
153 | |||
154 | /** |
||
155 | * \brief Called every message received by the bot. |
||
156 | * \details Override it to script the bot answer for each message. |
||
157 | * <code>$chat_id</code> and <code>$text</code>, if the message contains text(use getMessageText() to access it), set inside of this function. |
||
158 | * @param Message $message Reference to the message received. |
||
159 | */ |
||
160 | protected function processMessage(Message $message) |
||
163 | |||
164 | /** |
||
165 | * \brief Called every callback query received by the bot. |
||
166 | * \details Override it to script the bot answer for each callback. |
||
167 | * <code>$chat_id</code> and <code>$data</code>, if set in the callback query(use getCallbackData() to access it) set inside of this function. |
||
168 | * @param CallbackQuery $callback_query Reference to the callback query received. |
||
169 | */ |
||
170 | protected function processCallbackQuery(CallbackQuery $callback_query) |
||
173 | |||
174 | /** |
||
175 | * \brief Called every inline query received by the bot. |
||
176 | * \details Override it to script the bot answer for each inline query. |
||
177 | * $chat_id and $query(use getInlineQuery() to access it) set inside of this function. |
||
178 | * @param InlineQuery $inline_query Reference to the inline query received. |
||
179 | */ |
||
180 | protected function processInlineQuery(InlineQuery $inline_query) |
||
183 | |||
184 | /** |
||
185 | * \brief Called every chosen inline result received by the bot. |
||
186 | * \details Override it to script the bot answer for each chosen inline result. |
||
187 | * <code>$chat_id</code> set inside of this function. |
||
188 | * @param ChosenInlineResult $chosen_inline_result Reference to the chosen inline result received. |
||
189 | */ |
||
190 | protected function processChosenInlineResult(ChosenInlineResult $chosen_inline_result) |
||
193 | |||
194 | /** |
||
195 | * \brief Called every chosen edited message received by the bot. |
||
196 | * \details Override it to script the bot answer for each edited message. |
||
197 | * <code>$chat_id</code> set inside of this function. |
||
198 | * @param Message $edited_message The message edited by the user. |
||
199 | */ |
||
200 | protected function processEditedMessage(Message $edited_message) |
||
203 | |||
204 | /** |
||
205 | * \brief Called every new post in the channel where the bot is in. |
||
206 | * \details Override it to script the bot answer for each post sent in a channel. |
||
207 | * <code>$chat_id</code> set inside of this function. |
||
208 | * @param Message $post The message sent in the channel. |
||
209 | */ |
||
210 | protected function processChannelPost(Message $post) |
||
213 | |||
214 | /** |
||
215 | * \brief Called every time a post get edited in the channel where the bot is in. |
||
216 | * \details Override it to script the bot answer for each post edited in a channel. |
||
217 | * <code>$chat_id</code> set inside of this function. |
||
218 | * @param Message $post The message edited in the channel. |
||
219 | */ |
||
220 | protected function processEditedChannelPost(Message $edited_post) |
||
223 | |||
224 | /** @} */ |
||
225 | } |
||
226 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.