mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
fix comment spacing problem (build 443)
This commit is contained in:
parent
444a77933a
commit
7ce3ef41df
@ -65,7 +65,6 @@ return (new PhpCsFixer\Config())
|
||||
'standardize_not_equals' => true,
|
||||
'multiline_comment_opening_closing' => true,
|
||||
'phpdoc_summary' => false,
|
||||
'single_line_comment_spacing' => false,
|
||||
])
|
||||
->setFinder(
|
||||
PhpCsFixer\Finder::create()
|
||||
|
||||
@ -34,9 +34,9 @@ class Hello
|
||||
* 默认的图片监听路由对应目录,如需要使用可取消下面的注释,把上面的 /* 换成 /**
|
||||
* @OnStart(-1)
|
||||
*/
|
||||
//public function onStart() {
|
||||
// public function onStart() {
|
||||
// \ZM\Http\RouteManager::addStaticFileRoute("/images/", \ZM\Utils\DataProvider::getWorkingDir()."/zm_data/images/");
|
||||
//}
|
||||
// }
|
||||
|
||||
/**
|
||||
* 使用命令 .reload 发给机器人远程重载,注意将 user_id 换成你自己的 QQ
|
||||
@ -98,7 +98,7 @@ class Hello
|
||||
$api = ''; // 请在这里填入你的图灵机器人的apikey
|
||||
if ($api === '') {
|
||||
return false;
|
||||
} //如果没有填入apikey则此功能关闭
|
||||
} // 如果没有填入apikey则此功能关闭
|
||||
if (($this->_running_annotation ?? null) instanceof CQCommand) {
|
||||
$msg = ctx()->getFullArg('我在!有什么事吗?');
|
||||
} else {
|
||||
@ -109,7 +109,7 @@ class Hello
|
||||
return TuringAPI::getTuringMsg($msg, $user_id, $api);
|
||||
}
|
||||
QQBot::getInstance()->handle(ctx()->getData(), ctx()->getCache('level') + 1);
|
||||
//执行嵌套消息,递归层级+1
|
||||
// 执行嵌套消息,递归层级+1
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -19,14 +19,14 @@ class TuringAPI
|
||||
public static function getTuringMsg($msg, $user_id, $api)
|
||||
{
|
||||
$origin = $msg;
|
||||
if (($cq = CQ::getCQ($msg)) !== null) {//如有CQ码则去除
|
||||
if (($cq = CQ::getCQ($msg)) !== null) {// 如有CQ码则去除
|
||||
if ($cq['type'] == 'image') {
|
||||
$url = $cq['params']['url'];
|
||||
$msg = str_replace(mb_substr($msg, $cq['start'], $cq['end'] - $cq['start'] + 1), '', $msg);
|
||||
}
|
||||
$msg = trim($msg);
|
||||
}
|
||||
//构建将要发送的json包给图灵
|
||||
// 构建将要发送的json包给图灵
|
||||
$content = [
|
||||
'reqType' => 0,
|
||||
'userInfo' => [
|
||||
@ -64,11 +64,11 @@ class TuringAPI
|
||||
return '哎呀,我刚才有点走神了,可能忘记你说什么了,可以重说一遍吗';
|
||||
}
|
||||
Console::error(zm_internal_errcode('E00038') . "图灵机器人发送错误!\n错误原始内容:" . $origin . "\n来自:" . $user_id . "\n错误信息:" . $status);
|
||||
//echo json_encode($r, 128|256);
|
||||
// echo json_encode($r, 128|256);
|
||||
return '哎呀,我刚才有点走神了,要不一会儿换一种问题试试?';
|
||||
}
|
||||
$result = $api_return['results'];
|
||||
//Console::info(Console::setColor(json_encode($result, 128 | 256), "green"));
|
||||
// Console::info(Console::setColor(json_encode($result, 128 | 256), "green"));
|
||||
$final = '';
|
||||
foreach ($result as $v) {
|
||||
switch ($v['resultType']) {
|
||||
|
||||
@ -48,7 +48,7 @@ class AnnotationParser
|
||||
public function __construct()
|
||||
{
|
||||
$this->start_time = microtime(true);
|
||||
//$this->loadAnnotationClasses();
|
||||
// $this->loadAnnotationClasses();
|
||||
$this->req_mapping[0] = [
|
||||
'id' => 0,
|
||||
'pid' => -1,
|
||||
@ -72,7 +72,7 @@ class AnnotationParser
|
||||
$methods = $reflection_class->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||
$class_annotations = $this->reader->getClassAnnotations($reflection_class);
|
||||
// 这段为新加的:start
|
||||
//这里将每个类里面所有的类注解、方法注解通通加到一颗大树上,后期解析
|
||||
// 这里将每个类里面所有的类注解、方法注解通通加到一颗大树上,后期解析
|
||||
/*
|
||||
$annotation_map: {
|
||||
Module\Example\Hello: {
|
||||
@ -100,7 +100,7 @@ class AnnotationParser
|
||||
foreach ($this->annotation_map[$v]['class_annotations'] as $vs) {
|
||||
$vs->class = $v;
|
||||
|
||||
//预处理1:将适用于每一个函数的注解到类注解重新注解到每个函数下面
|
||||
// 预处理1:将适用于每一个函数的注解到类注解重新注解到每个函数下面
|
||||
if ($vs instanceof ErgodicAnnotation) {
|
||||
foreach (($this->annotation_map[$v]['methods'] ?? []) as $method) {
|
||||
$copy = clone $vs;
|
||||
@ -109,13 +109,13 @@ class AnnotationParser
|
||||
}
|
||||
}
|
||||
|
||||
//预处理2:处理 class 下面的注解
|
||||
// 预处理2:处理 class 下面的注解
|
||||
if ($vs instanceof Closed) {
|
||||
unset($this->annotation_map[$v]);
|
||||
continue 2;
|
||||
}
|
||||
if ($vs instanceof MiddlewareClass) {
|
||||
//注册中间件本身的类,标记到 middlewares 属性中
|
||||
// 注册中间件本身的类,标记到 middlewares 属性中
|
||||
Console::debug('正在注册中间件 ' . $reflection_class->getName());
|
||||
$rs = $this->registerMiddleware($vs, $reflection_class);
|
||||
$this->middlewares[$rs['name']] = $rs;
|
||||
@ -124,7 +124,7 @@ class AnnotationParser
|
||||
|
||||
$inserted = [];
|
||||
|
||||
//预处理3:处理每个函数上面的特殊注解,就是需要操作一些东西的
|
||||
// 预处理3:处理每个函数上面的特殊注解,就是需要操作一些东西的
|
||||
foreach (($this->annotation_map[$v]['methods_annotations'] ?? []) as $method_name => $methods_annotations) {
|
||||
foreach ($methods_annotations as $method_anno) {
|
||||
/* @var AnnotationBase $method_anno */
|
||||
@ -223,7 +223,7 @@ class AnnotationParser
|
||||
public function verifyMiddlewares()
|
||||
{
|
||||
if ((ZMConfig::get('global', 'runtime')['middleware_error_policy'] ?? 1) === 2) {
|
||||
//我承认套三层foreach很不优雅,但是这个会很快的。
|
||||
// 我承认套三层foreach很不优雅,但是这个会很快的。
|
||||
foreach ($this->middleware_map as $v) {
|
||||
foreach ($v as $vs) {
|
||||
foreach ($vs as $mid) {
|
||||
@ -241,7 +241,7 @@ class AnnotationParser
|
||||
return microtime(true) - $this->start_time;
|
||||
}
|
||||
|
||||
//private function below
|
||||
// private function below
|
||||
|
||||
private function registerMiddleware(MiddlewareClass $vs, ReflectionClass $reflection_class): array
|
||||
{
|
||||
|
||||
@ -91,7 +91,7 @@ class InitCommand extends Command
|
||||
$output->writeln('<info>Done!</info>');
|
||||
return 0;
|
||||
}
|
||||
if (LOAD_MODE === 2) { //从phar启动的框架包,初始化的模式
|
||||
if (LOAD_MODE === 2) { // 从phar启动的框架包,初始化的模式
|
||||
$phar_link = new Phar(__DIR__);
|
||||
$current_dir = pathinfo($phar_link->getPath())['dirname'];
|
||||
chdir($current_dir);
|
||||
|
||||
@ -32,7 +32,7 @@ class ModuleListCommand extends Command
|
||||
exit(zm_internal_errcode('E00007') . 'Global config load failed: ' . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
|
||||
}
|
||||
|
||||
//定义常量
|
||||
// 定义常量
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include_once DataProvider::getFrameworkRootDir() . '/src/ZM/global_defines.php';
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ class ModulePackCommand extends Command
|
||||
exit(zm_internal_errcode('E00007') . 'Global config load failed: ' . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
|
||||
}
|
||||
|
||||
//定义常量
|
||||
// 定义常量
|
||||
include_once DataProvider::getFrameworkRootDir() . '/src/ZM/global_defines.php';
|
||||
|
||||
Console::init(
|
||||
|
||||
@ -41,7 +41,7 @@ class ModuleUnpackCommand extends Command
|
||||
exit(zm_internal_errcode('E00007') . 'Global config load failed: ' . ZMConfig::$last_error . "\nPlease init first!\nSee: https://github.com/zhamao-robot/zhamao-framework/issues/37\n");
|
||||
}
|
||||
|
||||
//定义常量
|
||||
// 定义常量
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include_once DataProvider::getFrameworkRootDir() . '/src/ZM/global_defines.php';
|
||||
|
||||
|
||||
@ -73,7 +73,7 @@ class PureHttpCommand extends Command
|
||||
'document_index' => $index,
|
||||
]
|
||||
);
|
||||
//echo "\r" . Coroutine::stats()["coroutine_peak_num"];
|
||||
// echo "\r" . Coroutine::stats()["coroutine_peak_num"];
|
||||
});
|
||||
$server->on('start', function ($server) {
|
||||
Process::signal(SIGINT, function () use ($server) {
|
||||
|
||||
@ -28,7 +28,7 @@ use ZM\Exception\InitException;
|
||||
|
||||
class ConsoleApplication extends Application
|
||||
{
|
||||
public const VERSION_ID = 442;
|
||||
public const VERSION_ID = 443;
|
||||
|
||||
public const VERSION = '2.7.0-beta4';
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ class DB
|
||||
if ($result !== true) {
|
||||
SqlPoolStorage::$sql_pool->putConnection(null);
|
||||
throw new DBException("语句[{$line}]错误!" . $ps->errorInfo()[2]);
|
||||
//echo json_encode(debug_backtrace(), 128 | 256);
|
||||
// echo json_encode(debug_backtrace(), 128 | 256);
|
||||
}
|
||||
SqlPoolStorage::$sql_pool->putConnection($conn);
|
||||
return $ps->fetchAll($fetch_mode);
|
||||
|
||||
@ -67,7 +67,7 @@ class Table
|
||||
public function statement()
|
||||
{
|
||||
$this->cache = [];
|
||||
//TODO: 无返回的statement语句
|
||||
// TODO: 无返回的statement语句
|
||||
}
|
||||
|
||||
public function paintWhereSQL($rule, $operator)
|
||||
|
||||
@ -19,15 +19,15 @@ use ZM\Utils\ZMUtil;
|
||||
|
||||
class EventDispatcher
|
||||
{
|
||||
public const STATUS_NORMAL = 0; //正常结束
|
||||
public const STATUS_NORMAL = 0; // 正常结束
|
||||
|
||||
public const STATUS_INTERRUPTED = 1; //被interrupt了,不管在什么地方
|
||||
public const STATUS_INTERRUPTED = 1; // 被interrupt了,不管在什么地方
|
||||
|
||||
public const STATUS_EXCEPTION = 2; //执行过程中抛出了异常
|
||||
public const STATUS_EXCEPTION = 2; // 执行过程中抛出了异常
|
||||
|
||||
public const STATUS_BEFORE_FAILED = 3; //中间件HandleBefore返回了false,所以不执行此方法
|
||||
public const STATUS_BEFORE_FAILED = 3; // 中间件HandleBefore返回了false,所以不执行此方法
|
||||
|
||||
public const STATUS_RULE_FAILED = 4; //判断事件执行的规则函数判定为false,所以不执行此方法
|
||||
public const STATUS_RULE_FAILED = 4; // 判断事件执行的规则函数判定为false,所以不执行此方法
|
||||
|
||||
/** @var int */
|
||||
public $status = self::STATUS_NORMAL;
|
||||
@ -133,7 +133,7 @@ class EventDispatcher
|
||||
if ($this->status === self::STATUS_RULE_FAILED) {
|
||||
$this->status = self::STATUS_NORMAL;
|
||||
}
|
||||
//TODO:没有过滤before的false,可能会导致一些问题,先观望一下
|
||||
// TODO:没有过滤before的false,可能会导致一些问题,先观望一下
|
||||
} catch (InterruptException $e) {
|
||||
$this->store = $e->return_var;
|
||||
$this->status = self::STATUS_INTERRUPTED;
|
||||
@ -200,7 +200,7 @@ class EventDispatcher
|
||||
}
|
||||
$middleware_obj = EventManager::$middlewares[$middleware->middleware];
|
||||
$before = $middleware_obj['class'];
|
||||
//var_dump($middleware_obj);
|
||||
// var_dump($middleware_obj);
|
||||
$r[$k] = new $before();
|
||||
$r[$k]->class = $q_c;
|
||||
$r[$k]->method = $q_f;
|
||||
|
||||
@ -61,7 +61,7 @@ class EventManager
|
||||
if (server()->worker_id !== $vss->worker_id && $vss->worker_id != -1) {
|
||||
return;
|
||||
}
|
||||
//echo server()->worker_id.PHP_EOL;
|
||||
// echo server()->worker_id.PHP_EOL;
|
||||
$plain_class = $vss->class;
|
||||
Console::debug('Added Middleware-based timer: ' . $plain_class . ' -> ' . $vss->method);
|
||||
Timer::tick($vss->tick_ms, function () use ($vss, $dispatcher) {
|
||||
|
||||
@ -52,10 +52,10 @@ class OnMessage implements SwooleEvent
|
||||
return false;
|
||||
});
|
||||
try {
|
||||
//$starttime = microtime(true);
|
||||
// $starttime = microtime(true);
|
||||
$dispatcher1->dispatchEvents($conn);
|
||||
$dispatcher->dispatchEvents($conn);
|
||||
//Console::success("Used ".round((microtime(true) - $starttime) * 1000, 3)." ms!");
|
||||
// Console::success("Used ".round((microtime(true) - $starttime) * 1000, 3)." ms!");
|
||||
} catch (Exception $e) {
|
||||
$error_msg = $e->getMessage() . ' at ' . $e->getFile() . '(' . $e->getLine() . ')';
|
||||
Console::error(zm_internal_errcode('E00017') . 'Uncaught exception ' . get_class($e) . ' when calling "message": ' . $error_msg);
|
||||
|
||||
@ -66,7 +66,7 @@ class OnRequest implements SwooleEvent
|
||||
$div->method = $node['method'];
|
||||
$div->request_method = $node['request_method'];
|
||||
$div->class = $node['class'];
|
||||
//Console::success("正在执行路由:".$node["method"]);
|
||||
// Console::success("正在执行路由:".$node["method"]);
|
||||
$dispatcher->dispatchEvent($div, null, $params, $request, $response);
|
||||
if (is_string($dispatcher->store) && !$response->isEnd()) {
|
||||
$response->end($dispatcher->store);
|
||||
@ -74,7 +74,7 @@ class OnRequest implements SwooleEvent
|
||||
}
|
||||
}
|
||||
if (!$response->isEnd()) {
|
||||
//Console::warning('返回了404');
|
||||
// Console::warning('返回了404');
|
||||
HttpUtil::responseCodePage($response, 404);
|
||||
}
|
||||
} catch (InterruptException $e) {
|
||||
|
||||
@ -66,7 +66,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
} elseif (!isset($error['type'])) {
|
||||
return;
|
||||
}
|
||||
//DataProvider::saveBuffer();
|
||||
// DataProvider::saveBuffer();
|
||||
/* @var Server $server */
|
||||
if (server() === null) {
|
||||
$server->shutdown();
|
||||
@ -77,10 +77,10 @@ class OnWorkerStart implements SwooleEvent
|
||||
|
||||
Console::verbose("Worker #{$server->worker_id} starting");
|
||||
Framework::$server = $server;
|
||||
//ZMBuf::resetCache(); //清空变量缓存
|
||||
//ZMBuf::set("wait_start", []); //添加队列,在workerStart运行完成前先让其他协程等待执行
|
||||
// ZMBuf::resetCache(); //清空变量缓存
|
||||
// ZMBuf::set("wait_start", []); //添加队列,在workerStart运行完成前先让其他协程等待执行
|
||||
|
||||
//TODO: 单独抽出来MySQL和Redis连接池
|
||||
// TODO: 单独抽出来MySQL和Redis连接池
|
||||
$this->initMySQLPool();
|
||||
|
||||
// 开箱即用的Redis
|
||||
@ -93,9 +93,9 @@ class OnWorkerStart implements SwooleEvent
|
||||
}
|
||||
}
|
||||
|
||||
$this->loadAnnotations(); //加载composer资源、phar外置包、注解解析注册等
|
||||
$this->loadAnnotations(); // 加载composer资源、phar外置包、注解解析注册等
|
||||
|
||||
EventManager::registerTimerTick(); //启动计时器
|
||||
EventManager::registerTimerTick(); // 启动计时器
|
||||
set_coroutine_params(['server' => $server, 'worker_id' => $worker_id]);
|
||||
$dispatcher = new EventDispatcher(OnStart::class);
|
||||
$dispatcher->setRuleFunction(function ($v) {
|
||||
@ -151,7 +151,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
if (Framework::$instant_mode) {
|
||||
goto skip;
|
||||
}
|
||||
//加载各个模块的注解类,以及反射
|
||||
// 加载各个模块的注解类,以及反射
|
||||
Console::debug('Mapping annotations');
|
||||
$parser = new AnnotationParser();
|
||||
$composer = json_decode(file_get_contents(DataProvider::getSourceRootDir() . '/composer.json'), true);
|
||||
@ -187,16 +187,16 @@ class OnWorkerStart implements SwooleEvent
|
||||
}
|
||||
|
||||
$parser->registerMods();
|
||||
EventManager::loadEventByParser($parser); //加载事件
|
||||
EventManager::loadEventByParser($parser); // 加载事件
|
||||
|
||||
skip:
|
||||
//加载自定义的全局函数
|
||||
// 加载自定义的全局函数
|
||||
Console::debug('Loading context class...');
|
||||
$context_class = ZMConfig::get('global', 'context_class');
|
||||
if (!is_a($context_class, ContextInterface::class, true)) {
|
||||
throw new ZMKnownException('E00032', 'Context class must implemented from ContextInterface!');
|
||||
}
|
||||
//加载插件
|
||||
// 加载插件
|
||||
$obb_onebot = ZMConfig::get('global', 'onebot') ??
|
||||
ZMConfig::get('global', 'modules')['onebot'] ??
|
||||
['status' => true, 'single_bot_mode' => false, 'message_level' => 99999];
|
||||
@ -251,7 +251,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
if (!empty($real_conf)) {
|
||||
Console::info('Connecting to MySQL pool');
|
||||
ob_start();
|
||||
phpinfo(); //这个phpinfo是有用的,不能删除
|
||||
phpinfo(); // 这个phpinfo是有用的,不能删除
|
||||
$str = ob_get_clean();
|
||||
$str = explode("\n", $str);
|
||||
foreach ($str as $v) {
|
||||
|
||||
@ -97,7 +97,7 @@ class Framework
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//定义常量
|
||||
// 定义常量
|
||||
include_once 'global_defines.php';
|
||||
|
||||
try {
|
||||
@ -144,9 +144,9 @@ class Framework
|
||||
$this->server_set['log_level'] = SWOOLE_LOG_DEBUG;
|
||||
$add_port = ZMConfig::get('global', 'remote_terminal')['status'] ?? false;
|
||||
|
||||
//if ($instant_mode) {
|
||||
// if ($instant_mode) {
|
||||
$this->loadServerEvents();
|
||||
//}
|
||||
// }
|
||||
|
||||
$this->parseCliArgs(self::$argv, $add_port);
|
||||
|
||||
@ -288,7 +288,7 @@ class Framework
|
||||
|
||||
$port->on('close', function ($serv, $fd) {
|
||||
ManagerGM::popConnect($fd);
|
||||
//echo "Client: Close.\n";
|
||||
// echo "Client: Close.\n";
|
||||
});
|
||||
}
|
||||
|
||||
@ -301,9 +301,9 @@ class Framework
|
||||
// 注册 Swoole Server 的事件
|
||||
$this->registerServerEvents();
|
||||
$r = ZMConfig::get('global', 'light_cache') ?? [
|
||||
'size' => 512, //最多允许储存的条数(需要2的倍数)
|
||||
'max_strlen' => 32768, //单行字符串最大长度(需要2的倍数)
|
||||
'hash_conflict_proportion' => 0.6, //Hash冲突率(越大越好,但是需要的内存更多)
|
||||
'size' => 512, // 最多允许储存的条数(需要2的倍数)
|
||||
'max_strlen' => 32768, // 单行字符串最大长度(需要2的倍数)
|
||||
'hash_conflict_proportion' => 0.6, // Hash冲突率(越大越好,但是需要的内存更多)
|
||||
'persistence_path' => DataProvider::getDataFolder() . '_cache.json',
|
||||
'auto_save_interval' => 900,
|
||||
];
|
||||
@ -520,13 +520,13 @@ class Framework
|
||||
if (!isset($line_width[$current_line])) {
|
||||
$line_width[$current_line] = $max_border - 2;
|
||||
}
|
||||
//Console::info("行宽[$current_line]:".$line_width[$current_line]);
|
||||
// Console::info("行宽[$current_line]:".$line_width[$current_line]);
|
||||
if ($max_border >= 57) { // 很宽的时候,一行能放两个短行
|
||||
if ($line_width[$current_line] == ($max_border - 2)) { //空行
|
||||
if ($line_width[$current_line] == ($max_border - 2)) { // 空行
|
||||
self::writeNoDouble($k, $v, $line_data, $line_width, $current_line, $colorful, $max_border);
|
||||
} else { // 不是空行,已经有东西了
|
||||
$tmp_line = $k . ': ' . $v;
|
||||
//Console::info("[$current_line]即将插入后面的东西[".$tmp_line."]");
|
||||
// Console::info("[$current_line]即将插入后面的东西[".$tmp_line."]");
|
||||
if (strlen($tmp_line) > $line_width[$current_line]) { // 地方不够,另起一行
|
||||
$line_data[$current_line] = str_replace('| ', '', $line_data[$current_line]);
|
||||
++$current_line;
|
||||
@ -725,8 +725,8 @@ class Framework
|
||||
break;
|
||||
case 'show-php-ver':
|
||||
default:
|
||||
//Console::info("Calculating ".$x);
|
||||
//dump($y);
|
||||
// Console::info("Calculating ".$x);
|
||||
// dump($y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -742,8 +742,8 @@ class Framework
|
||||
private static function writeNoDouble($k, $v, &$line_data, &$line_width, &$current_line, $colorful, $max_border)
|
||||
{
|
||||
$tmp_line = $k . ': ' . $v;
|
||||
//Console::info("写入[".$tmp_line."]");
|
||||
if (strlen($tmp_line) > $line_width[$current_line]) { //输出的内容太多了,以至于一行都放不下一个,要折行
|
||||
// Console::info("写入[".$tmp_line."]");
|
||||
if (strlen($tmp_line) > $line_width[$current_line]) { // 输出的内容太多了,以至于一行都放不下一个,要折行
|
||||
$title_strlen = strlen($k . ': ');
|
||||
$content_len = $line_width[$current_line] - $title_strlen;
|
||||
|
||||
@ -769,7 +769,7 @@ class Framework
|
||||
++$current_line;
|
||||
} while ($rest > $max_border - 2); // 循环,直到放完
|
||||
} else { // 不需要折行
|
||||
//Console::info("不需要折行");
|
||||
// Console::info("不需要折行");
|
||||
$line_data[$current_line] = ' ' . $k . ': ';
|
||||
if ($colorful) {
|
||||
$line_data[$current_line] .= TermColor::color8(32);
|
||||
@ -781,10 +781,10 @@ class Framework
|
||||
|
||||
if ($max_border >= 57) {
|
||||
if (strlen($tmp_line) >= intval(($max_border - 2) / 2)) { // 不需要折行,直接输出一个转下一行
|
||||
//Console::info("不需要折行,直接输出一个转下一行");
|
||||
// Console::info("不需要折行,直接输出一个转下一行");
|
||||
++$current_line;
|
||||
} else { // 输出很小,写到前面并分片
|
||||
//Console::info("输出很小,写到前面并分片");
|
||||
// Console::info("输出很小,写到前面并分片");
|
||||
$space = intval($max_border / 2) - 2 - strlen($tmp_line);
|
||||
$line_data[$current_line] .= str_pad('', $space);
|
||||
$line_data[$current_line] .= '| '; // 添加分片
|
||||
|
||||
@ -47,16 +47,16 @@ class QQBot
|
||||
}
|
||||
set_coroutine_params(['data' => $data]);
|
||||
if (isset($data['post_type'])) {
|
||||
//echo TermColor::ITALIC.json_encode($data, 128|256).TermColor::RESET.PHP_EOL;
|
||||
// echo TermColor::ITALIC.json_encode($data, 128|256).TermColor::RESET.PHP_EOL;
|
||||
ctx()->setCache('level', $level);
|
||||
//Console::debug("Calling CQ Event from fd=" . ctx()->getConnection()->getFd());
|
||||
// Console::debug("Calling CQ Event from fd=" . ctx()->getConnection()->getFd());
|
||||
if ($data['post_type'] != 'meta_event') {
|
||||
$r = $this->dispatchBeforeEvents($data, 'pre'); // before在这里执行,元事件不执行before为减少不必要的调试日志
|
||||
if ($r->store === 'block') {
|
||||
EventDispatcher::interrupt();
|
||||
}
|
||||
}
|
||||
//Console::warning("最上数据包:".json_encode($data));
|
||||
// Console::warning("最上数据包:".json_encode($data));
|
||||
}
|
||||
if (isset($data['echo']) || isset($data['post_type'])) {
|
||||
if (CoMessage::resumeByWS()) {
|
||||
@ -134,10 +134,10 @@ class QQBot
|
||||
*/
|
||||
private function dispatchEvents($data)
|
||||
{
|
||||
//Console::warning("最xia数据包:".json_encode($data));
|
||||
// Console::warning("最xia数据包:".json_encode($data));
|
||||
switch ($data['post_type']) {
|
||||
case 'message':
|
||||
//分发CQCommand事件
|
||||
// 分发CQCommand事件
|
||||
$dispatcher = new EventDispatcher(CQCommand::class);
|
||||
$dispatcher->setReturnFunction(function ($result) {
|
||||
if (is_string($result)) {
|
||||
@ -170,7 +170,7 @@ class QQBot
|
||||
}
|
||||
}
|
||||
|
||||
//分发CQMessage事件
|
||||
// 分发CQMessage事件
|
||||
$msg_dispatcher = new EventDispatcher(CQMessage::class);
|
||||
$msg_dispatcher->setRuleFunction(function ($v) {
|
||||
return ($v->message == '' || ($v->message == ctx()->getStringMessage()))
|
||||
@ -187,12 +187,12 @@ class QQBot
|
||||
$msg_dispatcher->dispatchEvents(ctx()->getMessage());
|
||||
return;
|
||||
case 'meta_event':
|
||||
//Console::success("当前数据包:".json_encode(ctx()->getData()));
|
||||
// Console::success("当前数据包:".json_encode(ctx()->getData()));
|
||||
$dispatcher = new EventDispatcher(CQMetaEvent::class);
|
||||
$dispatcher->setRuleFunction(function (CQMetaEvent $v) {
|
||||
return $v->meta_event_type == '' || ($v->meta_event_type != '' && $v->meta_event_type == ctx()->getData()['meta_event_type']);
|
||||
});
|
||||
//eval(BP);
|
||||
// eval(BP);
|
||||
$dispatcher->dispatchEvents(ctx()->getData());
|
||||
return;
|
||||
case 'notice':
|
||||
|
||||
@ -18,13 +18,13 @@ class LightCacheInside
|
||||
{
|
||||
try {
|
||||
self::createTable('wait_api', 3, 65536);
|
||||
self::createTable('connect', 3, 64); //用于存单机器人模式下的机器人fd的
|
||||
self::createTable('static_route', 64, 256); //用于存储
|
||||
self::createTable('connect', 3, 64); // 用于存单机器人模式下的机器人fd的
|
||||
self::createTable('static_route', 64, 256); // 用于存储
|
||||
self::createTable('light_array', 8, 512, 0.6);
|
||||
} catch (ZMException $e) {
|
||||
return false;
|
||||
} //用于存协程等待的状态内容的
|
||||
//self::createTable("worker_start", 2, 1024);//用于存启动服务器时的状态的
|
||||
} // 用于存协程等待的状态内容的
|
||||
// self::createTable("worker_start", 2, 1024);//用于存启动服务器时的状态的
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ class SpinLock
|
||||
|
||||
public static function lock(string $key)
|
||||
{
|
||||
while (($r = self::$kv_lock->incr($key, 'lock_num')) > 1) { //此资源已经被锁上了
|
||||
while (($r = self::$kv_lock->incr($key, 'lock_num')) > 1) { // 此资源已经被锁上了
|
||||
if (Coroutine::getCid() != -1) {
|
||||
System::sleep(self::$delay / 1000);
|
||||
} else {
|
||||
|
||||
@ -27,7 +27,7 @@ class CoroutinePool
|
||||
}
|
||||
go(function () use ($func, $name) {
|
||||
self::$cids[$name][] = Coroutine::getCid();
|
||||
//Console::debug("正在执行协程,当前协程池中有 " . count(self::$cids[$name]) . " 个正在运行的协程: ".implode(", ", self::$cids[$name]));
|
||||
// Console::debug("正在执行协程,当前协程池中有 " . count(self::$cids[$name]) . " 个正在运行的协程: ".implode(", ", self::$cids[$name]));
|
||||
$func();
|
||||
self::checkCids($name);
|
||||
});
|
||||
|
||||
@ -51,7 +51,7 @@ class RouteManager
|
||||
$route_name = ($tail === '' ? '' : '/') . $tail . '/{filename}';
|
||||
Console::debug('添加静态文件路由:' . $route_name);
|
||||
$route = new Route($route_name, ['_class' => RouteManager::class, '_method' => 'onStaticRoute']);
|
||||
//echo $path.PHP_EOL;
|
||||
// echo $path.PHP_EOL;
|
||||
LightCacheInside::set('static_route', $route->getPath(), $path);
|
||||
|
||||
self::$routes->add(md5($route_name), $route);
|
||||
|
||||
@ -77,7 +77,7 @@ class SignalListener
|
||||
});
|
||||
self::processKillerPrompt();
|
||||
}
|
||||
//Console::verbose("Interrupted in worker");
|
||||
// Console::verbose("Interrupted in worker");
|
||||
// do nothing
|
||||
});
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ class ZMUtil
|
||||
public static function getModInstance($class)
|
||||
{
|
||||
if (!isset(ZMBuf::$instance[$class])) {
|
||||
//Console::debug('Class instance $class not exist, so I created it.');
|
||||
// Console::debug('Class instance $class not exist, so I created it.');
|
||||
return ZMBuf::$instance[$class] = new $class();
|
||||
}
|
||||
return ZMBuf::$instance[$class];
|
||||
@ -92,7 +92,7 @@ class ZMUtil
|
||||
foreach ($files as $v) {
|
||||
$pathinfo = pathinfo($v);
|
||||
if (($pathinfo['extension'] ?? '') == 'php') {
|
||||
if ($rule === null) { //规则未设置回调时候,使用默认的识别过滤规则
|
||||
if ($rule === null) { // 规则未设置回调时候,使用默认的识别过滤规则
|
||||
/*if (substr(file_get_contents($dir . '/' . $v), 6, 6) == '#plain') {
|
||||
continue;
|
||||
}*/
|
||||
|
||||
@ -28,7 +28,7 @@ function getClassPath($class_name)
|
||||
{
|
||||
$dir = str_replace('\\', '/', $class_name);
|
||||
$dir2 = DataProvider::getSourceRootDir() . '/src/' . $dir . '.php';
|
||||
//echo "@@@".$dir2.PHP_EOL;
|
||||
// echo "@@@".$dir2.PHP_EOL;
|
||||
$dir2 = str_replace('\\', '/', $dir2);
|
||||
if (file_exists($dir2)) {
|
||||
return $dir2;
|
||||
@ -66,7 +66,7 @@ function explodeMsg($msg, $ban_comma = false): array
|
||||
{
|
||||
$msg = str_replace(' ', "\n", trim($msg));
|
||||
if (!$ban_comma) {
|
||||
//$msg = str_replace(",", "\n", $msg);
|
||||
// $msg = str_replace(",", "\n", $msg);
|
||||
$msg = str_replace("\t", "\n", $msg);
|
||||
}
|
||||
$msgs = explode("\n", $msg);
|
||||
@ -128,7 +128,7 @@ function split_explode($del, $str, $divide_en = false): array
|
||||
}
|
||||
}
|
||||
$str = implode($del, $str);
|
||||
//echo $str."\n";
|
||||
// echo $str."\n";
|
||||
$ls = [];
|
||||
foreach (explode($del, $str) as $v) {
|
||||
if (trim($v) == '') {
|
||||
@ -136,7 +136,7 @@ function split_explode($del, $str, $divide_en = false): array
|
||||
}
|
||||
$ls[] = $v;
|
||||
}
|
||||
//var_dump($ls);
|
||||
// var_dump($ls);
|
||||
return $ls == [] ? [''] : $ls;
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ function matchArgs($pattern, $context)
|
||||
$exp = explode('*', $pattern);
|
||||
$i = 0;
|
||||
foreach ($exp as $k => $v) {
|
||||
//echo "[MATCH$k] " . $v . PHP_EOL;
|
||||
// echo "[MATCH$k] " . $v . PHP_EOL;
|
||||
if ($v == '' && $k == 0) {
|
||||
continue;
|
||||
}
|
||||
@ -159,14 +159,14 @@ function matchArgs($pattern, $context)
|
||||
$v = '^EOL';
|
||||
}
|
||||
$cur_var = '';
|
||||
//echo mb_substr($context, $i) . "|" . $v . PHP_EOL;
|
||||
// echo mb_substr($context, $i) . "|" . $v . PHP_EOL;
|
||||
$ori = $i;
|
||||
while (($a = mb_substr($context, $i, mb_strlen($v))) != $v && $a != '') {
|
||||
$cur_var .= mb_substr($context, $i, 1);
|
||||
++$i;
|
||||
}
|
||||
if ($i != $ori || $k == 1 || $k == count($exp) - 1) {
|
||||
//echo $cur_var . PHP_EOL;
|
||||
// echo $cur_var . PHP_EOL;
|
||||
$result[] = $cur_var;
|
||||
}
|
||||
$i += mb_strlen($v);
|
||||
@ -194,11 +194,11 @@ function connectIs($type): bool
|
||||
function getAnnotations(): array
|
||||
{
|
||||
$s = debug_backtrace()[1];
|
||||
//echo json_encode($s, 128|256);
|
||||
// echo json_encode($s, 128|256);
|
||||
$list = [];
|
||||
foreach (EventManager::$events as $v) {
|
||||
foreach ($v as $vs) {
|
||||
//echo get_class($vs).": ".$vs->class." => ".$vs->method.PHP_EOL;
|
||||
// echo get_class($vs).": ".$vs->class." => ".$vs->method.PHP_EOL;
|
||||
if ($vs->class == $s['class'] && $vs->method == $s['function']) {
|
||||
$list[get_class($vs)][] = $vs;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user