mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-18 13:14:52 +08:00
Merge pull request #211 from zhamao-robot/fix-bot-context-not-sync
修复 BotContext 不同步问题
This commit is contained in:
commit
8473a1152d
@ -6,7 +6,6 @@ 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\ContainerHolder;
|
||||
@ -241,10 +240,8 @@ function config(array|string $key = null, mixed $default = null)
|
||||
|
||||
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']);
|
||||
if (container()->has(ZM\Context\BotContext::class)) {
|
||||
return container()->get(ZM\Context\BotContext::class);
|
||||
}
|
||||
return new \ZM\Context\BotContext('', '');
|
||||
}
|
||||
|
||||
@ -26,8 +26,16 @@ class ContainerRegistrant
|
||||
self::addServices([
|
||||
OneBotEvent::class => $event,
|
||||
'bot.event' => DI\get(OneBotEvent::class),
|
||||
BotContext::class => fn () => bot(),
|
||||
]);
|
||||
|
||||
if (isset($event->self['platform'])) {
|
||||
self::addServices([
|
||||
BotContext::class => DI\autowire(BotContext::class)->constructor(
|
||||
$event->self['user_id'] ?? '',
|
||||
$event->self['platform'],
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user