Skip to content

Commit d5b99fa

Browse files
authored
Merge pull request #1001 from noplanman/mini_fixes
Small code fixes and simplifications
2 parents c2a40fc + fd1ec33 commit d5b99fa

File tree

10 files changed

+65
-78
lines changed

10 files changed

+65
-78
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
88
- [:ledger: View file changes][Unreleased]
99
### Added
1010
### Changed
11+
- Small readme and code fixes / simplifications.
1112
### Deprecated
1213
### Removed
1314
### Fixed
1415
- Boolean value for Polls gets saved correctly in MySQL DB.
16+
- Correctly use `Request::answerInlineQuery` in `InlineQuery::answer`.
1517
### Security
1618

1719
## [0.60.0] - 2019-08-16

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Telegram announced official support for a [Bot API](https://telegram.org/blog/bo
7373
This Bot aims to provide a platform where one can simply write a bot and have interactions in a matter of minutes.
7474

7575
The Bot can:
76-
- Retrieve updates with [webhook][#webhook-installation] and [getUpdates][#getupdates-installation] methods.
76+
- Retrieve updates with [webhook](#webhook-installation) and [getUpdates](#getupdates-installation) methods.
7777
- Supports all types and methods according to Telegram API 4.4 (July 2019).
7878
- Supports supergroups.
7979
- Handle commands in chat with other bots.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"ext-json": "*",
3030
"ext-mbstring": "*",
3131
"psr/log": "^1.1",
32-
"monolog/monolog": "^1.24",
32+
"monolog/monolog": "^1.25",
3333
"guzzlehttp/guzzle": "^6.3"
3434
},
3535
"require-dev": {

composer.lock

Lines changed: 44 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Commands/Command.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,7 @@ abstract public function execute();
197197
*/
198198
public function executeNoDb()
199199
{
200-
//Preparing message
201-
$message = $this->getMessage();
202-
$chat_id = $message->getChat()->getId();
203-
204-
$data = [
205-
'chat_id' => $chat_id,
206-
'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.',
207-
];
208-
209-
return Request::sendMessage($data);
200+
return $this->replyToChat('Sorry no database connection, unable to execute "' . $this->name . '" command.');
210201
}
211202

212203
/**

src/Commands/SystemCommands/CallbackqueryCommand.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace Longman\TelegramBot\Commands\SystemCommands;
1212

1313
use Longman\TelegramBot\Commands\SystemCommand;
14-
use Longman\TelegramBot\Request;
14+
use Longman\TelegramBot\Entities\ServerResponse;
1515

1616
/**
1717
* Callback query command
@@ -41,21 +41,24 @@ class CallbackqueryCommand extends SystemCommand
4141
/**
4242
* Command execute method
4343
*
44-
* @return mixed
44+
* @return ServerResponse
4545
*/
4646
public function execute()
4747
{
48-
//$callback_query = $this->getUpdate()->getCallbackQuery();
48+
//$callback_query = $this->getCallbackQuery();
4949
//$user_id = $callback_query->getFrom()->getId();
5050
//$query_id = $callback_query->getId();
5151
//$query_data = $callback_query->getData();
5252

53+
$answer = null;
54+
$callback_query = $this->getCallbackQuery();
55+
5356
// Call all registered callbacks.
5457
foreach (self::$callbacks as $callback) {
55-
$callback($this->getUpdate()->getCallbackQuery());
58+
$answer = $callback($callback_query);
5659
}
5760

58-
return Request::answerCallbackQuery(['callback_query_id' => $this->getUpdate()->getCallbackQuery()->getId()]);
61+
return ($answer instanceof ServerResponse) ? $answer : $callback_query->answer();
5962
}
6063

6164
/**

src/Commands/SystemCommands/InlinequeryCommand.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
namespace Longman\TelegramBot\Commands\SystemCommands;
1212

1313
use Longman\TelegramBot\Commands\SystemCommand;
14-
use Longman\TelegramBot\Request;
1514

1615
/**
1716
* Inline query command
@@ -31,7 +30,7 @@ class InlinequeryCommand extends SystemCommand
3130
/**
3231
* @var string
3332
*/
34-
protected $version = '1.0.0';
33+
protected $version = '1.0.1';
3534

3635
/**
3736
* Command execute method
@@ -40,10 +39,10 @@ class InlinequeryCommand extends SystemCommand
4039
*/
4140
public function execute()
4241
{
43-
//$inline_query = $this->getUpdate()->getInlineQuery();
42+
//$inline_query = $this->getInlineQuery();
4443
//$user_id = $inline_query->getFrom()->getId();
4544
//$query = $inline_query->getQuery();
4645

47-
return Request::answerInlineQuery(['inline_query_id' => $this->getUpdate()->getInlineQuery()->getId()]);
46+
return $this->getInlineQuery()->answer([]);
4847
}
4948
}

src/Entities/InlineQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected function subEntities()
4747
*/
4848
public function answer(array $results, array $data = [])
4949
{
50-
return Request::answerCallbackQuery(array_merge([
50+
return Request::answerInlineQuery(array_merge([
5151
'callback_query_id' => $this->getId(),
5252
'results' => $results,
5353
], $data));

src/Entities/Update.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,7 @@ protected function subEntities()
5858
*/
5959
public function getUpdateType()
6060
{
61-
$types = [
62-
'message',
63-
'edited_message',
64-
'channel_post',
65-
'edited_channel_post',
66-
'inline_query',
67-
'chosen_inline_result',
68-
'callback_query',
69-
'shipping_query',
70-
'pre_checkout_query',
71-
'poll',
72-
];
61+
$types = array_keys($this->subEntities());
7362
foreach ($types as $type) {
7463
if ($this->getProperty($type)) {
7564
return $type;

0 commit comments

Comments
 (0)