import logging import json import random import asyncio from datetime import datetime from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.ext import Application, CommandHandler, CallbackQueryHandler, MessageHandler, filters, ContextTypes from sqlalchemy import create_engine, Column, Integer, String, Float, DateTime, desc from sqlalchemy.orm import sessionmaker, declarative_base
logging.basicConfig(level=logging.INFO)
TOKEN = "8957659468:AAEasLYnO0cfRGoB5cRwFnA7xFneNexiBnM"
Base = declarative_base() engine = create_engine('sqlite:///mascot_jamb.db', echo=False) Session = sessionmaker(bind=engine)
class User(Base): tablename = 'users' user_id = Column(Integer, primary_key=True) username = Column(String) subjects = Column(String) # JSON list total_score = Column(Float, default=0.0) quizzes_taken = Column(Integer, default=0)
class ScoreRecord(Base): tablename = 'scores' id = Column(Integer, primary_key=True) user_id = Column(Integer) subject = Column(String) score = Column(Float) accuracy = Column(Float) mode = Column(String) timestamp = Column(DateTime, default=datetime.utcnow)
Base.metadata.create_all(engine)
QUESTIONS = { "Commerce": [ {"q": "Commerce is defined as the study of how", "options": ["A. man utilizes the resources in his physical environment", "B. man produces, distributes and consumes his goods and services", "C. man buys, sells and distributes goods and services", "D. raw materials are changed into finished goods."], "answer": "B"}, {"q": "The type of activity which turns processed raw materials into consumer and industrial goods is described as", "options": ["A. extractive", "B. manufacturing", "C. constructive", "D. processing"], "answer": "B"}, # Add hundreds more from your Commerce PDF ], "Biology": [ {"q": "Which of the following characterizes a mature plant cell?", "options": ["A. the cytoplasm fills up the entire cell space", "B. the nucleus is pushed to the centre of the cell", "C. the cell wall is made up of cellulose", "D. the nucleus is small and irregular in shape"], "answer": "C"}, # Add from Biology PDFs ], # Add other subjects: Chemistry, Government, Literature, CRK, Physics, Mathematics, English, etc. }
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): await update.message.reply_text( "🎓 MASCOT JAMB Bot Ready!\n\n" "Works in Group & Private Chat\n\n" "/register - Select your 4 subjects\n" "/quiz - Start quiz (Timed or Untimed)\n" "/leaderboard - Top scorers\n" "/mystats - Your stats" )
async def register(update: Update, context: ContextTypes.DEFAULT_TYPE): await update.message.reply_text("Send your 4 JAMB subjects separated by commas.\nExample: English, Mathematics, Biology, Chemistry") context.user_data['registering'] = True
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): text = update.message.text.strip() if context.user_data.get('registering'): subjects = [s.strip().title() for s in text.split(',')][:4] session = Session() user = session.query(User).filter_by(user_id=update.effective_user.id).first() if not user: user = User(user_id=update.effective_user.id, username=update.effective_user.username or str(update.effective_user.id)) user.subjects = json.dumps(subjects) session.add(user) session.commit() session.close() await update.message.reply_text(f"✅ Profile updated!\nSubjects: {subjects}") context.user_data['registering'] = False
def main(): app = Application.builder().token(TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CommandHandler("register", register))
# Add /quiz, /leaderboard, /mystats, callback handlers for timed quizzes etc.
app.add_handler(MessageHandler(filters.TEXT & \~filters.COMMAND, handle_message))
print("🚀 MASCOT JAMB Bot is LIVE (Group + Private)")
app.run_polling()
if name == 'main': main()