新增大量渠道适配器相关的协议、策略、工具类与基础设施代码,包括: 1. 多协议定义:认证、消息、配置、网关等核心接口 2. 策略模块:上下文、群聊、去重、防抖等业务策略 3. 工具集:重试、去重、文本分块、消息格式化等SDK工具 4. 基础设施:外部进程管理、事件广播、熔断机制等 5. 账户与管道系统:账户管理、消息处理管道实现 6. 运行时服务:状态收集、维护任务、日志等后台服务
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from collections import defaultdict
|
|
from typing import TYPE_CHECKING
|
|
|
|
from yuxi.utils.logging_config import logger
|
|
|
|
if TYPE_CHECKING:
|
|
from yuxi.channels.manager import ChannelManager
|
|
|
|
|
|
class WebhookRegistry:
|
|
def __init__(self, channel_manager: ChannelManager):
|
|
self._manager = channel_manager
|
|
self._registered: dict[str, list[str]] = defaultdict(list)
|
|
|
|
async def run(self, interval: float = 3600) -> None:
|
|
logger.info("WebhookRegistry started")
|
|
while True:
|
|
await asyncio.sleep(interval)
|
|
try:
|
|
await self._check_webhooks()
|
|
except asyncio.CancelledError:
|
|
break
|
|
except Exception:
|
|
logger.exception("WebhookRegistry error")
|
|
|
|
async def register_webhook(self, channel_id: str, url: str) -> None:
|
|
self._registered[channel_id].append(url)
|
|
logger.info(f"Webhook registered for {channel_id}: {url}")
|
|
|
|
async def _check_webhooks(self) -> None:
|
|
for channel_id in self._registered:
|
|
logger.debug(f"Webhook check for {channel_id}: {len(self._registered[channel_id])} registered")
|