68 lines
2 KiB
Python
68 lines
2 KiB
Python
from __future__ import annotations
|
||
|
||
from typing import Any
|
||
|
||
from nio import AsyncClient
|
||
|
||
from sdk.interface import UserSettings
|
||
|
||
CONFIRM_REACTION = "👍"
|
||
CANCEL_REACTION = "❌"
|
||
SKILL_REACTIONS = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣"]
|
||
REACTION_TO_INDEX = {emoji: idx + 1 for idx, emoji in enumerate(SKILL_REACTIONS)}
|
||
|
||
|
||
def build_skills_text(settings: UserSettings) -> str:
|
||
lines: list[str] = ["🧩 Скиллы"]
|
||
for idx, (name, enabled) in enumerate(settings.skills.items(), start=1):
|
||
state = "✅" if enabled else "❌"
|
||
emoji = SKILL_REACTIONS[idx - 1] if idx - 1 < len(SKILL_REACTIONS) else f"{idx}."
|
||
lines.append(f"{state} {emoji} {name}")
|
||
lines.append("")
|
||
lines.append("Реакции 1️⃣-9️⃣ переключают навыки.")
|
||
return "\n".join(lines)
|
||
|
||
|
||
def build_confirmation_text(description: str) -> str:
|
||
return "\n".join(
|
||
[
|
||
"🤖 Lambda",
|
||
description,
|
||
"",
|
||
f"{CONFIRM_REACTION} подтвердить · {CANCEL_REACTION} отменить",
|
||
"!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,
|
||
},
|
||
)
|