feat(01-03): switch Matrix confirmations to text commands
- replace reaction-based helper text with !yes/!no and !skill commands - resolve confirm and cancel through pending confirmation state - render !settings as a read-only status dashboard
This commit is contained in:
parent
8a6a33a2ce
commit
01610ef768
4 changed files with 86 additions and 70 deletions
|
|
@ -1,9 +1,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from nio import AsyncClient
|
||||
|
||||
from sdk.interface import UserSettings
|
||||
|
||||
CONFIRM_REACTION = "👍"
|
||||
|
|
@ -13,56 +9,26 @@ REACTION_TO_INDEX = {emoji: idx + 1 for idx, emoji in enumerate(SKILL_REACTIONS)
|
|||
|
||||
|
||||
def build_skills_text(settings: UserSettings) -> str:
|
||||
lines: list[str] = ["🧩 Скиллы"]
|
||||
lines: list[str] = ["Скиллы"]
|
||||
for idx, (name, enabled) in enumerate(settings.skills.items(), start=1):
|
||||
state = "✅" if enabled else "❌"
|
||||
state = "on" if enabled else "off"
|
||||
emoji = SKILL_REACTIONS[idx - 1] if idx - 1 < len(SKILL_REACTIONS) else f"{idx}."
|
||||
lines.append(f"{state} {emoji} {name}")
|
||||
lines.append(f" {state} {emoji} {name}")
|
||||
lines.append("")
|
||||
lines.append("Реакции 1️⃣-9️⃣ переключают навыки.")
|
||||
lines.append("!skill on/off <название> — переключить навык.")
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def build_confirmation_text(description: str) -> str:
|
||||
return "\n".join(
|
||||
[
|
||||
"🤖 Lambda",
|
||||
"Lambda",
|
||||
description,
|
||||
"",
|
||||
f"{CONFIRM_REACTION} подтвердить · {CANCEL_REACTION} отменить",
|
||||
"!yes — подтвердить · !no — отменить",
|
||||
"Ответьте !yes для подтверждения или !no для отмены.",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def reaction_to_skill_index(key: str) -> int | None:
|
||||
return REACTION_TO_INDEX.get(key)
|
||||
|
||||
|
||||
async def add_reaction(client: AsyncClient, room_id: str, event_id: str, key: str) -> Any:
|
||||
return await client.room_send(
|
||||
room_id,
|
||||
"m.reaction",
|
||||
{
|
||||
"m.relates_to": {
|
||||
"rel_type": "m.annotation",
|
||||
"event_id": event_id,
|
||||
"key": key,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
async def remove_reaction(client: AsyncClient, room_id: str, event_id: str, key: str) -> Any:
|
||||
return await client.room_send(
|
||||
room_id,
|
||||
"m.reaction",
|
||||
{
|
||||
"m.relates_to": {
|
||||
"rel_type": "m.annotation",
|
||||
"event_id": event_id,
|
||||
"key": key,
|
||||
},
|
||||
"undo": True,
|
||||
},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue