welcomecenterbot/bot/handlers/routing.py
2023-10-26 12:25:02 +03:00

42 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from handlers.handle_feedback import handle_feedback, handle_answer
from handlers.handle_default import handle_default
from handlers.command_my import handle_command_my
from handlers.command_graph import handle_command_graph
from handlers.command_ask import handle_command_ask
from config import FEEDBACK_CHAT_ID
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
async def handle_routing(msg, state):
cid = msg["chat"]["id"]
uid = msg["from"]["id"]
if cid == uid:
# сообщения в личке с ботом
logger.info("private chat message")
text = msg.get("text")
if text:
if text.startswith("/my"):
await handle_command_my(msg, state)
elif text.startswith("/graph"):
await handle_command_graph(msg)
else:
await handle_feedback(msg, state)
elif str(cid) == FEEDBACK_CHAT_ID:
# сообщения из группы обратной связи
logger.info("feedback chat message")
logger.debug(msg)
if msg.get("reply_to_message"):
await handle_answer(msg)
elif msg.get("text", "").startswith("/ask"):
await handle_command_ask(msg)
else:
# сообщения из всех остальных групп
logger.info(f"group {cid} chat message")
text = msg.get("text", msg.get("caption"))
if text:
await handle_default(msg, state)