Skip to content

Commit

Permalink
Updated commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsandrov16 committed Nov 27, 2024
1 parent 3e1b631 commit 8d0dd22
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
28 changes: 27 additions & 1 deletion src/Cli/Commands/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Al3x5\xBot\Cli\Cmd;
use Al3x5\xBot\Cli\Style;
use Al3x5\xBot\xBot;

/**
* Hook Command class
Expand All @@ -18,9 +19,34 @@ final class Hook extends Cmd
];

public static function execute(array $argv = []): string
{
//chequea si el usuario ha proporcionado algún argumento
$ck = self::checkArguments($argv, 3);
if (!is_null($ck)) return $ck;

if (count($argv) === 3) {
if (file_exists('config.php')) {
$cfg = require 'config.php';

$xbot = new xBot($cfg);

return match ($argv[2]) {
'set' => $xbot->setWebhook(['url' => $argv[2]]),
'get' => $xbot->getWebhookInfo(),
'delete' => $xbot->deleteWebhook(),
'about' => $xbot->getMe(),
default => self::help()
};
}
}

return self::help();
}

public static function help(): string
{
self::println(
Style::bgColor("Manages the webhook settings of your Telegram bot", "purple",false) .PHP_EOL .PHP_EOL .
self::NAME . Style::color(' v' . self::VERSION, 'green') . PHP_EOL . PHP_EOL .
Style::color('Usage:', 'yellow') . PHP_EOL .
"php xbot hook [options]"
);
Expand Down
54 changes: 52 additions & 2 deletions src/Cli/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,59 @@ final class Install extends Cmd
{
public static function execute(array $argv = []): string
{
$ck=self::checkArguments($argv);
$ck = self::checkArguments($argv);
if (!is_null($ck)) return $ck;

return self::println(Style::bgColor('Install','blue'));

self::println(
'This command will help you create the necessary configuration files for your bot.' . PHP_EOL
);

$data = '';

$token = self::input("Enter your bot token");
$name = self::input("Enter your bot name");

$admins = self::input("Enter the IDs of the administrators (separated by commas)");
/*$adminsInput = self::input("Enter the IDs of the administrators (separated by commas)");
$admins = array_map('trim', explode(',', $adminsInput));*/

$dev = self::input("Is it development environment [yes/no]?");
$dev = ($dev === 'yes') ? 'true' : 'false';
$parseMode = self::input("Enter the parsing mode [HTML, Markdown or MarkdownV2]");

$data = <<<PHP
<?php
return [
'token' => '$token',
'name' => '$name',
'admins' => [$admins],
//'storage' => INSTANCE_OF_YOUR_CACHE_LIBRARY,
//'webhook'=> 'https://YOUR_WEBHOOK_URL,
//'webhook_secret' => 'YOUR_WEBHOOK_SECRET',
//'db'=>'sqlite:xbot.db',
'dev' => $dev,
'logs' => 'storage/logs', //LOGS DIR
'parse_mode'=>'HTML',
'handler' => [
//NAMESPACES COMMANDS
//'/start' => \App\Commands\StartCommand::class,
]
];
PHP;

static::make($data);

return self::println(Style::bgColor('SUCCESS','green')." Process successfully completed");
}

private static function make(string $content)
{
if (!file_exists('storage')) {
mkdir('storage/logs',recursive:true);
mkdir('storage/cache',recursive:true);
}

file_put_contents('config.php', $content);
}
}

0 comments on commit 8d0dd22

Please sign in to comment.