mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-02-12 15:39:58 +08:00
⚡ 更新少量文档, 减少夸赞名单文件开启次数
This commit is contained in:
parent
17f19dc1ce
commit
625603105c
@ -86,7 +86,7 @@ _✨ 使用 Azure OpenAI 推理服务的聊天机器人插件 ✨_
|
|||||||
|
|
||||||
## 🤖 获取 token
|
## 🤖 获取 token
|
||||||
- 新建一个[personal access token](https://github.com/settings/tokens/new),**不需要给予任何权限**。
|
- 新建一个[personal access token](https://github.com/settings/tokens/new),**不需要给予任何权限**。
|
||||||
- 将新建的 token 复制,添加到`config.py`文件中的`MARSHOAI_TOKEN`配置项中。
|
- 将新建的 token 复制,添加到`.env`文件中的`marshoai_token`配置项中。
|
||||||
## 🎉 使用
|
## 🎉 使用
|
||||||
|
|
||||||
发送`marsho`指令可以获取使用说明(若在配置中自定义了指令前缀请使用自定义的指令前缀)。
|
发送`marsho`指令可以获取使用说明(若在配置中自定义了指令前缀请使用自定义的指令前缀)。
|
||||||
@ -114,7 +114,7 @@ _✨ 使用 Azure OpenAI 推理服务的聊天机器人插件 ✨_
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## ⚙️ 配置
|
## ⚙️ 可配置项
|
||||||
|
|
||||||
在 nonebot2 项目的`.env`文件中添加下表中的配置
|
在 nonebot2 项目的`.env`文件中添加下表中的配置
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ _✨ 使用 Azure OpenAI 推理服务的聊天机器人插件 ✨_
|
|||||||
|
|
||||||
## ❤ 鸣谢&版权说明
|
## ❤ 鸣谢&版权说明
|
||||||
"Marsho" logo 由 [@Asankilp](https://github.com/Asankilp) 绘制,基于 [CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/) 许可下提供。
|
"Marsho" logo 由 [@Asankilp](https://github.com/Asankilp) 绘制,基于 [CC BY-NC-SA 4.0](http://creativecommons.org/licenses/by-nc-sa/4.0/) 许可下提供。
|
||||||
"nonebot-plugin-marshoai" 基于 [MIT](https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/blob/main/LICENSE) 许可下提供。
|
"nonebot-plugin-marshoai" 基于 [MIT](./LICENSE) 许可下提供。
|
||||||
|
|
||||||
## 🕊️ TODO
|
## 🕊️ TODO
|
||||||
- [x] [Melobot](https://github.com/Meloland/melobot) 实现
|
- [x] [Melobot](https://github.com/Meloland/melobot) 实现
|
||||||
|
@ -117,6 +117,8 @@ async def nickname(event: Event, name=None):
|
|||||||
nicknames = await get_nicknames()
|
nicknames = await get_nicknames()
|
||||||
user_id = event.get_user_id()
|
user_id = event.get_user_id()
|
||||||
if not name:
|
if not name:
|
||||||
|
if user_id not in nicknames:
|
||||||
|
await nickname_cmd.finish("你未设置昵称")
|
||||||
await nickname_cmd.finish("你的昵称为:" + str(nicknames[user_id]))
|
await nickname_cmd.finish("你的昵称为:" + str(nicknames[user_id]))
|
||||||
if name == "reset":
|
if name == "reset":
|
||||||
await set_nickname(user_id, "")
|
await set_nickname(user_id, "")
|
||||||
@ -142,6 +144,8 @@ async def marsho(target: MsgTarget, event: Event, text: Optional[UniMsg] = None)
|
|||||||
nickname_prompt = f"\n*此消息的说话者:{nickname}*"
|
nickname_prompt = f"\n*此消息的说话者:{nickname}*"
|
||||||
else:
|
else:
|
||||||
nickname_prompt = ""
|
nickname_prompt = ""
|
||||||
|
#user_nickname = event.sender.nickname
|
||||||
|
#nickname_prompt = f"\n*此消息的说话者:{user_nickname}"
|
||||||
if config.marshoai_enable_nickname_tip:
|
if config.marshoai_enable_nickname_tip:
|
||||||
await UniMessage(
|
await UniMessage(
|
||||||
"*你未设置自己的昵称。推荐使用'nickname [昵称]'命令设置昵称来获得个性化(可能)回答。"
|
"*你未设置自己的昵称。推荐使用'nickname [昵称]'命令设置昵称来获得个性化(可能)回答。"
|
||||||
|
@ -6,11 +6,14 @@ from typing import Any
|
|||||||
import httpx
|
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 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
|
||||||
from .config import config
|
from .config import config
|
||||||
|
|
||||||
|
nickname_json = None
|
||||||
|
|
||||||
async def get_image_b64(url):
|
async def get_image_b64(url):
|
||||||
headers = {
|
headers = {
|
||||||
@ -91,6 +94,7 @@ async def load_context_from_json(name: str):
|
|||||||
|
|
||||||
|
|
||||||
async def set_nickname(user_id: str, name: str):
|
async def set_nickname(user_id: str, name: str):
|
||||||
|
global nickname_json
|
||||||
filename = store.get_plugin_data_file("nickname.json")
|
filename = store.get_plugin_data_file("nickname.json")
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
data = {}
|
data = {}
|
||||||
@ -98,17 +102,23 @@ async def set_nickname(user_id: str, name: str):
|
|||||||
with open(filename, "r", encoding="utf-8") as f:
|
with open(filename, "r", encoding="utf-8") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
data[user_id] = name
|
data[user_id] = name
|
||||||
|
if name == "" and user_id in data:
|
||||||
|
del data[user_id]
|
||||||
with open(filename, "w", encoding="utf-8") as f:
|
with open(filename, "w", encoding="utf-8") as f:
|
||||||
json.dump(data, f, ensure_ascii=False, indent=4)
|
json.dump(data, f, ensure_ascii=False, indent=4)
|
||||||
|
nickname_json = data
|
||||||
|
|
||||||
|
|
||||||
async def get_nicknames():
|
async def get_nicknames():
|
||||||
|
global nickname_json
|
||||||
|
if nickname_json is None:
|
||||||
filename = store.get_plugin_data_file("nickname.json")
|
filename = store.get_plugin_data_file("nickname.json")
|
||||||
try:
|
try:
|
||||||
with open(filename, "r", encoding="utf-8") as f:
|
with open(filename, "r", encoding="utf-8") as f:
|
||||||
return json.load(f)
|
nickname_json = json.load(f)
|
||||||
except FileNotFoundError:
|
except Exception:
|
||||||
return {}
|
nickname_json = {}
|
||||||
|
return nickname_json
|
||||||
|
|
||||||
|
|
||||||
def get_prompt():
|
def get_prompt():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user