feat: 新增跨平台消息互通插件及适配器优化
refactor(discord_adapter): 优化音频处理与心跳机制 feat(plugins/discord-cross): 实现QQ与Discord消息互通功能 fix(events/base): 添加platform字段到基础事件模型
This commit is contained in:
61
plugins/discord-cross/config.py
Normal file
61
plugins/discord-cross/config.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
跨平台消息互通插件配置模块
|
||||
"""
|
||||
import os
|
||||
from typing import Dict, Any
|
||||
from core.utils.logger import logger
|
||||
|
||||
class CrossPlatformConfig:
|
||||
def __init__(self):
|
||||
self.CROSS_PLATFORM_MAP: Dict[int, Dict[str, Any]] = {}
|
||||
self.CROSS_PLATFORM_CHANNEL = "neobot_cross_platform"
|
||||
self.ENABLE_CROSS_PLATFORM = True
|
||||
|
||||
# DeepSeek API 配置
|
||||
self.DEEPSEEK_API_KEY = "sk-Cn4BeHyTHDPRKuDadLy6dUnjSSHxrz5wQa54ZFAdQovXguLD"
|
||||
self.DEEPSEEK_API_URL = "https://api.gptgod.online/v1/chat/completions"
|
||||
self.DEEPSEEK_MODEL = "gemini-3-flash-preview"
|
||||
|
||||
# 是否启用翻译功能
|
||||
self.ENABLE_TRANSLATION = True
|
||||
|
||||
async def reload(self):
|
||||
"""重新加载配置"""
|
||||
try:
|
||||
config_path = os.path.join(os.path.dirname(__file__), "..", "..", "config.toml")
|
||||
|
||||
if os.path.exists(config_path):
|
||||
try:
|
||||
import tomllib
|
||||
except ImportError:
|
||||
import tomli as tomllib
|
||||
|
||||
with open(config_path, "rb") as f:
|
||||
config_data = tomllib.load(f)
|
||||
|
||||
cross_platform_config = config_data.get("cross_platform", {})
|
||||
self.ENABLE_CROSS_PLATFORM = cross_platform_config.get("enabled", True)
|
||||
|
||||
# 重新加载映射配置
|
||||
mappings = cross_platform_config.get("mappings", {})
|
||||
self.CROSS_PLATFORM_MAP.clear()
|
||||
|
||||
if isinstance(mappings, dict) and mappings:
|
||||
for key, value in mappings.items():
|
||||
if isinstance(value, dict) and "qq_group_id" in value:
|
||||
try:
|
||||
discord_id = int(key) if str(key).isdigit() else int(str(key).split('.')[-1])
|
||||
self.CROSS_PLATFORM_MAP[discord_id] = {
|
||||
"qq_group_id": int(value.get("qq_group_id", 0)),
|
||||
"name": value.get("name", "")
|
||||
}
|
||||
except (ValueError, AttributeError):
|
||||
continue
|
||||
|
||||
logger.success(f"[CrossPlatform] 配置已重新加载: {len(self.CROSS_PLATFORM_MAP)} 个映射")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[CrossPlatform] 重新加载配置失败: {e}")
|
||||
|
||||
config = CrossPlatformConfig()
|
||||
Reference in New Issue
Block a user