refactored bot code

This commit is contained in:
Hosein
2025-12-30 18:57:48 +03:30
parent 67a76250ab
commit a52d62c0fc
15 changed files with 328 additions and 149 deletions
+7
View File
@@ -0,0 +1,7 @@
from . import students, teachers
def register_all_callbacks(bot):
"""Register all callback handlers"""
students.register(bot)
teachers.register(bot)
+20
View File
@@ -0,0 +1,20 @@
from telebot import types
from database.models import Students
from bot.utils.formatters import format_student_info
def register(bot):
@bot.callback_query_handler(func=lambda call: call.data.startswith('student_'))
def show_student_details(call):
student_id = call.data.split('_')[1]
student = Students.getStudentById(student_id)
if student:
details = format_student_info(student)
markup = types.InlineKeyboardMarkup()
bot.send_message(call.message.chat.id, details,
reply_markup=markup, parse_mode="HTML")
else:
bot.send_message(call.message.chat.id, "Student not found.")
bot.answer_callback_query(call.id)
+20
View File
@@ -0,0 +1,20 @@
from telebot import types
from database.models import Teachers
from bot.utils.formatters import format_teacher_info
def register(bot):
@bot.callback_query_handler(func=lambda call: call.data.startswith('teacher_'))
def show_teacher_details(call):
teacher_id = call.data.split('_')[1]
teacher = Teachers.getTeachertById(teacher_id)
if teacher:
details = format_teacher_info(teacher)
markup = types.InlineKeyboardMarkup()
bot.send_message(call.message.chat.id, details,
reply_markup=markup, parse_mode="HTML")
else:
bot.send_message(call.message.chat.id, "Teacher not found.")
bot.answer_callback_query(call.id)