Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
dae9b2b5b1 | |||
40ceb7a86c |
@@ -45,12 +45,13 @@ class command
|
||||
/**
|
||||
* Выполнить команду
|
||||
*
|
||||
* @param array $update Событие
|
||||
* @param string ...$parameters Параметры команды
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function execute(string ...$parameters): bool
|
||||
public function execute(array $update, string ...$parameters): mixed
|
||||
{
|
||||
return ($this->program)(...$parameters);
|
||||
return call_user_func($this->program, $update, ...$parameters);
|
||||
}
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ class core
|
||||
}
|
||||
|
||||
// Запись в реестр
|
||||
$this->patterns .= [$pattern];
|
||||
$this->patterns []= $pattern;
|
||||
|
||||
return $pattern;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class core
|
||||
// Пройдена проверка на совпадение с шаблоном
|
||||
|
||||
// Выполнение команд связанных с шаблоном
|
||||
$pattern->handle($update['object']['message']['from_id'], $parameters);
|
||||
$pattern->handle($update['object']['message']['from_id'], $update, ...$parameters);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ class pattern
|
||||
public function command(command $command): static
|
||||
{
|
||||
// Запись в реестр
|
||||
$this->commands .= [$command];
|
||||
$this->commands []= $command;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class pattern
|
||||
public function check(string $text, array &$parameters = []): bool
|
||||
{
|
||||
// Проверка на совпадение с шаблоном
|
||||
preg_match_all($this->text, $text, $matches);
|
||||
preg_match_all($this->text, $text, $matches, PREG_PATTERN_ORDER);
|
||||
|
||||
// Простой шаблон
|
||||
if (count($matches) === 1) return !empty($matches[0]);
|
||||
@@ -64,7 +64,7 @@ class pattern
|
||||
unset($matches[0]);
|
||||
|
||||
// Сложный шаблон
|
||||
foreach ($matches as $match) if (!empty($match[0])) $parameters []= $match[0]; else return false;
|
||||
foreach ($matches as $match) if (isset($match[0])) $parameters []= $match[0]; else return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -73,17 +73,21 @@ class pattern
|
||||
* Обработать подключенные команды
|
||||
*
|
||||
* @param int $id Идентификатор аккаунта вызывающего выполнение
|
||||
* @param array $update Событие
|
||||
* @param string ...$parameters Параметры команды
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(int $id, string ...$parameters): void
|
||||
public function handle(int $id, array $update, string ...$parameters): void
|
||||
{
|
||||
foreach ($this->commands as $command) {
|
||||
// Перебор команд
|
||||
|
||||
// Авторизация
|
||||
if (!empty($command->accounts) && !$command->access($id)) return;
|
||||
|
||||
// Выполнение команды
|
||||
if (!empty($command->accounts) && $command->access($id)) $command->execute(...$parameters);
|
||||
$command->execute($update, ...$parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user