initial 2.0.0-b1 commit

This commit is contained in:
jerry
2020-11-08 19:40:16 +08:00
parent deab5fd921
commit 3b90bf6245
9 changed files with 79 additions and 37 deletions

View File

@@ -5,6 +5,7 @@ namespace ZM\Context;
use Co;
use Exception;
use Swoole\Http\Request;
use Swoole\WebSocket\Frame;
use swoole_server;
@@ -15,9 +16,6 @@ use ZM\Exception\InvalidArgumentException;
use ZM\Exception\WaitTimeoutException;
use ZM\Http\Response;
use ZM\API\ZMRobot;
use ZM\Store\LightCacheInside;
use ZM\Store\Lock\SpinLock;
use ZM\Store\ZMAtomic;
use ZM\Utils\CoMessage;
class Context implements ContextInterface
@@ -146,7 +144,11 @@ class Context implements ContextInterface
Console::debug("==== 开始等待输入 ====");
if ($prompt != "") $this->reply($prompt);
$r = CoMessage::yieldByWS($this->getData(), ["user_id", "self_id", "message_type", onebot_target_id_name($this->getMessageType())]);
try {
$r = CoMessage::yieldByWS($this->getData(), ["user_id", "self_id", "message_type", onebot_target_id_name($this->getMessageType())]);
} catch (Exception $e) {
$r = false;
}
if($r === false) {
throw new WaitTimeoutException($this, $timeout_prompt);
}
@@ -231,4 +233,6 @@ class Context implements ContextInterface
}
public function copy() { return self::$context[$this->cid]; }
public function getOption() { return self::getCache("match"); }
}

View File

@@ -114,4 +114,6 @@ interface ContextInterface
public function cloneFromParent();
public function copy();
public function getOption();
}

View File

@@ -134,10 +134,7 @@ class ServerEventHandler
foreach ($server->connections as $v) {
$server->close($v);
}
if (SqlPoolStorage::$sql_pool !== null) {
SqlPoolStorage::$sql_pool->close();
SqlPoolStorage::$sql_pool = null;
}
// 这里执行的是只需要执行一遍的代码,比如终端监听器和键盘监听器
/*if ($server->worker_id === 0) {
@@ -163,6 +160,10 @@ class ServerEventHandler
}*/
//TODO: 单独抽出来MySQL和Redis连接池
if (ZMConfig::get("global", "sql_config")["sql_host"] != "") {
if (SqlPoolStorage::$sql_pool !== null) {
SqlPoolStorage::$sql_pool->close();
SqlPoolStorage::$sql_pool = null;
}
Console::info("新建SQL连接池中");
ob_start();
phpinfo();
@@ -503,9 +504,9 @@ class ServerEventHandler
//加载插件
$plugins = ZMConfig::get("global", "modules") ?? [];
if (!isset($plugins["qqbot"])) $plugins["qqbot"] = true;
if (!isset($plugins["onebot"])) $plugins["onebot"] = true;
if ($plugins["qqbot"]) {
if ($plugins["onebot"]) {
$obj = new OnSwooleEvent();
$obj->class = QQBot::class;
$obj->method = 'handle';
@@ -516,7 +517,7 @@ class ServerEventHandler
}
//TODO: 编写加载外部插件的方式
//$this->loadExternalModules();
$this->loadExternalModules($plugins);
}
private function addWatcher($maindir, $fd) {
@@ -530,4 +531,11 @@ class ServerEventHandler
}
}
}
private function loadExternalModules($plugins) {
foreach ($plugins as $k => $v) {
if ($k == "onebot") continue;
}
}
}

View File

@@ -21,7 +21,7 @@ use ZM\Utils\CoMessage;
/**
* Class QQBot
* @package ZM\Module
* @ExternalModule("qqbot")
* @ExternalModule("onebot")
*/
class QQBot
{