async def download_decrypt_file( auth_key, chat_id, password, search, from_user, role, ): try: client = TelegramClient(StringSession(auth_key), api_id, api_hash) await client.connect() except: return "client error" try: entity = await get_entity(chat_id, client) except: return {"message": "get entity error"} if role == "owner": me = await client.get_me() from_user = me.id decrypt_key = get_decrypt_key(password, me.id) n = check_file(search) while n <= 30: filename = f"{search}_{n}.txt" message = await client.get_messages(entity=entity, search=filename, from_user=from_user) if message: if message[0].file: try: with open(f'temp/{search}_{n}.txt', 'wb') as fd: async for chunk in client.iter_download( message[0].media): fd.write(chunk) with open(f'temp/{search}_{n}.txt', 'rb') as f: token = f.read() data = decrypt_file(token, decrypt_key) with open(f'video/{search}.mp4', 'ab') as f: f.write(data) os.remove(f'temp/{search}_{n}.txt') print(message[0].id) n += 1 except errors.FloodWaitError as e: os.remove(f'temp/{search}_{n}.txt') client.flood_sleep_threshold = 24 * 60 * 60 else: return {"message": "File you want to download is not found"} break return {"message": "download sucess"}
def login(): global instabot, client instabot = InstaBot(like_per_day=config['max_likes'], login=config['ig_username'], password=config['ig_password'], session_file=config['cookie_name'], log_mod=2) # Telegram client client = TelegramClient(config['session'], config['telegram_api_id'], config['telegram_api_hash']) client.flood_sleep_threshold = 24 * 60 * 60 # Sleep always
def login(): global instabot, client, user_followers, user_following, user_media, user_id instabot = API() instabot.login( username = config['ig_username'], password = config['ig_password'], use_cookie = True, cookie_fname = config['cookie_name']) # Telegram client client = TelegramClient(config['session'], config['telegram_api_id'], config['telegram_api_hash']) client.flood_sleep_threshold = 24 * 60 * 60 # Get user info instabot.get_username_info(instabot.user_id) user_followers = instabot.last_json['user']['follower_count'] user_following = instabot.last_json['user']['following_count'] user_media = instabot.last_json['user']['media_count'] user_id = instabot.user_id return [user_followers, user_following, user_media, client, instabot]
def login(): global instabot, client, user_followers, user_following, user_media instabot = InstaBot(like_per_day=config['max_likes'], login=config['ig_username'], password=config['ig_password'], session_file=config['cookie_name'], unfollow_recent_feed=False, log_mod=2) # Telegram client client = TelegramClient(config['session'], config['telegram_api_id'], config['telegram_api_hash']) client.flood_sleep_threshold = 24 * 60 * 60 get_user_info(instabot, config['ig_username']) user_followers = instabot.current_user_info["edge_followed_by"]["count"] user_following = instabot.current_user_info["edge_follow"]["count"] user_media = instabot.current_user_info["edge_owner_to_timeline_media"][ "count"] return [user_followers, user_following, user_media]
try: return pytz.timezone(s) except: msg = "Not a valid tz: '{0}'.".format(s) raise argparse.ArgumentTypeError(msg) parser = argparse.ArgumentParser() parser.add_argument("--api_id", required=False, help="user api ID", type=str, default=Config.API_ID) parser.add_argument("--api_hash", required=False, help="user api Hash", type=str, default=Config.API_HASH) parser.add_argument("--tz", required=False, help="user api Hash", type=valid_tz, default=valid_tz('Asia/Tashkent')) args = parser.parse_args() client = TelegramClient(Config.SESSION_NAME, args.api_id, args.api_hash) client.flood_sleep_threshold = 0 # Don't auto-sleep async def setBio(): index = 0 while True: size = len(array) bts = str(countdown(datetime.now(args.tz).replace(microsecond=0, tzinfo=None))) if index == size: bio = 'Yangi yil ' + bts + ' dan keyin kirib keladi!' index = 0 else: bio = str(getStringFromArray(index)) index += 1 await client(UpdateProfileRequest(about=bio)) time.sleep(60)
err_file = logging.FileHandler(Path.cwd().joinpath(CONFIG["LOG"]["ERR"])) err_file.setLevel(logging.WARNING) err_file.setFormatter(formatter) [logger.addHandler(handler) for handler in [console, debug_file, info_file, err_file]] # OBJECT INSTANTIATION bot = Bot(token=CONFIG["AIOGRAM"]["TOKEN"]) dp = Dispatcher(bot=bot) client = TelegramClient( session=str(Path.cwd().joinpath(CONFIG["TELETHON"]["SESSION"])), api_id=CONFIG["TELETHON"]["API_ID"], api_hash=CONFIG["TELETHON"]["API_HASH"], ) client.flood_sleep_threshold = 5 client.start() # MIDDLEWARE middle = userbot.UserBot(client=client) middle.add_func(app.username_reply) # HANDLERS dp.register_message_handler(admin.stats, commands=["stats"], user_id=CONFIG["ADMINS"]) dp.register_message_handler(service.start, commands=["start"]) dp.register_message_handler(service.lang, commands=["lang"]) dp.register_message_handler(service.help, commands=["help"]) dp.register_message_handler(service.credits, commands=["credits"]) dp.register_message_handler(app.reply_id, commands=["id"])
logging.basicConfig(level=logging.INFO) try: API_ID = os.environ['TG_API_ID'] API_HASH = os.environ['TG_API_HASH'] TOKEN = os.environ['TG_TOKEN'] except KeyError as e: print(e.args[0], 'missing from environment variables') exit(0) NAME = TOKEN.split(':')[0] GROUP = "telethonofftopic" DELAY = 24 * 60 * 60 client = TelegramClient(NAME, API_ID, API_HASH).start(bot_token=TOKEN) client.flood_sleep_threshold = 24 * 60 * 60 clicked = asyncio.Event() chosen = None async def kick_users(): global chosen while True: clicked.clear() users = await client.get_participants(GROUP) chosen = random.choice(users) chosen.name = html.escape(utils.get_display_name(chosen)) start = time.time() try: await kick_user()