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

47 lines
1.2 KiB
Python
Raw Normal View History

from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from .adapter import WeChatAdapter
WECHAT_RELOAD_CONFIG = {
"configPrefixes": [
"channels.wechat",
"plugins.entries.wechat",
],
"noopPrefixes": [
"channels.wechat.logLevel",
],
}
class WeChatConfigReloader:
def __init__(self, adapter: WeChatAdapter):
self._adapter = adapter
self._watched_prefixes = list(WECHAT_RELOAD_CONFIG["configPrefixes"])
self._noop_prefixes = list(WECHAT_RELOAD_CONFIG["noopPrefixes"])
def should_reload(self, changed_keys: list[str]) -> bool:
for key in changed_keys:
for prefix in self._watched_prefixes:
if key.startswith(prefix):
for noop in self._noop_prefixes:
if key.startswith(noop):
return False
return True
return False
async def reload(self) -> None:
await self._adapter.disconnect()
await self._adapter.connect()
@property
def watched_prefixes(self) -> list[str]:
return list(self._watched_prefixes)
@property
def noop_prefixes(self) -> list[str]:
return list(self._noop_prefixes)