mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-24 00:55:35 +08:00
Merge pull request #211 from zhamao-robot/fix-bot-context-not-sync
修复 BotContext 不同步问题
This commit is contained in:
@@ -6,7 +6,6 @@ use OneBot\Driver\Coroutine\Adaptive;
|
|||||||
use OneBot\Driver\Coroutine\CoroutineInterface;
|
use OneBot\Driver\Coroutine\CoroutineInterface;
|
||||||
use OneBot\Driver\Process\ExecutionResult;
|
use OneBot\Driver\Process\ExecutionResult;
|
||||||
use OneBot\V12\Object\MessageSegment;
|
use OneBot\V12\Object\MessageSegment;
|
||||||
use OneBot\V12\Object\OneBotEvent;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use ZM\Config\ZMConfig;
|
use ZM\Config\ZMConfig;
|
||||||
use ZM\Container\ContainerHolder;
|
use ZM\Container\ContainerHolder;
|
||||||
@@ -241,10 +240,8 @@ function config(array|string $key = null, mixed $default = null)
|
|||||||
|
|
||||||
function bot(): ZM\Context\BotContext
|
function bot(): ZM\Context\BotContext
|
||||||
{
|
{
|
||||||
if (\container()->has('bot.event')) {
|
if (container()->has(ZM\Context\BotContext::class)) {
|
||||||
/** @var OneBotEvent $bot_event */
|
return container()->get(ZM\Context\BotContext::class);
|
||||||
$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('', '');
|
return new \ZM\Context\BotContext('', '');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,16 @@ class ContainerRegistrant
|
|||||||
self::addServices([
|
self::addServices([
|
||||||
OneBotEvent::class => $event,
|
OneBotEvent::class => $event,
|
||||||
'bot.event' => DI\get(OneBotEvent::class),
|
'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'],
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user