Update main.py
Browse files24 unmodified lines252627282930313245 unmodified lines78798081828380 unmodified lines16416516616716816917010 unmodified lines181182183184185186187185 unmodified lines37337437524 unmodified linesfrom telethon import TelegramClient, events, functions, types, errors# ---------------- CONFIG ----------------API_ID = int(os.environ.get("API_ID", "22138159")) # REPLACE WITH YOUR API_IDAPI_HASH = os.environ.get("API_HASH", "3fe4592e4cad72f366b6c564505f2d57") # REPLACE WITH YOUR API_HASHBOT_TOKEN = os.environ.get("BOT_TOKEN", "8873565701:AAF5X2ykgoKZZgg39gTETeBCrDfb81BFpUE")MONGO_URI = os.environ.get("MONGO_URI", "mongodb+srv://userbot:userbot@cluster0.iweqz.mongodb.net/test?retryWrites=true&w=majority")45 unmodified linesexcept Exception:log.exception("Failed to register user %s", user_id)def get_setting(key: str, default: Any = None) -> Any:doc = settings_col.find_one({"key": key})return doc["value"] if doc else default80 unmodified linesawait asyncio.sleep(1.0) # wait before polling db againasync def process_dm(client, payload):await client.send_message(payload["user_id"], payload["text"])async def process_approve(client, payload):try:10 unmodified linesraise easync def process_broadcast(client, payload):await client.send_message(payload["user_id"], payload["text"])# ---------------- Client Initialization ----------------bot = TelegramClient('bot_session', API_ID, API_HASH)185 unmodified lineslog.error("Please set a valid API_ID and API_HASH environment variable.")else:asyncio.run(main())24 unmodified lines252627282930313245 unmodified lines78798081828384858687888990919280 unmodified lines17317417517617717817918018118218310 unmodified lines194195196197198199200201202203204185 unmodified lines39039139239324 unmodified linesfrom telethon import TelegramClient, events, functions, types, errors# ---------------- CONFIG ----------------API_ID = int(os.environ.get("API_ID", "22138159"))API_HASH = os.environ.get("API_HASH", "3fe4592e4cad72f366b6c564505f2d57")BOT_TOKEN = os.environ.get("BOT_TOKEN", "8873565701:AAF5X2ykgoKZZgg39gTETeBCrDfb81BFpUE")MONGO_URI = os.environ.get("MONGO_URI", "mongodb+srv://userbot:userbot@cluster0.iweqz.mongodb.net/test?retryWrites=true&w=majority")45 unmodified linesexcept Exception:log.exception("Failed to register user %s", user_id)def remove_blocked_user(user_id: int) -> None:"""Removes a user from all DB collections if they have blocked the bot."""try:users_col.delete_one({"user_id": user_id})pending_col.delete_many({"user_id": user_id})log.info(f"Successfully deleted blocked user {user_id} from database.")except Exception:log.exception(f"Failed to delete blocked user {user_id} from database.")def get_setting(key: str, default: Any = None) -> Any:doc = settings_col.find_one({"key": key})return doc["value"] if doc else default80 unmodified linesawait asyncio.sleep(1.0) # wait before polling db againasync def process_dm(client, payload):try:await client.send_message(payload["user_id"], payload["text"])except errors.UserIsBlockedError:log.warning(f"User {payload['user_id']} blocked the bot. Removing from DB.")remove_blocked_user(payload["user_id"])async def process_approve(client, payload):try:10 unmodified linesraise easync def process_broadcast(client, payload):try:await client.send_message(payload["user_id"], payload["text"])except errors.UserIsBlockedError:log.warning(f"Broadcast failed: User {payload['user_id']} blocked the bot. Removing from DB.")remove_blocked_user(payload["user_id"])# ---------------- Client Initialization ----------------bot = TelegramClient('bot_session', API_ID, API_HASH)185 unmodified lineslog.error("Please set a valid API_ID and API_HASH environment variable.")else:asyncio.run(main())
main.py+22-4