-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters