-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bot.py
55 lines (43 loc) · 2.29 KB
/
Bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, Update, WebAppInfo
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes, CallbackContext
import logging
import os
# Enable logging
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)
logger = logging.getLogger(__name__)
# Error handler
async def error_handler(update: object, context: CallbackContext) -> None:
logger.error(msg="Exception while handling an update:", exc_info=context.error)
if isinstance(update, Update):
await update.message.reply_text("An error occurred. Please try again later.")
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
try:
logger.info("Received /start command from user: %s", update.message.from_user.username)
keyboard = [
[InlineKeyboardButton("Start Earning", web_app=WebAppInfo(url='https://kalabhaftu.github.io/Taptoerarn/'))],
[InlineKeyboardButton("Join Community", url='https://t.me/venom_hackers')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text('Welcome! This is earning game', reply_markup=reply_markup)
restart_button = [
[KeyboardButton("/start")]
]
reply_markup_restart = ReplyKeyboardMarkup(restart_button, resize_keyboard=True)
await update.message.reply_text('Click below to restart the bot:', reply_markup=reply_markup_restart)
except Exception as e:
logger.error("Error in start handler: %s", str(e))
await update.message.reply_text("An error occurred while processing your request.")
async def unknown_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text("I'm sorry, I didn't understand that command.")
def main() -> None:
BOT_TOKEN = "7401107556:AAHiWzq_k9iX2DgkfI9_wkqR8VoFeOTlHV8"
application = Application.builder().token(BOT_TOKEN).build()
application.add_handler(CommandHandler("start", start))
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, unknown_message))
application.add_error_handler(error_handler)
application.run_polling()
if __name__ == "__main__":
main()