删除yaml配置,使用toml进行配置
This commit is contained in:
@@ -6,4 +6,9 @@ command-format = """
|
||||
设置京东 token内容 备注名称
|
||||
token内容示例:pt_key=xxx; pt_pin=xxx;
|
||||
通过m.jd.com登录,F12查看请求中的cookie获得
|
||||
"""
|
||||
"""
|
||||
|
||||
# 青龙面板配置
|
||||
QL_HOST= "http://192.168.2.32:5800" # 青龙面板地址,请根据实际情况修改
|
||||
CLIENT_ID= "g_jH014_iQhW" # 青龙面板应用ID,请填写实际值
|
||||
CLIENT_SECRET= "lSRhT-1Xs0lOEZ5YfKMMCkbl" # 青龙面板应用密钥,请填写实际值
|
||||
@@ -1,4 +0,0 @@
|
||||
# 青龙面板配置
|
||||
QL_HOST: "http://192.168.2.32:5800" # 青龙面板地址,请根据实际情况修改
|
||||
CLIENT_ID: "g_jH014_iQhW" # 青龙面板应用ID,请填写实际值
|
||||
CLIENT_SECRET: "lSRhT-1Xs0lOEZ5YfKMMCkbl" # 青龙面板应用密钥,请填写实际值
|
||||
@@ -2,7 +2,6 @@ from loguru import logger
|
||||
import requests
|
||||
import re
|
||||
import os
|
||||
import yaml
|
||||
from json import dumps as jsonDumps
|
||||
from typing import Dict, Any, List, Optional, Tuple
|
||||
|
||||
@@ -145,8 +144,6 @@ class JDTokenPlugin(MessagePluginInterface):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.plugin_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
self.config_path = os.path.join(self.plugin_dir, "config.yaml")
|
||||
|
||||
def initialize(self, context: Dict[str, Any]) -> bool:
|
||||
"""初始化插件"""
|
||||
@@ -157,33 +154,22 @@ class JDTokenPlugin(MessagePluginInterface):
|
||||
self.event_system = context.get("event_system")
|
||||
self.message_util = context.get("message_util")
|
||||
|
||||
# 从TOML配置文件加载配置
|
||||
self._commands = self._config.get("JD_Token", {}).get("command", ["设置京东"])
|
||||
self.command_format = self._config.get("JD_Token", {}).get("command-format", "设置京东 token内容 备注名称")
|
||||
self.enable = self._config.get("JD_Token", {}).get("enable", True)
|
||||
|
||||
# 加载青龙面板配置
|
||||
self.load_config()
|
||||
self.ql = QL(self.ql_config.get("QL_HOST"), self.ql_config.get("CLIENT_ID"), self.ql_config.get("CLIENT_SECRET"))
|
||||
|
||||
# 从TOML配置文件加载青龙面板配置
|
||||
ql_host = self._config.get("JD_Token", {}).get("QL_HOST", "http://localhost:5700")
|
||||
client_id = self._config.get("JD_Token", {}).get("CLIENT_ID", "")
|
||||
client_secret = self._config.get("JD_Token", {}).get("CLIENT_SECRET", "")
|
||||
|
||||
# 初始化青龙面板连接
|
||||
self.ql = QL(ql_host, client_id, client_secret)
|
||||
|
||||
self.LOG.info(f"[{self.name}] 插件初始化完成,指令:{self._commands}")
|
||||
return True
|
||||
|
||||
def load_config(self):
|
||||
"""加载配置"""
|
||||
if os.path.exists(self.config_path):
|
||||
with open(self.config_path, 'r', encoding='utf-8') as f:
|
||||
self.ql_config = yaml.safe_load(f)
|
||||
else:
|
||||
# 默认配置
|
||||
self.ql_config = {
|
||||
"QL_HOST": "http://localhost:5700",
|
||||
"CLIENT_ID": "",
|
||||
"CLIENT_SECRET": ""
|
||||
}
|
||||
# 保存默认配置
|
||||
with open(self.config_path, 'w', encoding='utf-8') as f:
|
||||
yaml.dump(self.ql_config, f, default_flow_style=False, allow_unicode=True)
|
||||
|
||||
def start(self) -> bool:
|
||||
"""启动插件"""
|
||||
self.LOG.info(f"[{self.name}] 插件已启动")
|
||||
@@ -207,6 +193,7 @@ class JDTokenPlugin(MessagePluginInterface):
|
||||
return command in self._commands
|
||||
|
||||
@plugin_stats_decorator(plugin_name="京东签到Token设置")
|
||||
@plugin_points_cost(2, "京东签到Token设置消耗积分", Feature.UTILITY)
|
||||
async def process_message(self, message: Dict[str, Any]) -> Tuple[bool, Optional[str]]:
|
||||
"""处理消息"""
|
||||
content = str(message.get("content", "")).strip()
|
||||
|
||||
Reference in New Issue
Block a user