mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-19 18:47:41 +08:00
* refactor: code structure for improved readability and maintainability * style: ruff format * Update packages/astrbot/commands/provider.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Update packages/astrbot/commands/persona.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Update packages/astrbot/commands/llm.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Update packages/astrbot/commands/conversation.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * fix: improve error handling message formatting in key switching * fix: update LLM command to use safe get for provider settings * feat: implement ProcessLLMRequest class for handling LLM requests and persona injection --------- Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
import astrbot.api.star as star
|
|
from astrbot.api.event import AstrMessageEvent, MessageEventResult
|
|
from astrbot.api import sp
|
|
|
|
|
|
class SetUnsetCommands:
|
|
def __init__(self, context: star.Context):
|
|
self.context = context
|
|
|
|
async def set_variable(self, event: AstrMessageEvent, key: str, value: str):
|
|
"""设置会话变量"""
|
|
uid = event.unified_msg_origin
|
|
session_var = await sp.session_get(uid, "session_variables", {})
|
|
session_var[key] = value
|
|
await sp.session_put(uid, "session_variables", session_var)
|
|
|
|
event.set_result(
|
|
MessageEventResult().message(
|
|
f"会话 {uid} 变量 {key} 存储成功。使用 /unset 移除。"
|
|
)
|
|
)
|
|
|
|
async def unset_variable(self, event: AstrMessageEvent, key: str):
|
|
"""移除会话变量"""
|
|
uid = event.unified_msg_origin
|
|
session_var = await sp.session_get(uid, "session_variables", {})
|
|
|
|
if key not in session_var:
|
|
event.set_result(
|
|
MessageEventResult().message("没有那个变量名。格式 /unset 变量名。")
|
|
)
|
|
else:
|
|
del session_var[key]
|
|
await sp.session_put(uid, "session_variables", session_var)
|
|
event.set_result(
|
|
MessageEventResult().message(f"会话 {uid} 变量 {key} 移除成功。")
|
|
)
|