import logging import random from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, CallbackQueryHandler # Enable logging logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO ) logger = logging.getLogger(__name__) # Fun fact list fun_facts = [ "Did you know? Honey never spoils.", "Fact: Bananas are berries, but strawberries aren't.", "Fun Fact: Octopuses have three hearts!", "Legendary: The Eiffel Tower can grow by 6 inches in summer due to heat expansion.", "Myth or fact? You can't hum while holding your nose closed." ] # Start command async def start(update: Update, context) -> None: await update.message.reply_text( f"Welcome to the legendary Error404Bot!\nI'm here to assist you with the best features.\nUse /help to see more commands." ) # Help command async def help_command(update: Update, context) -> None: await update.message.reply_text( "/start - Start interacting with the bot.\n" "/welcome - Sends a custom welcome message.\n" "/fact - Get a fun fact." ) # Welcome message function async def welcome(update: Update, context) -> None: user = update.effective_user welcome_text = f"Welcome, {user.first_name}, to the legendary Error404Bot community! Prepare to be amazed. 😎" keyboard = [ [InlineKeyboardButton("Learn More", callback_data='learn_more')], [InlineKeyboardButton("Support", callback_data='support')] ] reply_markup = InlineKeyboardMarkup(keyboard) await update.message.reply_text(welcome_text, reply_markup=reply_markup) # Fun fact feature async def send_fun_fact(update: Update, context) -> None: fact = random.choice(fun_facts) await update.message.reply_text(fact) # Button handler (for Learn More and Support) async def button(update: Update, context) -> None: query = update.callback_query await query.answer() if query.data == 'learn_more': await query.edit_message_text(text="This bot is designed to provide legendary services and features.") elif query.data == 'support': await query.edit_message_text(text="Support is on the way! Please wait for a response or contact @support.") # Error handler async def error_handler(update: object, context) -> None: logger.error(msg="Exception while handling an update:", exc_info=context.error) # Main function to run the bot async def main() -> None: # Create the Application and pass it your bot's token. application = ApplicationBuilder().token("7813873560:AAFW6_I_n9OYgbycJZsL92ns1SuXsrYLTI0").build() # Register command handlers application.add_handler(CommandHandler("start", start)) application.add_handler(CommandHandler("help", help_command)) application.add_handler(CommandHandler("welcome", welcome)) application.add_handler(CommandHandler("fact", send_fun_fact)) # Button handler for interactive buttons application.add_handler(CallbackQueryHandler(button)) # Log all errors application.add_error_handler(error_handler) # Start the bot await application.start_polling() await application.idle() # Run the bot if __name__ == '__main__': import asyncio asyncio.run(main())