""" حضور و غیاب ساده — Bale Bot (نسخه رایگان) Single-class attendance tracker for schools. بات‌بان | hi@botban.ir """ import os, sqlite3, logging, time from datetime import date from typing import Optional import requests from dotenv import load_dotenv load_dotenv() log = logging.getLogger(__name__) TOKEN: str = os.getenv("BALE_BOT_TOKEN", "") ADMIN_ID: int = int(os.getenv("ADMIN_USER_ID", "0")) DB_PATH: str = "attendance.db" API_BASE: str = f"https://tapi.bale.ai/bot{TOKEN}" def init_db() -> None: with sqlite3.connect(DB_PATH) as con: con.execute(""" CREATE TABLE IF NOT EXISTS attendance ( id INTEGER PRIMARY KEY AUTOINCREMENT, student TEXT NOT NULL, status TEXT NOT NULL CHECK(status IN ('present','absent')), day TEXT NOT NULL ) """) con.commit() def mark(student: str, status: str) -> None: today = str(date.today()) with sqlite3.connect(DB_PATH) as con: con.execute("DELETE FROM attendance WHERE student=? AND day=?", (student, today)) con.execute("INSERT INTO attendance (student,status,day) VALUES (?,?,?)", (student, status, today)) con.commit() START_KEYBOARD = { "inline_keyboard": [ [ {"text": "✅ حاضر کردن دانش‌آموز", "callback_data": "help_present"}, {"text": "❌ غایب کردن دانش‌آموز", "callback_data": "help_absent"}, ], [{"text": "📋 گزارش امروز", "callback_data": "report"}, {"text": "⭐ نسخه حرفه‌ای", "callback_data": "upgrade"}], ] } def handle_report(chat_id: int, user_id: int) -> None: if user_id != ADMIN_ID: send(chat_id, "⛔ فقط مدیر می‌تواند گزارش ببیند.") return rows = get_report() present = [r[0] for r in rows if r[1] == "present"] absent = [r[0] for r in rows if r[1] == "absent"] lines = [f"📋 گزارش حضور — {date.today()}\n"] if present: lines.append("✅ حاضر:") lines.extend(f" • {n}" for n in present) if absent: lines.append("\n❌ غایب:") lines.extend(f" • {n}" for n in absent) lines.append(f"\n👥 جمع: {len(present)} حاضر / {len(absent)} غایب") send(chat_id, "\n".join(lines)) # ... ادامه کد (تا ۱۳۵ خط دیگر) # نسخه کامل + مستندات + دیتابیس → hi@botban.ir