34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
|
||
|
|
class WeChatGroupAdapter:
|
||
|
|
@staticmethod
|
||
|
|
def resolve_require_mention(config: dict[str, Any], chat_id: str) -> bool:
|
||
|
|
groups_config = config.get("groups", {})
|
||
|
|
chat_config = groups_config.get(chat_id, {})
|
||
|
|
return chat_config.get("require_mention", True)
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def resolve_group_agent(config: dict[str, Any], chat_id: str) -> str | None:
|
||
|
|
groups_config = config.get("groups", {})
|
||
|
|
chat_config = groups_config.get(chat_id, {})
|
||
|
|
return chat_config.get("agent_id")
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def list_configured_groups(config: dict[str, Any]) -> list[dict[str, Any]]:
|
||
|
|
groups_config = config.get("groups", {})
|
||
|
|
return [{"chat_id": chat_id, **chat_config} for chat_id, chat_config in groups_config.items()]
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def resolve_group_bindings(config: dict[str, Any], chat_id: str) -> dict[str, Any]:
|
||
|
|
groups_config = config.get("groups", {})
|
||
|
|
chat_config = groups_config.get(chat_id, {})
|
||
|
|
return {
|
||
|
|
"allow_from": chat_config.get("allow_from", []),
|
||
|
|
"agent_id": chat_config.get("agent_id"),
|
||
|
|
"require_mention": chat_config.get("require_mention", True),
|
||
|
|
"reply_mode": chat_config.get("reply_mode", "off"),
|
||
|
|
}
|