Skip to content

Commit

Permalink
Added GetMe Command and refactored configure()
Browse files Browse the repository at this point in the history
  • Loading branch information
TiiFuchs committed Oct 6, 2022
1 parent 51e042a commit dada8bb
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Commands/BotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}


protected function configureBotArguments()
protected function configure()
{
$this->addOption('bot-token', 't', InputOption::VALUE_REQUIRED, 'Telegram Bot API Token');
$defaultApiUrl = TelegramBot::DEFAULT_API_SERVER_URL;
Expand Down
6 changes: 1 addition & 5 deletions src/Commands/Close.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@
use Telepath\Exceptions\TelegramException;

#[AsCommand(
name: 'close',
name: 'server:close',
description: 'Close the bot instance before moving it from one local server to another.'
)]
class Close extends BotCommand
{
protected function configure()
{
$this->configureBotArguments();
}

protected function execute(InputInterface $input, OutputInterface $output)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DeleteWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DeleteWebhook extends BotCommand

protected function configure()
{
$this->configureBotArguments();
parent::configure();

$this->addOption('drop-pending-updates', 'd', InputOption::VALUE_NONE, 'Drop all pending updates');
}
Expand Down
59 changes: 59 additions & 0 deletions src/Commands/GetMe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Telepath\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'bot:info',
description: 'Get basic information about the bot'
)]
class GetMe extends BotCommand
{

protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);

$bot = $this->makeBot($input, $output);

$user = $bot->getMe();

$table = new Table($output);
$table->setHeaderTitle('User');

$table->setHeaders([
'id',
'is_bot',
'first_name',
'last_name',
'username',
'can_join_groups',
'can_read_all_group_messages',
'supports_inline_queries',
]);

$table->setRow(0, [
$user->id,
$user->is_bot ? 'true' : 'false',
$user->first_name,
$user->last_name,
$user->username,
$user->can_join_groups ? 'true' : 'false',
$user->can_read_all_group_messages ? 'true' : 'false',
$user->supports_inline_queries ? 'true' : 'false',
]);

$table->setVertical();
$table->setStyle('box');

$table->render();

return self::SUCCESS;
}


}
4 changes: 0 additions & 4 deletions src/Commands/GetWebhookInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
)]
class GetWebhookInfo extends BotCommand
{
protected function configure()
{
$this->configureBotArguments();
}

protected function execute(InputInterface $input, OutputInterface $output)
{
Expand Down
7 changes: 1 addition & 6 deletions src/Commands/LogOut.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@
use Telepath\Exceptions\TelegramException;

#[AsCommand(
name: 'logout',
name: 'server:logout',
description: 'Log out from the cloud Bot API server before launching the bot locally.'
)]
class LogOut extends BotCommand
{

protected function configure()
{
$this->configureBotArguments();
}

protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/SetWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SetWebhook extends BotCommand

protected function configure()
{
$this->configureBotArguments();
parent::configure();

$this->addArgument('url', InputArgument::OPTIONAL, 'HTTPS URL to send updates to');

Expand Down
2 changes: 2 additions & 0 deletions telepathy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ foreach ([__DIR__ . '/../../autoload.php', __DIR__ . '/../autoload.php', __DIR__
use Symfony\Component\Console\Application;
use Telepath\Commands\Close;
use Telepath\Commands\DeleteWebhook;
use Telepath\Commands\GetMe;
use Telepath\Commands\GetWebhookInfo;
use Telepath\Commands\LogOut;
use Telepath\Commands\SetWebhook;
Expand All @@ -26,6 +27,7 @@ $application->addCommands([
new GetWebhookInfo(),
new LogOut(),
new Close(),
new GetMe(),
]);

$application->run();

0 comments on commit dada8bb

Please sign in to comment.