Lightarmortech commited on
Commit
86efe7b
·
verified ·
1 Parent(s): 6c76d49

ERROR404.py

Browse files

Best bot
![nyovGYOiRbyWpus-eEZ7gw.webp](https://cdn-uploads.huggingface.co/production/uploads/66fb9a9868fb2a7410908607/UM-JLDIqZImvjK7XxZ-mn.webp)

Files changed (1) hide show
  1. app.py +92 -0
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ import random
3
+ from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
4
+ from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, CallbackQueryHandler
5
+
6
+ # Enable logging
7
+ logging.basicConfig(
8
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
9
+ level=logging.INFO
10
+ )
11
+ logger = logging.getLogger(__name__)
12
+
13
+ # Fun fact list
14
+ fun_facts = [
15
+ "Did you know? Honey never spoils.",
16
+ "Fact: Bananas are berries, but strawberries aren't.",
17
+ "Fun Fact: Octopuses have three hearts!",
18
+ "Legendary: The Eiffel Tower can grow by 6 inches in summer due to heat expansion.",
19
+ "Myth or fact? You can't hum while holding your nose closed."
20
+ ]
21
+
22
+ # Start command
23
+ async def start(update: Update, context) -> None:
24
+ await update.message.reply_text(
25
+ f"Welcome to the legendary Error404Bot!\nI'm here to assist you with the best features.\nUse /help to see more commands."
26
+ )
27
+
28
+ # Help command
29
+ async def help_command(update: Update, context) -> None:
30
+ await update.message.reply_text(
31
+ "/start - Start interacting with the bot.\n"
32
+ "/welcome - Sends a custom welcome message.\n"
33
+ "/fact - Get a fun fact."
34
+ )
35
+
36
+ # Welcome message function
37
+ async def welcome(update: Update, context) -> None:
38
+ user = update.effective_user
39
+ welcome_text = f"Welcome, {user.first_name}, to the legendary Error404Bot community! Prepare to be amazed. 😎"
40
+
41
+ keyboard = [
42
+ [InlineKeyboardButton("Learn More", callback_data='learn_more')],
43
+ [InlineKeyboardButton("Support", callback_data='support')]
44
+ ]
45
+ reply_markup = InlineKeyboardMarkup(keyboard)
46
+
47
+ await update.message.reply_text(welcome_text, reply_markup=reply_markup)
48
+
49
+ # Fun fact feature
50
+ async def send_fun_fact(update: Update, context) -> None:
51
+ fact = random.choice(fun_facts)
52
+ await update.message.reply_text(fact)
53
+
54
+ # Button handler (for Learn More and Support)
55
+ async def button(update: Update, context) -> None:
56
+ query = update.callback_query
57
+ await query.answer()
58
+
59
+ if query.data == 'learn_more':
60
+ await query.edit_message_text(text="This bot is designed to provide legendary services and features.")
61
+ elif query.data == 'support':
62
+ await query.edit_message_text(text="Support is on the way! Please wait for a response or contact @support.")
63
+
64
+ # Error handler
65
+ async def error_handler(update: object, context) -> None:
66
+ logger.error(msg="Exception while handling an update:", exc_info=context.error)
67
+
68
+ # Main function to run the bot
69
+ async def main() -> None:
70
+ # Create the Application and pass it your bot's token.
71
+ application = ApplicationBuilder().token("7813873560:AAFW6_I_n9OYgbycJZsL92ns1SuXsrYLTI0").build()
72
+
73
+ # Register command handlers
74
+ application.add_handler(CommandHandler("start", start))
75
+ application.add_handler(CommandHandler("help", help_command))
76
+ application.add_handler(CommandHandler("welcome", welcome))
77
+ application.add_handler(CommandHandler("fact", send_fun_fact))
78
+
79
+ # Button handler for interactive buttons
80
+ application.add_handler(CallbackQueryHandler(button))
81
+
82
+ # Log all errors
83
+ application.add_error_handler(error_handler)
84
+
85
+ # Start the bot
86
+ await application.start_polling()
87
+ await application.idle()
88
+
89
+ # Run the bot
90
+ if __name__ == '__main__':
91
+ import asyncio
92
+ asyncio.run(main())