prerelease of beta1

This commit is contained in:
crazywhalecc
2022-12-20 20:10:40 +08:00
parent 04247048d4
commit c9bf0fb13c
16 changed files with 585 additions and 43 deletions

View File

@@ -6,11 +6,11 @@ use OneBot\Driver\Coroutine\Adaptive;
use OneBot\Driver\Coroutine\CoroutineInterface;
use OneBot\Driver\Process\ExecutionResult;
use OneBot\V12\Object\MessageSegment;
use OneBot\V12\Object\OneBotEvent;
use Psr\Log\LoggerInterface;
use ZM\Config\ZMConfig;
use ZM\Container\Container;
use ZM\Container\ContainerInterface;
use ZM\Context\Context;
use ZM\Logger\ConsoleLogger;
use ZM\Middleware\MiddlewareHandler;
use ZM\Store\Database\DBException;
@@ -68,6 +68,9 @@ function zm_internal_errcode(int|string $code): string
return "[ErrCode:{$code}] ";
}
/**
* 返回当前炸毛实例的 ID
*/
function zm_instance_id(): string
{
if (defined('ZM_INSTANCE_ID')) {
@@ -101,11 +104,6 @@ function is_assoc_array(array $array): bool
return !empty($array) && array_keys($array) !== range(0, count($array) - 1);
}
function ctx(): Context
{
return \container()->get('ctx');
}
/**
* 构建消息段的助手函数
*
@@ -208,3 +206,13 @@ function config(array|string $key = null, mixed $default = null)
}
return $config->get($key, $default);
}
function bot(): ZM\Context\BotContext
{
if (\container()->has('bot.event')) {
/** @var OneBotEvent $bot_event */
$bot_event = \container()->get('bot.event');
return new \ZM\Context\BotContext($bot_event->self['user_id'] ?? '', $bot_event->self['platform']);
}
return new \ZM\Context\BotContext('', '');
}