removed depreceated code, and logs
This commit is contained in:
39
bot.py
39
bot.py
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import asyncio
|
||||
import logging
|
||||
from contextlib import suppress
|
||||
from dotenv import load_dotenv
|
||||
from functools import wraps
|
||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||
@@ -12,6 +13,7 @@ from database import upload_entry
|
||||
from scraper import get_clean_content
|
||||
|
||||
load_dotenv()
|
||||
logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||
|
||||
# Configuration
|
||||
TOKEN = os.getenv("TG_TOKEN")
|
||||
@@ -260,20 +262,39 @@ async def button_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
else:
|
||||
await query.edit_message_text("🗑️ Discarded.")
|
||||
|
||||
# --- Main Entry ---
|
||||
if __name__ == '__main__':
|
||||
# Main Entry Point
|
||||
async def _main():
|
||||
application = ApplicationBuilder().token(TOKEN).build()
|
||||
|
||||
# Add Handlers
|
||||
|
||||
application.add_handler(CommandHandler("start", start))
|
||||
application.add_handler(CommandHandler("op", handle_opportunity))
|
||||
application.add_handler(CommandHandler("ev", handle_event))
|
||||
application.add_handler(MessageHandler(filters.TEXT & (~filters.COMMAND), handle_followup_text))
|
||||
application.add_handler(CallbackQueryHandler(button_handler))
|
||||
|
||||
# Start the worker thread
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.create_task(worker())
|
||||
async with application:
|
||||
await application.initialize()
|
||||
await application.start()
|
||||
|
||||
print("🤖 Bot is running...")
|
||||
application.run_polling()
|
||||
worker_task = asyncio.create_task(worker())
|
||||
print("🤖 Bot is running...")
|
||||
|
||||
await application.updater.start_polling()
|
||||
|
||||
# Keep running until interrupted
|
||||
await asyncio.Event().wait()
|
||||
|
||||
# Graceful shutdown
|
||||
await application.updater.stop()
|
||||
worker_task.cancel()
|
||||
with suppress(asyncio.CancelledError):
|
||||
await worker_task
|
||||
|
||||
await application.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
if sys.platform == 'win32':
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
asyncio.run(_main())
|
||||
Reference in New Issue
Block a user