From ac4d9c1c6f9154b97f1e8f88b1af2c66e7ed8975 Mon Sep 17 00:00:00 2001 From: Tii Date: Thu, 6 Oct 2022 22:07:10 +0200 Subject: [PATCH] Added Close and logOut Commands --- src/Commands/Close.php | 40 ++++++++++++++++++++++++++++++++++ src/Commands/LogOut.php | 48 +++++++++++++++++++++++++++++++++++++++++ telepathy | 10 +++++++-- 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 src/Commands/Close.php create mode 100644 src/Commands/LogOut.php diff --git a/src/Commands/Close.php b/src/Commands/Close.php new file mode 100644 index 0000000..7a1c0fc --- /dev/null +++ b/src/Commands/Close.php @@ -0,0 +1,40 @@ +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('
' . $e->getMessage() . '
'); + return self::FAILURE; + } + + $success = $bot->lastApiResult() ?? 'Close was successful'; + \Termwind\render('
' . $success . '
'); + return self::SUCCESS; + } + + +} \ No newline at end of file diff --git a/src/Commands/LogOut.php b/src/Commands/LogOut.php new file mode 100644 index 0000000..9c262dd --- /dev/null +++ b/src/Commands/LogOut.php @@ -0,0 +1,48 @@ +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('
' . $e->getMessage() . '
'); + return self::FAILURE; + } + + $success = $bot->lastApiResult() ?? 'logOut was successful'; + \Termwind\render('
' . $success . '
'); + + $time = new \DateTime('+10 minutes'); + \Termwind\render(<< + 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). + + HTML); + + return self::SUCCESS; + } + +} \ No newline at end of file diff --git a/telepathy b/telepathy index 7e63678..422abf3 100755 --- a/telepathy +++ b/telepathy @@ -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(); \ No newline at end of file