in this script, if I get a peer flood error, is there a way to remove that api id and…
- User
in this script, if I get a peer flood error, is there a way to remove that api id and hash from the program for a specific amount of time without editing the clean_accounts.json file?
import asyncio import json import logging from telethon import TelegramClient, errors, Button
Configure logging
logging.basicConfig( filename='bot_log.log', # Log file name level=logging.INFO, # Log level format='%(asctime)s - %(levelname)s - %(message)s', # Log format datefmt='%Y-%m-%d %H:%M:%S' # Date format )
Configuration Constants
GROUP_LINK = 'https://t.me/rocketproxyupdates' # Telegram group link BUTTON_TEXT = 'Join Our Telegram Group' # Text displayed on the button
USER_LIST_FILE = 'targets.json' SENT_FILE = 'sent.json'
Function to read API IDs and hashes from a JSON file
def read_api_config(filename): with open(filename, 'r') as f: data = json.load(f) return data['API_ID_LIST'], data['API_HASH_LIST']
Read API_ID_LIST and API_HASH_LIST from the JSON file
API_ID_LIST, API_HASH_LIST = read_api_config('clean_accounts.json')
Source chat information
FORWARD_SOURCE_CHAT_ID = 'rocketproxyupdates'
WAIT_TIME_BASE = 10 # base wait time in seconds WAIT_TIME_FACTOR = 60 # wait time factor based on errors
async def forward_to_user(client, user, source_chat_entity, message_id): """ Forwards a message from the source chat to the target user using the provided client. """ try: forwarded_message = await client.forward_messages( entity=user['username'], messages=message_id, from_peer=source_chat_entity ) logging.info(f"Forwarded message to {user['username']} using API ID {client.api_id}") return forwarded_message except errors.FloodWaitError as e: wait_time = max(WAIT_TIME_BASE, e.seconds + WAIT_TIME_FACTOR) logging.warning(f"Flood wait error: Waiting for {wait_time} seconds before retrying.") await asyncio.sleep(wait_time) return None except errors.UsernameNotOccupiedError: logging.warning(f"No user has '{user['username']}' as username.") return None except errors.PeerFloodError: logging.error(f"Peer flood error when forwarding to '{user['username']}' using API ID {client.api_id}.") return None except Exception as e: logging.error(f"Failed to forward message to {user['username']}. Error: {e}") return None
async def send_button_message(client, user, reply_to_msg_id=None): """ Sends a text message saying "hey bro check this out" to the target user using the provided client. Optionally replies to a specific message if 'reply_to_msg_id' is provided.
Args: client: The Telegram client instance. user (dict): A dictionary containing user information, e.g., {'username': 'example_user'}. reply_to_msg_id (int, optional): The message ID to reply to. Defaults to None. Returns: bool: True if the message was sent successfully, False otherwise. """ try: message_text = "hey bro check this out" # Send the message to the user await client.send_message( entity=user['username'], message=message_text ) logging.info(f"Sent message to {user['username']} using API ID {client.api_id}") await asyncio.sleep(1) return True except errors.FloodWaitError as e: wait_time = max(WAIT_TIME_BASE, e.seconds + WAIT_TIME_FACTOR) logging.warning(f"Flood wait error: Waiting for {wait_time} seconds before retrying.") await asyncio.sleep(wait_time) return False except errors.UsernameNotOccupiedError: logging.warning(f"No user has the username '{user['username']}'.") return False except errors.PeerFloodError: logging.error(f"Peer flood error when sending message to '{user['username']}' using API ID {client.api_id}.") return False except Exception as e: logging.error(f"Failed to send message to '{user['username']}'. Error: {e}") return False - Assistant