Download bot/main.py from luci18/animebot: direct link, hf CLI and curl.
- Browser
- Download file 2.17 kB
-
https://huggingface.co/luci18/animebot/resolve/main/bot/main.py
- Command line
-
hf download hf://luci18/animebot/bot/main.py
-
curl -L -o main.py https://huggingface.co/luci18/animebot/resolve/main/bot/main.py
2.17 kB
| """Main entry point for Anime Encoder Bot.""" | |
| import logging | |
| import sys | |
| import asyncio | |
| from pathlib import Path | |
| from pyrogram import Client | |
| from config import Config | |
| from bot.handlers import register_handlers | |
| from bot.task_queue import task_queue | |
| # Setup logging | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | |
| handlers=[ | |
| logging.StreamHandler(sys.stdout), | |
| logging.FileHandler("bot.log") | |
| ] | |
| ) | |
| logger = logging.getLogger(__name__) | |
| async def main(): | |
| """Main function to start the bot.""" | |
| # Validate config | |
| try: | |
| Config.validate() | |
| logger.info("Configuration validated successfully") | |
| except ValueError as e: | |
| logger.error(f"Configuration error: {e}") | |
| sys.exit(1) | |
| # Create Pyrogram client | |
| app = Client( | |
| "anime_encoder_bot", | |
| api_id=Config.API_ID, | |
| api_hash=Config.API_HASH, | |
| bot_token=Config.BOT_TOKEN, | |
| workdir="." | |
| ) | |
| # Register handlers | |
| register_handlers(app) | |
| logger.info("Handlers registered") | |
| # Start task queue | |
| await task_queue.start() | |
| logger.info("Task queue started") | |
| # Start the bot | |
| try: | |
| logger.info("Starting bot...") | |
| await app.start() | |
| # Log startup | |
| me = await app.get_me() | |
| logger.info(f"Bot started: @{me.username}") | |
| if Config.LOG_CHANNEL: | |
| try: | |
| await app.send_message( | |
| Config.LOG_CHANNEL, | |
| f"✅ **Bot Started**\n@{me.username} is now online!" | |
| ) | |
| except Exception as e: | |
| logger.warning(f"Failed to send startup log: {e}") | |
| # Keep running | |
| await asyncio.Event().wait() | |
| except KeyboardInterrupt: | |
| logger.info("Shutting down...") | |
| except Exception as e: | |
| logger.error(f"Bot error: {e}") | |
| finally: | |
| # Stop task queue | |
| await task_queue.stop() | |
| # Stop the bot | |
| await app.stop() | |
| logger.info("Bot stopped") | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |