added authentication to the bot. added bot commnads. added create button for when the db is empty or no data is available to show.

This commit is contained in:
Hosein
2026-01-05 23:40:13 +03:30
parent 4b5b24c97c
commit caac6c3a08
18 changed files with 369 additions and 47 deletions
+13 -5
View File
@@ -1,13 +1,18 @@
import logging
from telebot import types
from database.models import Students
from telebot import types, TeleBot
from database.models import Students, Admins
logger = logging.getLogger(__name__)
def register(bot):
def register(bot: TeleBot):
@bot.message_handler(func=lambda message: message.text == "Show Students")
def get_students(message):
if not Admins.is_authenticated(message.from_user.id):
bot.send_message(
message.chat.id, "⛔ Unauthorized access!\nPlease /login first.")
return
try:
data = Students.getAllStudents()
if data:
@@ -20,12 +25,15 @@ def register(bot):
# add button for creating a new student
markup.add(types.InlineKeyboardButton(
" Create New Student", callback_data="create_student"))
" Create New Student 🔒", callback_data="create_student"))
bot.send_message(
message.chat.id, "Here is the data:", reply_markup=markup)
else:
bot.reply_to(message, "No data found.")
markup = types.InlineKeyboardMarkup(row_width=1)
markup.add(types.InlineKeyboardButton(
" Create New Student 🔒", callback_data="create_student"))
bot.reply_to(message, "No data found.", reply_markup=markup)
except Exception as e:
logger.error(f"Error in get_students handler: {e}")
bot.reply_to(message, "Sorry, an error occurred.")