2022-08-13 17:00:29 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace ZM\Annotation\OneBot;
|
|
|
|
|
|
|
|
|
|
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
|
|
|
|
|
use Doctrine\Common\Annotations\Annotation\Target;
|
|
|
|
|
use ZM\Annotation\AnnotationBase;
|
|
|
|
|
use ZM\Annotation\Interfaces\Level;
|
|
|
|
|
use ZM\Exception\InvalidArgumentException;
|
|
|
|
|
use ZM\Exception\ZMKnownException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class BotCommand
|
|
|
|
|
* 机器人指令注解
|
|
|
|
|
*
|
|
|
|
|
* @Annotation
|
|
|
|
|
* @NamedArgumentConstructor()
|
|
|
|
|
* @Target("METHOD")
|
|
|
|
|
*/
|
2022-11-03 10:18:17 +08:00
|
|
|
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
|
2022-08-13 17:00:29 +08:00
|
|
|
class BotCommand extends AnnotationBase implements Level
|
|
|
|
|
{
|
2022-09-26 22:44:41 +08:00
|
|
|
private array $arguments = [];
|
2022-08-13 17:00:29 +08:00
|
|
|
|
2022-12-19 20:22:47 +08:00
|
|
|
/**
|
|
|
|
|
* @param string[] $alias
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(public $name = '', public $match = '', public $pattern = '', public $regex = '', public $start_with = '', public $end_with = '', public $keyword = '', public $alias = [], public $message_type = '', public $user_id = '', public $group_id = '', public $level = 20)
|
|
|
|
|
{
|
2022-08-13 17:00:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function make(
|
|
|
|
|
$name = '',
|
|
|
|
|
$match = '',
|
|
|
|
|
$pattern = '',
|
|
|
|
|
$regex = '',
|
|
|
|
|
$start_with = '',
|
|
|
|
|
$end_with = '',
|
|
|
|
|
$keyword = '',
|
|
|
|
|
$alias = [],
|
|
|
|
|
$message_type = '',
|
|
|
|
|
$user_id = '',
|
|
|
|
|
$group_id = '',
|
|
|
|
|
$level = 20
|
|
|
|
|
): BotCommand {
|
|
|
|
|
return new static(...func_get_args());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
|
* @throws ZMKnownException
|
|
|
|
|
*/
|
|
|
|
|
public function withArgument(
|
|
|
|
|
string $name,
|
|
|
|
|
string $description = '',
|
|
|
|
|
string $type = 'string',
|
|
|
|
|
bool $required = false,
|
|
|
|
|
string $prompt = '',
|
|
|
|
|
string $default = '',
|
|
|
|
|
int $timeout = 60,
|
|
|
|
|
int $error_prompt_policy = 1
|
|
|
|
|
): BotCommand {
|
|
|
|
|
$this->arguments[] = new CommandArgument($name, $description, $type, $required, $prompt, $default, $timeout, $error_prompt_policy);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-19 01:45:27 +08:00
|
|
|
public function withArgumentObject(CommandArgument $argument): BotCommand
|
|
|
|
|
{
|
|
|
|
|
$this->arguments[] = $argument;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-13 17:00:29 +08:00
|
|
|
public function getLevel(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->level;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param int $level
|
|
|
|
|
*/
|
|
|
|
|
public function setLevel($level)
|
|
|
|
|
{
|
|
|
|
|
$this->level = $level;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getArguments(): array
|
|
|
|
|
{
|
|
|
|
|
return $this->arguments;
|
|
|
|
|
}
|
|
|
|
|
}
|