mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 15:45:36 +08:00
update to build 420
This commit is contained in:
@@ -52,7 +52,7 @@ class ModulePackCommand extends Command
|
||||
$output->writeln("<error>不存在模块 ".$input->getArgument("module-name")." !</error>");
|
||||
return 1;
|
||||
}
|
||||
$result = ModuleManager::packModule($list[$input->getArgument("module-name")]);
|
||||
$result = ModuleManager::packModule($list[$input->getArgument("module-name")], $input->getOption("target"));
|
||||
if ($result) Console::success("打包完成!");
|
||||
else Console::error("打包失败!");
|
||||
return 0;
|
||||
|
||||
@@ -28,7 +28,7 @@ class ConsoleApplication extends Application
|
||||
{
|
||||
private static $obj = null;
|
||||
|
||||
const VERSION_ID = 419;
|
||||
const VERSION_ID = 420;
|
||||
const VERSION = "2.5.3";
|
||||
|
||||
/**
|
||||
|
||||
@@ -72,11 +72,13 @@ class EventDispatcher
|
||||
}
|
||||
|
||||
public function setRuleFunction(callable $rule = null): EventDispatcher {
|
||||
if ($this->log) Console::verbose("[事件分发{$this->eid}] 设置事件rule: " . $this->class);
|
||||
$this->rule = $rule;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setReturnFunction(callable $return_func): EventDispatcher {
|
||||
if ($this->log) Console::verbose("[事件分发{$this->eid}] 设置事件returnFunc: " . $this->class);
|
||||
$this->return_func = $return_func;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ class EventManager
|
||||
public static $req_mapping = [];
|
||||
|
||||
public static function addEvent($event_name, ?AnnotationBase $event_obj) {
|
||||
Console::debug("Adding event $event_name at ".$event_obj->class.":".$event_obj->method);
|
||||
self::$events[$event_name][] = $event_obj;
|
||||
(new AnnotationParser())->sortByLevel(self::$events, $event_name);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ use ZM\Event\SwooleEvent;
|
||||
*/
|
||||
class OnMessage implements SwooleEvent
|
||||
{
|
||||
/**
|
||||
* @noinspection PhpUnreachableStatementInspection
|
||||
*/
|
||||
public function onCall($server, Frame $frame) {
|
||||
Console::debug("Calling Swoole \"message\" from fd=" . $frame->fd . ": " . TermColor::ITALIC . $frame->data . TermColor::RESET);
|
||||
unset(Context::$context[Coroutine::getCid()]);
|
||||
@@ -32,8 +35,8 @@ class OnMessage implements SwooleEvent
|
||||
set_coroutine_params(["server" => $server, "frame" => $frame, "connection" => $conn]);
|
||||
$dispatcher1 = new EventDispatcher(OnMessageEvent::class);
|
||||
$dispatcher1->setRuleFunction(function ($v) {
|
||||
/** @noinspection PhpUnreachableStatementInspection */
|
||||
return ctx()->getConnection()->getName() == $v->connect_type && eval("return " . $v->getRule() . ";");
|
||||
if ($v->getRule() == '') return true;
|
||||
else return eval("return " . $v->getRule() . ";");
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ use Swoole\Database\PDOConfig;
|
||||
use Swoole\Process;
|
||||
use Swoole\Server;
|
||||
use ZM\Annotation\AnnotationParser;
|
||||
use ZM\Annotation\Swoole\OnMessageEvent;
|
||||
use ZM\Annotation\Swoole\OnStart;
|
||||
use ZM\Annotation\Swoole\OnSwooleEvent;
|
||||
use ZM\Annotation\Swoole\SwooleHandler;
|
||||
@@ -157,21 +158,7 @@ class OnWorkerStart implements SwooleEvent
|
||||
ZMConfig::get("global", "modules")["onebot"] ??
|
||||
["status" => true, "single_bot_mode" => false, "message_level" => 99999];
|
||||
|
||||
if ($obb_onebot["status"]) {
|
||||
Console::debug("OneBot support enabled, listening OneBot event(3).");
|
||||
$obj = new OnSwooleEvent();
|
||||
$obj->class = QQBot::class;
|
||||
$obj->method = 'handleByEvent';
|
||||
$obj->type = 'message';
|
||||
$obj->level = $obb_onebot["message_level"] ?? 99999;
|
||||
$obj->rule = 'connectIsQQ()';
|
||||
EventManager::addEvent(OnSwooleEvent::class, $obj);
|
||||
if ($obb_onebot["single_bot_mode"]) {
|
||||
LightCacheInside::set("connect", "conn_fd", -1);
|
||||
} else {
|
||||
LightCacheInside::set("connect", "conn_fd", -2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 检查是否允许热加载phar模块,允许的话将遍历phar内的文件
|
||||
$plugin_enable_hotload = ZMConfig::get("global", "module_loader")["enable_hotload"] ?? false;
|
||||
@@ -188,6 +175,22 @@ class OnWorkerStart implements SwooleEvent
|
||||
|
||||
$parser->registerMods();
|
||||
EventManager::loadEventByParser($parser); //加载事件
|
||||
|
||||
if ($obb_onebot["status"]) {
|
||||
Console::debug("OneBot support enabled, listening OneBot event(3).");
|
||||
$obj = new OnMessageEvent();
|
||||
$obj->class = QQBot::class;
|
||||
$obj->method = 'handleByEvent';
|
||||
$obj->level = $obb_onebot["message_level"] ?? 99999;
|
||||
$obj->rule = 'connectIsQQ()';
|
||||
EventManager::addEvent(OnMessageEvent::class, $obj);
|
||||
zm_dump(EventManager::$events[OnMessageEvent::class]);
|
||||
if ($obb_onebot["single_bot_mode"]) {
|
||||
LightCacheInside::set("connect", "conn_fd", -1);
|
||||
} else {
|
||||
LightCacheInside::set("connect", "conn_fd", -2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function initMySQLPool() {
|
||||
|
||||
@@ -54,6 +54,7 @@ class ModulePacker
|
||||
*/
|
||||
public function setOutputPath($path) {
|
||||
$this->output_path = $path;
|
||||
if (!is_dir($path)) mkdir($path, 0755, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user