ForcePilot/backend/package/yuxi/channels/adapters/wechat/dual_plugin.py

48 lines
1.7 KiB
Python
Raw Normal View History

from __future__ import annotations
from typing import Any
from yuxi.utils.logging_config import logger
class WeChatAccountPlugin:
plugin_id: str = "wechat-account"
plugin_type: str = "account"
def __init__(self, config: dict[str, Any] | None = None):
self._config = config or {}
async def register(self, registry: Any) -> None:
logger.info("[WeChat/AccountPlugin] Registering WeChat account plugin")
async def unregister(self, registry: Any) -> None:
logger.info("[WeChat/AccountPlugin] Unregistering WeChat account plugin")
def detect_legacy_state_migrations(self, old_config: dict[str, Any]) -> dict[str, Any]:
migrated = dict(old_config)
if "wechat_token" in migrated:
migrated.setdefault("corp_secret", migrated.pop("wechat_token"))
logger.info("[WeChat/AccountPlugin] Migrated legacy wechat_token to corp_secret")
return migrated
class WeChatSetupPlugin:
plugin_id: str = "wechat-setup"
plugin_type: str = "setup"
def __init__(self, config: dict[str, Any] | None = None):
self._config = config or {}
async def register(self, registry: Any) -> None:
logger.info("[WeChat/SetupPlugin] Registering WeChat setup plugin")
async def unregister(self, registry: Any) -> None:
logger.info("[WeChat/SetupPlugin] Unregistering WeChat setup plugin")
def detect_legacy_state_migrations(self, old_config: dict[str, Any]) -> dict[str, Any]:
migrated = dict(old_config)
if "encoding_aes_key" not in migrated and "aes_key" in migrated:
migrated["encoding_aes_key"] = migrated.pop("aes_key")
logger.info("[WeChat/SetupPlugin] Migrated legacy aes_key to encoding_aes_key")
return migrated