mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2024-11-23 09:37:37 +08:00
⚡ 修复错误的依赖, 添加refresh_data用于手动刷新数据
This commit is contained in:
parent
625603105c
commit
45d25b90aa
@ -48,6 +48,7 @@ nickname_cmd = on_alconna(
|
|||||||
Args["name?", str],
|
Args["name?", str],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
refresh_data = on_alconna("refresh_data", permission=SUPERUSER)
|
||||||
model_name = config.marshoai_default_model
|
model_name = config.marshoai_default_model
|
||||||
context = MarshoContext()
|
context = MarshoContext()
|
||||||
token = config.marshoai_token
|
token = config.marshoai_token
|
||||||
@ -127,6 +128,10 @@ async def nickname(event: Event, name=None):
|
|||||||
await set_nickname(user_id, name)
|
await set_nickname(user_id, name)
|
||||||
await nickname_cmd.finish("已设置昵称为:" + name)
|
await nickname_cmd.finish("已设置昵称为:" + name)
|
||||||
|
|
||||||
|
@refresh_data.handle()
|
||||||
|
async def refresh_data():
|
||||||
|
await refresh_nickname_json()
|
||||||
|
await refresh_data.finish("已刷新数据")
|
||||||
|
|
||||||
@marsho_cmd.handle()
|
@marsho_cmd.handle()
|
||||||
async def marsho(target: MsgTarget, event: Event, text: Optional[UniMsg] = None):
|
async def marsho(target: MsgTarget, event: Event, text: Optional[UniMsg] = None):
|
||||||
|
@ -7,7 +7,7 @@ import httpx
|
|||||||
import nonebot_plugin_localstore as store
|
import nonebot_plugin_localstore as store
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from cashews.backends.redis.client_side import logger
|
from nonebot.log import logger
|
||||||
from zhDateTime import DateTime # type: ignore
|
from zhDateTime import DateTime # type: ignore
|
||||||
from azure.ai.inference.aio import ChatCompletionsClient
|
from azure.ai.inference.aio import ChatCompletionsClient
|
||||||
from azure.ai.inference.models import SystemMessage
|
from azure.ai.inference.models import SystemMessage
|
||||||
@ -110,6 +110,7 @@ async def set_nickname(user_id: str, name: str):
|
|||||||
|
|
||||||
|
|
||||||
async def get_nicknames():
|
async def get_nicknames():
|
||||||
|
'''获取nickname_json, 优先来源于全局变量'''
|
||||||
global nickname_json
|
global nickname_json
|
||||||
if nickname_json is None:
|
if nickname_json is None:
|
||||||
filename = store.get_plugin_data_file("nickname.json")
|
filename = store.get_plugin_data_file("nickname.json")
|
||||||
@ -120,6 +121,16 @@ async def get_nicknames():
|
|||||||
nickname_json = {}
|
nickname_json = {}
|
||||||
return nickname_json
|
return nickname_json
|
||||||
|
|
||||||
|
async def refresh_nickname_json():
|
||||||
|
'''强制刷新nickname_json, 刷新全局变量'''
|
||||||
|
global nickname_json
|
||||||
|
filename = store.get_plugin_data_file("nickname.json")
|
||||||
|
try:
|
||||||
|
with open(filename, "r", encoding="utf-8") as f:
|
||||||
|
nickname_json = json.load(f)
|
||||||
|
except Exception:
|
||||||
|
logger.error("Error loading nickname.json")
|
||||||
|
|
||||||
|
|
||||||
def get_prompt():
|
def get_prompt():
|
||||||
prompts = ""
|
prompts = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user