Include utility modules, shared channels, prompts, read-only skills, wardrobe memory and regression tests. Externalize legacy credentials and exclude private runtime state.
35 lines
1.5 KiB
Python
35 lines
1.5 KiB
Python
"""Implementation of /setting for per-platform user and group modes."""
|
|
from __future__ import annotations
|
|
|
|
from agent.modes import ModeStore
|
|
from channel import send_message
|
|
|
|
|
|
async def handle_setting(channel, msg_type, user_id, target_id, raw_text):
|
|
parts = (raw_text or "").strip().split()
|
|
arg = parts[1].lower() if len(parts) > 1 else ""
|
|
store = ModeStore()
|
|
group_id = target_id if msg_type == "group" else None
|
|
if msg_type == "group" and not channel.is_admin(user_id):
|
|
await send_message(channel, msg_type, target_id, "只有管理员可以修改本群的回复模式")
|
|
return
|
|
if msg_type != "group" and user_id is None:
|
|
await send_message(channel, msg_type, target_id, "绑定统一身份后才能使用聊天模式")
|
|
return
|
|
if arg not in ("command", "chat"):
|
|
current = store.get_mode(channel.name, user_id, group_id)
|
|
await send_message(
|
|
channel, msg_type, target_id,
|
|
f"当前是 {current} 模式。\n"
|
|
"发送 .setting command 使用传统命令;发送 .setting chat 使用自然语言聊天和工具调用。",
|
|
mirror=False,
|
|
)
|
|
return
|
|
store.set_mode(channel.name, user_id, arg, group_id)
|
|
text = (
|
|
"已切换为 command 模式。所有旧命令保持不变,发送 .help 查看服务。"
|
|
if arg == "command"
|
|
else "已切换为 chat 模式。现在可以直接用自然语言告诉我你想做什么;旧命令仍然可用。"
|
|
)
|
|
await send_message(channel, msg_type, target_id, text, mirror=False)
|