| import os | |
| import sqlite3 | |
| from datetime import datetime | |
| from app.config import FEEDBACK_DB_PATH | |
| from app.integrations.telegram_bot import send_telegram_message | |
| def _init_db(): | |
| os.makedirs(os.path.dirname(FEEDBACK_DB_PATH), exist_ok=True) | |
| with sqlite3.connect(FEEDBACK_DB_PATH) as conn: | |
| conn.execute(""" | |
| CREATE TABLE IF NOT EXISTS feedback ( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| created_at TEXT, | |
| author TEXT, | |
| channel TEXT, | |
| topic TEXT, | |
| rating INTEGER, | |
| message TEXT | |
| ) | |
| """) | |
| conn.commit() | |
| def save_feedback(author: str, channel: str, topic: str, rating: int, message: str) -> str: | |
| _init_db() | |
| ts = datetime.utcnow().isoformat(timespec="seconds") + "Z" | |
| with sqlite3.connect(FEEDBACK_DB_PATH) as conn: | |
| conn.execute( | |
| "INSERT INTO feedback(created_at, author, channel, topic, rating, message) VALUES(?,?,?,?,?,?)", | |
| (ts, author.strip(), channel.strip(), topic.strip(), int(rating), message.strip()) | |
| ) | |
| conn.commit() | |
| return f"✅ Сохранено (UTC {ts})" | |
| def send_feedback_to_telegram(author: str, channel: str, topic: str, rating: int, message: str) -> str: | |
| text = ( | |
| "🧾 2MOOD Feedback\n" | |
| f"Автор: {author}\n" | |
| f"Канал: {channel}\n" | |
| f"Тема: {topic}\n" | |
| f"Оценка: {rating}/5\n\n" | |
| f"{message}" | |
| ) | |
| ok, info = send_telegram_message(text) | |
| return "✅ " + info if ok else "⚠️ " + info | |