Skip to content

Small code fixes and simplifications #1001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- [:ledger: View file changes][Unreleased]
### Added
### Changed
- Small readme and code fixes / simplifications.
### Deprecated
### Removed
### Fixed
- Boolean value for Polls gets saved correctly in MySQL DB.
- Correctly use `Request::answerInlineQuery` in `InlineQuery::answer`.
### Security

## [0.60.0] - 2019-08-16
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Telegram announced official support for a [Bot API](https://telegram.org/blog/bo
This Bot aims to provide a platform where one can simply write a bot and have interactions in a matter of minutes.

The Bot can:
- Retrieve updates with [webhook][#webhook-installation] and [getUpdates][#getupdates-installation] methods.
- Retrieve updates with [webhook](#webhook-installation) and [getUpdates](#getupdates-installation) methods.
- Supports all types and methods according to Telegram API 4.4 (July 2019).
- Supports supergroups.
- Handle commands in chat with other bots.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"ext-json": "*",
"ext-mbstring": "*",
"psr/log": "^1.1",
"monolog/monolog": "^1.24",
"monolog/monolog": "^1.25",
"guzzlehttp/guzzle": "^6.3"
},
"require-dev": {
Expand Down
85 changes: 44 additions & 41 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 1 addition & 10 deletions src/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,7 @@ abstract public function execute();
*/
public function executeNoDb()
{
//Preparing message
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();

$data = [
'chat_id' => $chat_id,
'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.',
];

return Request::sendMessage($data);
return $this->replyToChat('Sorry no database connection, unable to execute "' . $this->name . '" command.');
}

/**
Expand Down
13 changes: 8 additions & 5 deletions src/Commands/SystemCommands/CallbackqueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Longman\TelegramBot\Commands\SystemCommands;

use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Entities\ServerResponse;

/**
* Callback query command
Expand Down Expand Up @@ -41,21 +41,24 @@ class CallbackqueryCommand extends SystemCommand
/**
* Command execute method
*
* @return mixed
* @return ServerResponse
*/
public function execute()
{
//$callback_query = $this->getUpdate()->getCallbackQuery();
//$callback_query = $this->getCallbackQuery();
//$user_id = $callback_query->getFrom()->getId();
//$query_id = $callback_query->getId();
//$query_data = $callback_query->getData();

$answer = null;
$callback_query = $this->getCallbackQuery();

// Call all registered callbacks.
foreach (self::$callbacks as $callback) {
$callback($this->getUpdate()->getCallbackQuery());
$answer = $callback($callback_query);
}

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

/**
Expand Down
7 changes: 3 additions & 4 deletions src/Commands/SystemCommands/InlinequeryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Commands\SystemCommands;

use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;

/**
* Inline query command
Expand All @@ -31,7 +30,7 @@ class InlinequeryCommand extends SystemCommand
/**
* @var string
*/
protected $version = '1.0.0';
protected $version = '1.0.1';

/**
* Command execute method
Expand All @@ -40,10 +39,10 @@ class InlinequeryCommand extends SystemCommand
*/
public function execute()
{
//$inline_query = $this->getUpdate()->getInlineQuery();
//$inline_query = $this->getInlineQuery();
//$user_id = $inline_query->getFrom()->getId();
//$query = $inline_query->getQuery();

return Request::answerInlineQuery(['inline_query_id' => $this->getUpdate()->getInlineQuery()->getId()]);
return $this->getInlineQuery()->answer([]);
}
}
2 changes: 1 addition & 1 deletion src/Entities/InlineQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function subEntities()
*/
public function answer(array $results, array $data = [])
{
return Request::answerCallbackQuery(array_merge([
return Request::answerInlineQuery(array_merge([
'callback_query_id' => $this->getId(),
'results' => $results,
], $data));
Expand Down
13 changes: 1 addition & 12 deletions src/Entities/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,7 @@ protected function subEntities()
*/
public function getUpdateType()
{
$types = [
'message',
'edited_message',
'channel_post',
'edited_channel_post',
'inline_query',
'chosen_inline_result',
'callback_query',
'shipping_query',
'pre_checkout_query',
'poll',
];
$types = array_keys($this->subEntities());
foreach ($types as $type) {
if ($this->getProperty($type)) {
return $type;
Expand Down
Loading