Skip to content

Commit

Permalink
Added Close and logOut Commands
Browse files Browse the repository at this point in the history
  • Loading branch information
TiiFuchs committed Oct 6, 2022
1 parent 6811fa1 commit ac4d9c1
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
40 changes: 40 additions & 0 deletions src/Commands/Close.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Telepath\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Telepath\Exceptions\TelegramException;

#[AsCommand(
name: '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)
{
parent::execute($input, $output);

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

try {
$bot->close();
} catch (TelegramException $e) {
\Termwind\render('<div class="error">' . $e->getMessage() . '</div>');
return self::FAILURE;
}

$success = $bot->lastApiResult() ?? 'Close was successful';
\Termwind\render('<div class="success">' . $success . '</div>');
return self::SUCCESS;
}


}
48 changes: 48 additions & 0 deletions src/Commands/LogOut.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Telepath\Commands;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Telepath\Exceptions\TelegramException;

#[AsCommand(
name: '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);

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

try {
$bot->logOut();
} catch (TelegramException $e) {
\Termwind\render('<div class="error">' . $e->getMessage() . '</div>');
return self::FAILURE;
}

$success = $bot->lastApiResult() ?? 'logOut was successful';
\Termwind\render('<div class="success">' . $success . '</div>');

$time = new \DateTime('+10 minutes');
\Termwind\render(<<<HTML
<div class="mt-1 px-1 py-1 bg-orange-700 text-white">
Please note that you will not be able to log back in to the cloud Bot API server for 10 minutes from now ({$time->format('H:i:s')} UTC).
</div>
HTML);

return self::SUCCESS;
}

}
10 changes: 8 additions & 2 deletions telepathy
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
require __DIR__ . '/vendor/autoload.php';

use Symfony\Component\Console\Application;
use Telepath\Commands\Close;
use Telepath\Commands\DeleteWebhook;
use Telepath\Commands\GetWebhookInfo;
use Telepath\Commands\LogOut;
use Telepath\Commands\SetWebhook;

$application = new Application();
$application = new Application(
name: 'Telepathy',
);

$application->addCommands([
new SetWebhook(),
new DeleteWebhook(),
new GetWebhookInfo()
new GetWebhookInfo(),
new LogOut(),
new Close(),
]);

$application->run();

0 comments on commit ac4d9c1

Please sign in to comment.