49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import logging
|
||
|
|
from dataclasses import dataclass
|
||
|
|
|
||
|
|
logger = logging.getLogger(__name__)
|
||
|
|
|
||
|
|
PLUGIN_VERSION = "1.0.0"
|
||
|
|
OPENCLAW_VERSION = "1.0.0"
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class SenderInfo:
|
||
|
|
plugin_version: str = PLUGIN_VERSION
|
||
|
|
openclaw_version: str = OPENCLAW_VERSION
|
||
|
|
channel_id: str = "qqbot"
|
||
|
|
user_agent: str = ""
|
||
|
|
|
||
|
|
def __post_init__(self):
|
||
|
|
self.user_agent = f"openclaw-qqbot/{self.plugin_version} openclaw/{self.openclaw_version}"
|
||
|
|
|
||
|
|
|
||
|
|
def init_sender(
|
||
|
|
plugin_version: str = PLUGIN_VERSION,
|
||
|
|
openclaw_version: str = OPENCLAW_VERSION,
|
||
|
|
) -> SenderInfo:
|
||
|
|
info = SenderInfo(
|
||
|
|
plugin_version=plugin_version,
|
||
|
|
openclaw_version=openclaw_version,
|
||
|
|
)
|
||
|
|
logger.info(
|
||
|
|
"Sender initialized: plugin=%s openclaw=%s ua=%s",
|
||
|
|
info.plugin_version,
|
||
|
|
info.openclaw_version,
|
||
|
|
info.user_agent,
|
||
|
|
)
|
||
|
|
return info
|
||
|
|
|
||
|
|
|
||
|
|
def build_sender_headers(info: SenderInfo, extra: dict | None = None) -> dict:
|
||
|
|
headers = {
|
||
|
|
"User-Agent": info.user_agent,
|
||
|
|
"X-Plugin-Version": info.plugin_version,
|
||
|
|
"X-OpenClaw-Version": info.openclaw_version,
|
||
|
|
}
|
||
|
|
if extra:
|
||
|
|
headers.update(extra)
|
||
|
|
return headers
|