| | |
| | | ) |
| | | |
| | | |
| | | async def messages_page(request) -> web.Response: |
| | | user = await _user(request) |
| | | chat_id = int(request.match_info["chat_id"]) |
| | | if chat_id not in await _allowed_ids(user["user_id"]): |
| | | raise web.HTTPForbidden() |
| | | chat = await db.get_chat(chat_id) or {"chat_id": chat_id, "title": str(chat_id)} |
| | | msgs = await db.list_msgs(chat_id, 100) |
| | | return render( |
| | | request, "messages.html", active="chats", chat=chat, msgs=msgs, fmt_dt=fmt_dt |
| | | ) |
| | | |
| | | |
| | | async def say(request) -> web.Response: |
| | | # Отправка сообщения в чат от имени Амадеуса с указанием автора. |
| | | user = await _user(request) |
| | | data = await request.post() |
| | | chat_id = int(data["chat_id"]) |
| | | text = (data.get("text") or "").strip() |
| | | if chat_id not in await _allowed_ids(user["user_id"]): |
| | | raise web.HTTPForbidden() |
| | | if not text: |
| | | raise web.HTTPFound(f"/chats/{chat_id}/messages") |
| | | name = user.get("first_name") or str(user["user_id"]) |
| | | try: |
| | | await bot.send_message(chat_id, f"От {name}:\n{text}") |
| | | await db.add_msg(chat_id, user["user_id"], f"Amadeus / {name}", text, now_ts()) |
| | | await db.add_log(chat_id, user["user_id"], 0, "say", text[:200], now_ts()) |
| | | except Exception as e: |
| | | logger.warning("say failed chat=%s: %s", chat_id, e) |
| | | raise web.HTTPFound(f"/chats/{chat_id}/messages") |
| | | |
| | | |
| | | async def alarm_toggle(request) -> web.Response: |
| | | user = await _user(request) |
| | | data = await request.post() |