mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-02-20 07:07:50 +08:00
修复部分 lint
This commit is contained in:
parent
0e72880167
commit
0b6ac9f73e
@ -1,4 +1,3 @@
|
||||
import shutil
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
|
||||
@ -81,15 +80,15 @@ destination_folder = Path("config/marshoai/")
|
||||
destination_file = destination_folder / "config.yaml"
|
||||
|
||||
|
||||
def dump_config_to_yaml(config: ConfigModel):
|
||||
return yaml_.dump(config.model_dump(), allow_unicode=True, default_flow_style=False)
|
||||
def dump_config_to_yaml(cfg: ConfigModel):
|
||||
return yaml_.dump(cfg.model_dump(), allow_unicode=True, default_flow_style=False)
|
||||
|
||||
|
||||
def write_default_config(destination_file):
|
||||
def write_default_config(dest_file):
|
||||
"""
|
||||
写入默认配置
|
||||
"""
|
||||
with open(destination_file, "w", encoding="utf-8") as f:
|
||||
with open(dest_file, "w", encoding="utf-8") as f:
|
||||
with StringIO(dump_config_to_yaml(ConfigModel())) as f2:
|
||||
f.write(f2.read())
|
||||
|
||||
@ -110,17 +109,17 @@ def check_yaml_is_changed():
|
||||
return True
|
||||
|
||||
|
||||
def merge_configs(old_config, new_config):
|
||||
def merge_configs(existing_cfg, new_cfg):
|
||||
"""
|
||||
合并配置文件
|
||||
"""
|
||||
for key, value in new_config.items():
|
||||
if key in old_config:
|
||||
for key, value in new_cfg.items():
|
||||
if key in existing_cfg:
|
||||
continue
|
||||
else:
|
||||
logger.info(f"新增配置项: {key} = {value}")
|
||||
old_config[key] = value
|
||||
return old_config
|
||||
existing_cfg[key] = value
|
||||
return existing_cfg
|
||||
|
||||
|
||||
config: ConfigModel = get_plugin_config(ConfigModel)
|
||||
|
@ -1,6 +1,4 @@
|
||||
# Marsho 的类实例以及全局变量
|
||||
from azure.ai.inference.aio import ChatCompletionsClient
|
||||
from azure.core.credentials import AzureKeyCredential
|
||||
from nonebot import get_driver
|
||||
from openai import AsyncOpenAI
|
||||
|
||||
|
@ -2,7 +2,6 @@ import contextlib
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
import openai
|
||||
from arclet.alconna import Alconna, AllParam, Args
|
||||
from azure.ai.inference.models import (
|
||||
AssistantMessage,
|
||||
@ -18,10 +17,11 @@ from nonebot.adapters import Bot, Event, Message
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import CommandArg
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.rule import Rule, to_me
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.typing import T_State
|
||||
from nonebot_plugin_alconna import MsgTarget, UniMessage, UniMsg, on_alconna
|
||||
|
||||
from .constants import INTRODUCTION, OPENAI_NEW_MODELS, SUPPORT_IMAGE_MODELS
|
||||
from .hooks import *
|
||||
from .instances import *
|
||||
from .metadata import metadata
|
||||
|
@ -9,7 +9,6 @@ import traceback
|
||||
from nonebot import logger
|
||||
|
||||
from .config import config
|
||||
from .util import *
|
||||
|
||||
|
||||
class MarshoContext:
|
||||
|
@ -21,12 +21,12 @@ from zhDateTime import DateTime
|
||||
|
||||
from ._types import DeveloperMessage
|
||||
from .config import config
|
||||
from .constants import *
|
||||
from .constants import CODE_BLOCK_PATTERN, IMG_LATEX_PATTERN, OPENAI_NEW_MODELS
|
||||
from .deal_latex import ConvertLatex
|
||||
|
||||
nickname_json = None # 记录昵称
|
||||
praises_json = None # 记录夸赞名单
|
||||
loaded_target_list = [] # 记录已恢复备份的上下文的列表
|
||||
loaded_target_list: List[str] = [] # 记录已恢复备份的上下文的列表
|
||||
|
||||
NOT_GIVEN = NotGiven()
|
||||
|
||||
@ -219,7 +219,7 @@ async def get_nicknames():
|
||||
try:
|
||||
async with aiofiles.open(filename, "r", encoding="utf-8") as f:
|
||||
nickname_json = json.loads(await f.read())
|
||||
except Exception:
|
||||
except (json.JSONDecodeError, FileNotFoundError):
|
||||
nickname_json = {}
|
||||
return nickname_json
|
||||
|
||||
@ -249,7 +249,7 @@ async def refresh_nickname_json():
|
||||
store.get_plugin_data_file("nickname.json"), "r", encoding="utf-8"
|
||||
) as f:
|
||||
nickname_json = json.loads(await f.read())
|
||||
except Exception:
|
||||
except (json.JSONDecodeError, FileNotFoundError):
|
||||
logger.error("刷新 nickname_json 表错误:无法载入 nickname.json 文件")
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user