async def start(self): await super().start() result = load_cmds(ALL_PLUGINS) LOGGER.info(result) me = await self.get_me() LOGGER.info(f"TelePyroBot based on Pyrogram v{__version__} " f"(Layer {layer}) started...\n" f"Hey {me.first_name}!")
async def take_screen_shot( video_file: str, duration: int, path: str = "" ) -> Optional[str]: """take a screenshot.""" ttl = duration // 2 thumb_image_path = path or os.path.join(screen_shot, f"{basename(video_file)}.jpg") command = f"ffmpeg -ss {ttl} -i '{video_file}' -vframes 1 '{thumb_image_path}'" err = (await run_cmd(command))[1] if err: LOGGER.info(err) return thumb_image_path if os.path.exists(thumb_image_path) else None
async def covid(c: TelePyroBot, m: Message): if len(m.text.split()) == 1: await m.edit_text("`Enter a directory location`") elif len(m.text.split()) >= 2: temp_dir = m.text.split(None, 1)[1] if not temp_dir.endswith("/"): temp_dir += "/" sm = await m.reply_text("`Uploading Files to Telegram...`") if os.path.exists(temp_dir): files = os.listdir(temp_dir) files.sort() for file in files: c_time = time.time() required_file_name = temp_dir + file thumb_image_path = await is_thumb_image_exists(required_file_name) doc_caption = os.path.basename(required_file_name) LOGGER.info( f"Uploading <i>{required_file_name}</i> from {temp_dir} to Telegram." ) await c.send_document( chat_id=m.chat.id, document=required_file_name, thumb=thumb_image_path, caption=doc_caption, disable_notification=True, progress=progress_for_pyrogram, progress_args=( f"Trying to upload __{file}__", sm, c_time, ), ) else: await sm.edit("Directory Not Found.") return await sm.delete() await m.delete() await m.reply_text(f"Uploaded all files from Directory `{temp_dir}`") LOGGER.info("Uploaded all files!") return
async def gDrive_upload_file(creds, file_path, message): service = build("drive", "v3", credentials=creds, cache_discovery=False) mime_type = guess_type(file_path)[0] mime_type = mime_type if mime_type else "text/plain" media_body = MediaFileUpload( file_path, mimetype=mime_type, chunksize=150 * 1024 * 1024, resumable=True) file_name = os.path.basename(file_path) body = { "name": file_name, "description": "Uploaded using TelePyroBot gDrive", "mimeType": mime_type, } u_file_obj = service.files().create(body=body, media_body=media_body) response = None display_message = "" while response is None: status, response = u_file_obj.next_chunk() if status: percentage = int(status.progress() * 100) progress_str = "[{0}{1}]\nProgress: {2}%\n".format( "".join(["●" for i in range(math.floor(percentage / 5))]), "".join(["○" for i in range(20 - math.floor(percentage / 5))]), round(percentage, 2), ) current_message = ( f"uploading to gDrive\nFile Name: {file_name}\n{progress_str}" ) if display_message != current_message: try: await m.edit_text(current_message) display_message = current_message except Exception as e: LOGGER.info(str(e)) pass file_id = response.get("id") return file_id
async def upload_as_document(c: TelePyroBot, m: Message): text = m.command[1:] if not text: await m.edit_text("`Input not found`") return s_time = 0.1 typing_symbol = "|" old_text = "" await m.edit_text(typing_symbol) time.sleep(s_time) for character in text: s_t = s_time / random.randint(1, 100) old_text += character typing_text = old_text + typing_symbol try: await m.try_to_edit(typing_text, sudo=False) time.sleep(s_t) await m.try_to_edit(old_text, sudo=False) time.sleep(s_t) except FloodWait as ef: time.sleep(ef.x) LOGGER.info(str(ef)) return
async def covid(c: TelePyroBot, m: Message): if len(m.text.split()) == 1: await m.edit("`Enter a directory location`") elif len(m.text.split()) >= 2: temp_dir = m.text.split(" ", 1)[1] if not temp_dir.endswith("/"): temp_dir += "/" status_message = await m.reply_text("`Uploading Files...`") if os.path.exists(temp_dir): files = sorted(os.listdir(temp_dir)) await status_message.edit("`Uploading Files to Telegram...`") for file in files: c_time = time.time() required_file_name = temp_dir + file thumb_image_path = await is_thumb_image_exists(required_file_name) doc_caption = os.path.basename(required_file_name) LOGGER.info( f"Uploading {required_file_name} from {temp_dir} to Telegram.") await c.send_document( chat_id=m.chat.id, document=required_file_name, thumb=thumb_image_path, caption=doc_caption, parse_mode="html", disable_notification=True, progress=progress_for_pyrogram, progress_args=( "Trying to upload multiple files...", status_message, c_time, ), ) else: await m.edit("Directory Not Found.") return await status_message.edit(f"Uploaded all files from Directory `{temp_dir}`" )
async def stop(self, *args): await super().stop() LOGGER.info("TelePyroBot stopped. Bye.")
`{COMMAND_HAND_LER}megafind <filename>`: Find file or folder in mega drive. `{COMMAND_HAND_LER}megaup <file location>`: Upload the file and export its link. `{COMMAND_HAND_LER}megaupdir <folder location>`: Upload contents of folder to mega drive. `{COMMAND_HAND_LER}megaimport <url>`: Download file from mega url to your account. """ mega, megaC = None, None try: mega = Mega() if MEGANZ_EMAIL and MEGANZ_PASSWORD: megaC = mega.login(MEGANZ_EMAIL, MEGANZ_PASSWORD) else: megaC = mega.login() except Exception as ef: LOGGER.info(ef) @TelePyroBot.on_message(filters.command("megainfo", COMMAND_HAND_LER) & filters.me) async def mega_info(c: TelePyroBot, m: Message): if (MEGANZ_EMAIL or MEGANZ_PASSWORD) is None: await m.edit_text( "Setup `MEGANZ_EMAIL` and `MEGANZ_PASSWORD` vars to use this." ) return user = megaC.get_user() storage = megaC.get_storage_space(giga=True) details = ( "</b>User Details:</b>\n" f"Name: {user['name']}\n" f"Email: {user['email']}\n"
async def down_load_media(c: TelePyroBot, m: Message): sm = await m.reply_text("...", quote=True) if not os.path.isdir(TMP_DOWNLOAD_DIRECTORY): os.makedirs(TMP_DOWNLOAD_DIRECTORY) if m.reply_to_message is not None: start_t = datetime.now() download_location = TMP_DOWNLOAD_DIRECTORY c_time = time.time() the_real_download_location = await c.download_media( message=m.reply_to_message, file_name=download_location, progress=progress_for_pyrogram, progress_args=("**__Trying to download...__**", m, c_time), ) end_t = datetime.now() ms = (end_t - start_t).seconds await sm.edit( f"Downloaded to <code>{the_real_download_location}</code> in <u>{ms}</u> seconds", parse_mode="html", ) await m.delete() elif len(m.command) > 1: start_t = datetime.now() the_url_parts = " ".join(m.command[1:]) url = the_url_parts.strip() custom_file_name = os.path.basename(url) if "|" in the_url_parts: url, custom_file_name = the_url_parts.split("|") url = url.strip() custom_file_name = custom_file_name.strip() download_file_path = os.path.join(TMP_DOWNLOAD_DIRECTORY, custom_file_name) downloader = SmartDL(url, download_file_path, progress_bar=False) downloader.start(blocking=False) c_time = time.time() while not downloader.isFinished(): total_length = downloader.filesize if downloader.filesize else None downloaded = downloader.get_dl_size() display_message = "" now = time.time() diff = now - c_time percentage = downloader.get_progress() * 100 speed = downloader.get_speed(human=True) elapsed_time = round(diff) * 1000 progress_str = "**[{0}{1}]**\n**Progress:** __{2}%__".format( "".join(["●" for i in range(math.floor(percentage / 5))]), "".join(["○" for i in range(20 - math.floor(percentage / 5))]), round(percentage, 2), ) estimated_total_time = downloader.get_eta(human=True) try: current_message = f"__**Trying to download...**__\n" current_message += f"**URL:** `{url}`\n" current_message += f"**File Name:** `{custom_file_name}`\n" current_message += f"{progress_str}\n" current_message += ( f"__{humanbytes(downloaded)} of {humanbytes(total_length)}__\n" ) current_message += f"**Download Speed** __{speed}__\n" current_message += f"**ETA:** __{estimated_total_time}__" if round(diff % 10.00) == 0 and current_message != display_message: await sm.edit(disable_web_page_preview=True, text=current_message) display_message = current_message await asyncio.sleep(10) except Exception as e: LOGGER.info(str(e)) pass if os.path.exists(download_file_path): end_t = datetime.now() ms = (end_t - start_t).seconds await sm.edit( f"Downloaded to <code>{download_file_path}</code> in <u>{ms}</u> seconds", parse_mode="html", ) else: await sm.edit( "`Reply to a Telegram Media, to download it to local server.`") return
async def updater(c: TelePyroBot, m: Message): if len(m.command) == 2 and m.command[1] == "force": force_update = True else: force_update = False umsg = await m.reply_text("`Checking for Update...`") if HEROKU_API_KEY is None or HEROKU_APP_NAME is None: await umsg.edit( "__Please the Vars__ `HEROKU_API_KEY` __and__ `HEROKU_APP_NAME` __properly!__" ) return if PRIVATE_GROUP_ID is None: await umsg.edit( "__**Please Set**__ `PRIVATE_GROUP_ID` **__to use updater!__**") try: repo = git.Repo() except git.exc.InvalidGitRepositoryError as error_one: LOGGER.info(str(error_one)) repo = git.Repo.init() origin = repo.create_remote(REPO_REMOTE_NAME, OFFICIAL_UPSTREAM_REPO) origin.fetch() repo.create_head(IFFUCI_ACTIVE_BRANCH_NAME, origin.refs.master) repo.heads.master.checkout(True) active_branch_name = repo.active_branch.name LOGGER.info(active_branch_name) if active_branch_name != IFFUCI_ACTIVE_BRANCH_NAME: await umsg.edit( IS_SELECTED_DIFFERENT_BRANCH.format( branch_name=active_branch_name, COMMAND_HAND_LER=COMMAND_HAND_LER)) return try: repo.create_remote(REPO_REMOTE_NAME, OFFICIAL_UPSTREAM_REPO) except Exception as error_two: LOGGER.info(str(error_two)) temp_remote = repo.remote(REPO_REMOTE_NAME) temp_remote.fetch(active_branch_name) changelog = generate_change_log( repo, DIFF_MARKER.format(remote_name=REPO_REMOTE_NAME, branch_name=active_branch_name), ) LOGGER.info(changelog) try: remote_head_github = repo.head.reference commit_id = remote_head_github.commit.hexsha commit_link = f"<a href='https://github.com/SkuzzyxD/TelePyroBot/commit/{commit_id}'>{commit_id[:7]}</a>" except: commit_link = "None" message_one = NEW_BOT_UP_DATE_FOUND.format(branch_name=active_branch_name, changelog=changelog, commit_link=commit_link) message_two = NEW_UP_DATE_FOUND.format(branch_name=active_branch_name) if len(message_one) > MAX_MESSAGE_LENGTH: with open("change.log", "w+", encoding="utf8") as out_file: out_file.write(str(message_one)) out_file.close() await m.reply_document( document="change.log", caption=message_two, disable_notification=True, reply_to_message_id=m.message_id, ) os.remove("change.log") if not changelog and force_update == False: await umsg.edit("`Your userbot is already up-to-date!!`") return await umsg.edit(message_one, disable_web_page_preview=True) if force_update == True: await umsg.edit( "**Force-Update initiated**\n`Fetching latest version and installing it...`" ) changelog = "#ForceUpdate" temp_remote.fetch(active_branch_name) repo.git.reset("--hard", "FETCH_HEAD") heroku = heroku3.from_key(HEROKU_API_KEY) heroku_app = heroku.apps()[HEROKU_APP_NAME] heroku_git_url = heroku_app.git_url.replace( "https://", f"https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) await umsg.reply( f"**Update Started**\n__**Type**__ `{COMMAND_HAND_LER}alive` **__to check if I'm alive__**\n\n**It would take upto 5 minutes to update!**" ) await c.send_message( PRIVATE_GROUP_ID, f"#UPDATE\n\n**__TelePyroBot Update__** {commit_link}\n\n**Changelog:**\n{changelog}", disable_web_page_preview=True, ) remote.push(refspec=HEROKU_GIT_REF_SPEC, force=True) asyncio.get_event_loop().create_task(deploy_start(client))