""" بات نوبت‌دهی کلینیک — نسخه رایگان Clinic Appointment Bot (Bale) بات‌بان | hi@botban.ir """ import os, time, sqlite3, logging from datetime import date, timedelta from typing import Any import requests from dotenv import load_dotenv load_dotenv() log = logging.getLogger(__name__) TOKEN: str = os.getenv("BALE_BOT_TOKEN", "") BASE_URL: str = f"https://tapi.bale.ai/bot{TOKEN}" DB_PATH: str = os.path.join(os.path.dirname(__file__), "appointments.db") DOCTOR_IDS: set[int] = {int(x) for x in os.getenv("DOCTOR_IDS","").split(",") if x.strip().isdigit()} # محدودیت نسخه رایگان: فقط ۲ پزشک، فقط فردا DOCTORS: dict[str, dict] = { "dr_rezavi": { "name": "دکتر رضوی", "specialty": "اطفال", "slots": ["۱۶:۳۰", "۱۷:۰۰", "۱۷:۳۰", "۱۸:۰۰"], }, "dr_karimi": { "name": "دکتر کریمی", "specialty": "داخلی", "slots": ["۹:۰۰", "۹:۳۰", "۱۰:۰۰", "۱۰:۳۰", "۱۱:۰۰"], }, } sessions: dict[int, dict] = {} def tomorrow_str() -> str: return (date.today() + timedelta(days=1)).strftime("%Y-%m-%d") def doctors_keyboard() -> dict: return {"inline_keyboard": [ [{"text": f"👨‍⚕️ {d['name']} ({d['specialty']})", "callback_data": f"doc:{key}"}] for key, d in DOCTORS.items() ]} def slots_keyboard(doctor_key: str, appt_date: str) -> dict: booked = get_booked_slots(doctor_key, appt_date) doctor = DOCTORS[doctor_key] buttons = [ [{"text": f"🔴 {s} پر", "callback_data": "slot_taken"}] if s in booked else [{"text": f"🟢 {s}", "callback_data": f"slot:{doctor_key}:{appt_date}:{s}"}] for s in doctor["slots"] ] buttons.append([{"text": "🔙 بازگشت", "callback_data": "back_doctors"}]) return {"inline_keyboard": buttons} def book_appointment(user_id: int, user_name: str, doctor_key: str, appt_date: str, slot: str) -> int: return db_run( "INSERT INTO appointments (user_id,user_name,doctor_key,appt_date,slot) VALUES (?,?,?,?,?)", (user_id, user_name, doctor_key, appt_date, slot) ) # ... ادامه کد (تا ۱۳۷ خط دیگر) # نسخه کامل + مستندات + دیتابیس → hi@botban.ir