async def start_stop_bot(client, query): try: await app.stop() except ConnectionError: await reload_userbot() text = await get_text_settings() button = await get_button_settings() text += tld('settings_stats_botstart') try: await query.message.edit_text(text, reply_markup=button) except errors.exceptions.bad_request_400.MessageNotModified: pass await client.answer_callback_query( query.id, tld('settings_stats_botstart'), ) return text = await get_text_settings() button = await get_button_settings() text += tld('settings_stats_botstop') try: await query.message.edit_text(text, reply_markup=button) except errors.exceptions.bad_request_400.MessageNotModified: pass await client.answer_callback_query(query.id, tld('settings_stats_botstop'))
async def update_changelog(changelog): await setbot.send_sticker(Owner, random.choice(RANDOM_STICKERS)) text = tld('update_successful') text += tld('update_welcome').format(USERBOT_VERSION, ASSISTANT_VERSION) text += tld('updated_changelog') text += changelog await setbot.send_message(Owner, text)
async def get_button_settings(): me = await is_userbot_run() toggle = ( tld('settings_userbot_stopbutton') if me else tld('settings_userbot_startbutton') ) list_button = InlineKeyboard(row_width=2) list_button.add( InlineKeyboardButton(toggle, callback_data='toggle_startbot'), InlineKeyboardButton( tld('settings_userbot_restartbutton'), callback_data='restart_bot', ), InlineKeyboardButton( tld('settings_setstickerbutton'), callback_data='setsticker', ), InlineKeyboardButton( tld('language_btn'), callback_data='set_lang_', ), InlineKeyboardButton( 'Select Branch', callback_data='change_branches', ), ) return list_button
async def get_list_bots(client, message): replyid = None if len(message.text.split()) >= 2: chat = message.text.split(None, 1)[1] else: chat = message.chat.id grup = await client.get_chat(chat) if message.reply_to_message: replyid = message.reply_to_message.message_id getbots = client.iter_chat_members(chat) bots = [] async for a in getbots: try: nama = a.user.first_name + ' ' + a.user.last_name except BaseException: nama = a.user.first_name if nama is None: nama = tld('botlist_one') if a.user.is_bot: bots.append(mention_markdown(a.user.id, nama)) teks = tld('botlist_two').format(grup.title) teks += tld('botlist_three') for x in bots: teks += f'│ • {x}\n' teks += tld('botlist_four').format(len(bots)) if replyid: await client.send_message( message.chat.id, teks, reply_to_message_id=replyid, ) else: await edit_or_reply(message, text=teks)
async def locale_button(_, query): lang_match = re.findall( r'en-US|hi|he|id|fa|el|dv|es|ja|de|ta|pt-br|ar|ku|tr', query.data, ) if lang_match: if lang_match[0]: switch_to_locale(Owner, lang_match[0]) await query.answer( text=tld('language_switch_success_pm').format( list_locales[lang_match[0]], ), show_alert=True, ) else: await query.answer(text='Error!', show_alert=True) try: LANGUAGE = prev_locale(Owner) locale = LANGUAGE.locale_name curr_lang = list_locales[locale] except Exception: curr_lang = 'English (US)' text = tld('language_select_language') text += tld('language_current_locale').format(curr_lang) buttons = InlineKeyboard() buttons.row( InlineKeyboardButton('US ЪЄ║ЪЄИ', callback_data='set_lang_en-US'), InlineKeyboardButton('IN ЪЄ«ЪЄ│', callback_data='set_lang_hi'), InlineKeyboardButton('HE ЪЄ«ЪЄ▒', callback_data='set_lang_he'), InlineKeyboardButton('ID ЪЄ«ЪЄЕ', callback_data='set_lang_id'), InlineKeyboardButton('FA ЪЄ«ЪЄи', callback_data='set_lang_fa'), ) buttons.row( InlineKeyboardButton('JA ЪЄ»ЪЄх', callback_data='set_lang_ja'), InlineKeyboardButton('GR ЪЄгЪЄи', callback_data='set_lang_el'), InlineKeyboardButton('MV ЪЄ▓ЪЄ╗', callback_data='set_lang_dv'), InlineKeyboardButton('ES ЪЄфЪЄИ', callback_data='set_lang_es'), InlineKeyboardButton('DE ЪЄЕЪЄф', callback_data='set_lang_de'), ) buttons.row( InlineKeyboardButton('TA ЪЈ┤заЂЕзаЂ«заЂ┤заЂ«заЂ┐', callback_data='set_lang_ta'), InlineKeyboardButton('BR ЪЄДЪЄи', callback_data='set_lang_pt-br'), InlineKeyboardButton('AR ЪЄИЪЄд', callback_data='set_lang_pt-ar'), InlineKeyboardButton('CKB Рўђ№ИЈ', callback_data='set_lang_pt-ku'), InlineKeyboardButton('TR ЪЄ╣ЪЄи', callback_data='set_lang_pt-tr'), ), buttons.row( InlineKeyboardButton('РЌђ№ИЈ', callback_data='language_back'), ) try: await query.message.edit( text, parse_mode='markdown', reply_markup=buttons, ) await query.answer() except errors.exceptions.bad_request_400.MessageNotModified: return
async def update_checker(): try: repo = Repo() except NoSuchPathError as error: log.warning(f'Check update failed!\nDirectory {error} is not found!') return except InvalidGitRepositoryError as error: log.warning( 'Check update failed!\nDirectory {} Not a git repository'.format( error, ), ) return except GitCommandError as error: log.warning(f'Check update failed!\n{error}') return brname = repo.active_branch.name if brname not in OFFICIAL_BRANCH: return try: repo.create_remote('upstream', REPOSITORY) except BaseException: pass upstream = repo.remote('upstream') upstream.fetch(brname) changelog = await gen_chlog(repo, f'HEAD..upstream/{brname}') if not changelog: log.info(f'Skynoid is up-to-date with branch {brname}') return log.warning(f'New UPDATE available for [{brname}]!') text = tld('updater_available_text').format(brname) text += f'**CHANGELOG:**\n`{changelog}`' button = InlineKeyboard(row_width=1) button.add( InlineKeyboardButton( tld('update_now_btn'), callback_data='update_now', ), ) await setbot.send_message( Owner, text, reply_markup=button, parse_mode='markdown', )
async def alive_func(answers): buttons = InlineKeyboard(row_width=1) try: me = await app.get_me() except ConnectionError: me = None skynoid_stats = 'stopped' if not me else 'alive' buttons.add(InlineKeyboardButton( '🏓', callback_data='alive_message', ), ) answers.append( InlineQueryResultArticle( title='Alive', description='Skynoid Userbot', input_message_content=InputTextMessageContent( tld('alive_str').format( skynoid_stats, USERBOT_VERSION, __version__, python_version(), DB_AVAILABLE, ), parse_mode='markdown', disable_web_page_preview=True, ), reply_markup=buttons, ), )
async def temp_ban(_, message): if not message.reply_to_message and len(message.command) == 1: await edit_or_reply( message, text='Reply to a user, or pass username/user_id', ) return if not message.reply_to_message and len(message.command) == 2: await edit_or_reply( message, text='`@Eviral please fix this string`', ) return user_id, set_time, _ = await user_time_and_reason(message) parsed_time = extract_time(set_time) if not parsed_time: await edit_or_reply(message, text='`Parsed time is wrong.`') return try: await app.kick_chat_member(message.chat.id, user_id, parsed_time) except errors.ChatAdminRequired: await edit_or_reply(message, text=tld('denied_permission')) return
async def help_button(_, query): mod_match = re.match(r'help_module\((.+?)\)', query.data) back_match = re.match(r'help_back', query.data) if mod_match: module = mod_match.group(1) text = ('This is help for the module **{}**:\n'.format( HELP_COMMANDS[module].__MODULE__, ) + HELP_COMMANDS[module].__HELP__) await query.message.edit( text=text, reply_markup=InlineKeyboardMarkup([ [ InlineKeyboardButton( text='Back', callback_data='help_back', ), ], ], ), ) elif back_match: await query.message.edit( text=tld('help_str').format(', '.join(COMMAND_PREFIXES)), reply_markup=InlineKeyboardMarkup( paginate_modules(0, HELP_COMMANDS, 'help'), ), ) await query.answer()
async def start(_, message): if message.chat.type != 'private': await message.reply('henlo ^0^') else: if len(message.text.split()) >= 2: helparg = message.text.split()[1] if helparg == 'help_inline': await message.reply( tld('inline_help_text', ).format(BotUsername, ), ) return try: me = await app.get_me() except ConnectionError: me = None userbot_stat = 'Stopped' if not me else 'Running' db_stat = len(get_all_chats()) if DB_AVAILABLE else 'None' buttons = InlineKeyboard(row_width=1) buttons.add( InlineKeyboardButton(tld('help_btn'), callback_data='help_back'), ) if SKYNOID_IMG: await message.reply_photo( SKYNOID_IMG, caption=tld('start_message').format( OwnerName, python_version(), userbot_stat, USERBOT_VERSION, ASSISTANT_VERSION, DB_AVAILABLE, db_stat, ), reply_markup=buttons, ) else: await message.reply( tld('start_message').format( OwnerName, python_version(), userbot_stat, USERBOT_VERSION, ASSISTANT_VERSION, DB_AVAILABLE, db_stat, ), reply_markup=buttons, )
async def update_button(client, query): await query.message.delete() await client.send_message(Owner, 'Updating, please wait...') try: repo = Repo() except NoSuchPathError as error: log.warning(f'Check update failed!\nDirectory {error} is not found!') return except InvalidGitRepositoryError as error: log.warning( 'Check update failed!\nDirectory {} Not a git repository'.format( error, ), ) return except GitCommandError as error: log.warning(f'Check update failed!\n{error}') return brname = repo.active_branch.name if brname not in OFFICIAL_BRANCH: return try: repo.create_remote('upstream', REPOSITORY) except BaseException: pass upstream = repo.remote('upstream') upstream.fetch(brname) changelog = await gen_chlog(repo, f'HEAD..upstream/{brname}') try: upstream.pull(brname) await client.send_message(Owner, tld('update_successful')) except GitCommandError: repo.git.reset('--hard') repo.git.clean('-fd', 'skynoid/modules/') repo.git.clean('-fd', 'skynoid/assistant/') repo.git.clean('-fd', 'skynoid/utils/') await client.send_message(Owner, tld('update_successful_force')) await update_changelog(changelog) await restart_all()
async def speedtest_func(answers): buttons = InlineKeyboard(row_width=2) buttons.add( InlineKeyboardButton( tld('speed_test_button_image'), callback_data='speedtest_image', ), InlineKeyboardButton( tld('speed_test_button_text'), callback_data='speedtest_text', ), ) answers.append( InlineQueryResultArticle( title='Speed Test', description='test your speed', input_message_content=InputTextMessageContent( tld('speed_test_trigger'), parse_mode='markdown', ), reply_markup=buttons, ), )
async def report_admin(client, message): await message.delete() if len(message.text.split()) >= 2: text = message.text.split(None, 1)[1] else: text = None grup = await client.get_chat(message.chat.id) alladmins = client.iter_chat_members( message.chat.id, filter='administrators', ) admin = [ mention_html(a.user.id, '\u200b') async for a in alladmins if a.status in ['administrator', 'creator'] and not a.user.is_bot ] if message.reply_to_message: if text: teks = f'{text}' else: user = message.reply_to_message.from_user teks = tld('reportadmins_one').format( mention_html(user.id, user.first_name), ) else: if text: teks = '{}'.format(html.escape(text)) else: teks = tld('reportadmins_two').format(grup.title) teks += ''.join(admin) if message.reply_to_message: await client.send_message( message.chat.id, teks, reply_to_message_id=message.reply_to_message.message_id, parse_mode='html', ) else: await client.send_message(message.chat.id, teks, parse_mode='html')
async def get_text_settings(): me = await is_userbot_run() text = tld('settings_userbot_repo').format(REPOSITORY) if not me: text += tld('settings_userbot_stop').format(USERBOT_VERSION) else: text += tld('settings_userbot_running').format(USERBOT_VERSION) text += tld('settings_assistant_running').format(ASSISTANT_VERSION) text += tld('settings_database').format(DB_AVAILABLE) text += tld('settings_python').format(python_version()) return text
async def tag_all_users(client, message): if len(message.text.split()) >= 2: text = message.text.split(None, 1)[1] else: text = tld('tagall') kek = client.iter_chat_members(message.chat.id) async for a in kek: if not a.user.is_bot: text += mention_html(a.user.id, '\u200b') if message.reply_to_message: await client.send_message( message.chat.id, text, reply_to_message_id=message.reply_to_message.message_id, parse_mode='html', ) else: await client.send_message(message.chat.id, text, parse_mode='html') await message.delete()
async def tempmute(client, message): if message.chat.type == 'private': await message.delete() return if not message.reply_to_message and len(message.command) == 1: await edit_or_reply( message, text='You must reply to a user, or pass a username/user_id', ) return if not message.reply_to_message and len(message.command) == 2: await edit_or_reply( message, text='@Eviral please fix this string asap.', ) return user_id, set_time, reason = await user_time_and_reason(message) parsed_time = extract_time(set_time) reas = parsed_time - int(time.time()) if not parsed_time: await edit_or_reply(message, text='Invalid Time') return try: await client.restrict_chat_member( message.chat.id, user_id, permissions=ChatPermissions(can_send_messages=False), until_date=parsed_time, ) except errors.ChatAdminRequired: await edit_or_reply(message, text=tld('denied_permission')) return # Must send a sticker await edit_or_reply( message, text='**Temporary muted** for {time}'.format( time=time_parser_int(reas), ) + '\nReason: ' + reason if reason else '', )
async def speedtestxyz_callback(client, query): if query.from_user.id in AdminSettings: await client.edit_inline_text( query.inline_message_id, tld('speed_test_running'), ) speed = speedtest.Speedtest() speed.get_best_server() speed.download() speed.upload() replymsg = tld('speed_test_result') if query.data == 'speedtest_image': speedtest_image = speed.results.share() replym = ('{}[\u200c\u200c\u200e]({})'.format( tld('speed_test_result'), speedtest_image, )) await client.edit_inline_text( query.inline_message_id, replym, parse_mode='markdown', ) elif query.data == 'speedtest_text': result = speed.results.dict() replymsg += '\n - {} `{}`'.format( tld('speed_test_isp'), result['client']['isp'], ) replymsg += '\n - {} `{}`'.format( tld('speed_test_download'), speed_convert(result['download']), ) replymsg += ('\n - {} `{}`'.format( tld('speed_test_upload'), speed_convert(result['upload']), )) replymsg += f"\n - {tld('speed_test_ping')} `{result['ping']}`" await client.edit_inline_text( query.inline_message_id, replymsg, ) else: await client.answer_callback_query( query.id, 'No, you are not allowed to do this', show_alert=False, )
async def help_command(client, message): if message.chat.type != 'private': buttons = InlineKeyboardMarkup([ [ InlineKeyboardButton( text='Help', url=f't.me/{BotUsername}?start=help', ), ], ], ) await message.reply( '**OWNER ONLY**\nContact me in PM', reply_markup=buttons, ) return await help_parser( client, message.chat.id, tld('help_str').format(', '.join(COMMAND_PREFIXES)), )
async def adminlist(client, message): creator = [] admin = [] badmin = [] replyid = None toolong = False if len(message.text.split()) >= 2: chat = message.text.split(None, 1)[1] else: chat = message.chat.id grup = await client.get_chat(chat) if message.reply_to_message: replyid = message.reply_to_message.message_id alladmins = client.iter_chat_members(chat, filter='administrators') async for a in alladmins: try: nama = a.user.first_name + ' ' + a.user.last_name except BaseException: nama = a.user.first_name if nama is None: nama = '☠️ Deleted Account' if a.status == 'administrator': if a.user.is_bot: badmin.append(mention_markdown(a.user.id, nama)) else: admin.append(mention_markdown(a.user.id, nama)) elif a.status == 'creator': creator.append(mention_markdown(a.user.id, nama)) admin.sort() badmin.sort() totaladmins = len(creator) + len(admin) + len(badmin) teks = tld('adminlist_one').format(grup.title) for x in creator: teks += f'│ • {x}\n' if len(teks) >= 4096: await message.reply( message.chat.id, teks, reply_to_message_id=replyid, ) teks = '' toolong = True teks += tld('adminlist_two').format(len(admin)) for x in admin: teks += f'│ • {x}\n' if len(teks) >= 4096: await message.reply(teks) teks = '' toolong = True teks += tld('adminlist_three').format(len(badmin)) for x in badmin: teks += f'│ • {x}\n' if len(teks) >= 4096: await message.reply( message.chat.id, teks, reply_to_message_id=replyid, ) teks = '' toolong = True teks += tld('adminlist_four').format(totaladmins) if toolong: await message.reply(message.chat.id, teks, reply_to_message_id=replyid) else: await edit_or_reply(message, text=teks)
async def gdrive_helper(_, message): if len(message.text.split()) == 1: gdriveclient = os.path.isfile('client_secrets.json') if ENV: if not GDRIVE_CREDENTIALS: await message.reply(tld('gdrive_credential_err_heroku')) return elif not gdriveclient: with open('client_secrets.json', 'w') as gfile: gfile.write(GDRIVE_CREDENTIALS) gfile.close() gdriveclient = os.path.isfile('client_secrets.json') if not gdriveclient: await message.reply(tld('gdrive_credential_err')) return gauth.LoadCredentialsFile('skynoid/session/drive') if gauth.credentials is None: try: authurl = gauth.GetAuthUrl() except auth.AuthenticationError: await message.reply( 'Wrong Credentials!' 'Check var ENV gdrive_credentials on heroku' 'or do .credentials (your ' 'credentials) for change your Credentials', ) return teks = ( 'First, you must log in to your Google drive first.\n\n' '[Visit this link and login to your Google ' 'account]({})\n\nAfter that you will get a verification code,' 'type `/gdrive (verification code)` ' "without '(' or ')'.".format(authurl)) await message.reply(teks) return await message.reply( "You're already logged in!\nTo logout type `/gdrive logout`", ) elif len(message.text.split(), ) == 2 and message.text.split()[1] == 'logout': os.remove('skynoid/session/drive') await message.reply('You have logged out of your account!', ) elif len(message.text.split()) == 2: try: gauth.Auth(message.text.split()[1]) except auth.AuthenticationError: await message.reply('Your Authentication code is Wrong!') return gauth.SaveCredentialsFile('skynoid/session/drive') drive = GoogleDrive(gauth) file_list = drive.ListFile({ 'q': "'root' in parents and trashed=false" }, ).GetList() for drivefolders in file_list: if drivefolders['title'] == 'Skynoid Drive': await message.reply( 'Authentication successful!\nWelcome back!', ) return mkdir = drive.CreateFile( { 'title': 'Skynoid Drive', 'mimeType': 'application/vnd.google-apps.folder', }, ) mkdir.Upload() await message.reply('Authentication successful!', ) else: await message.reply('Invaild args!\nCheck /gdrive for usage guide')
async def gdrive_stuff(client, message): gauth.LoadCredentialsFile('skynoid/session/drive') if gauth.credentials is None: if ENV and GDRIVE_CREDENTIALS: with open('client_secrets.json', 'w') as file: file.write(GDRIVE_CREDENTIALS) await edit_or_reply( message, text='You are not logged in to your google drive account!\n' 'Your assistant bot may help you to login google ' 'drive, check your assistant bot for more information!', ) gdriveclient = os.path.isfile('client_secrets.json') if gdriveclient: try: gauth.GetAuthUrl() except Exception as e: print(e) await setbot.send_message( message.from_user.id, 'Wrong Credentials! Check var ENV gdrive_credentials' 'on heroku or do ' '.credentials (your credentials)' 'for changing your Credentials', ) return await setbot.send_message( message.from_user.id, tld('gdrive_credential_err_heroku'), ) else: await setbot.send_message( message.from_user.id, tld('gdrive_credential_err'), ) return elif gauth.access_token_expired: # Refresh them if expired gauth.Refresh() else: # Initialize the saved creds gauth.Authorize() drive = GoogleDrive(gauth) drive_dir = await get_drivedir(drive) if len(message.text.split(), ) == 3 and message.text.split()[1] == 'download': await edit_or_reply(message, text='Downloading...') driveid = await get_driveid(message.text.split()[2]) if not driveid: await edit_or_reply( message, text='Invaild URL!', ) return filename = await get_driveinfo(driveid) if not filename: await edit_or_reply( message, text='Invaild URL!', ) return await edit_or_reply( message, text='Downloading for `{}`\nPlease wait...'.format( filename.replace(' ', '_'), ), ) download = drive.CreateFile({'id': driveid}) download.GetContentFile(filename) try: os.rename(filename, 'skynoid/downloads/' + filename.replace(' ', '_')) except FileExistsError: os.rename( filename, 'skynoid/downloads/' + filename.replace( ' ', '_', ) + '.2', ) await edit_or_reply( message, text='Downloaded!\nFile saved to `{}`'.format( 'skynoid/downloads/' + filename.replace(' ', '_'), ), ) elif len(message.text.split(), ) == 3 and message.text.split()[1] == 'upload': filerealname = message.text.split()[2].split(None, 1)[0] filename = 'skynoid/downloads/{}'.format(filerealname.replace( ' ', '_')) checkfile = os.path.isfile(filename) if not checkfile: await edit_or_reply( message, text=f'File `{filerealname}` was not found!', ) return await edit_or_reply( message, text='Uploading `{}`...'.format(filerealname, ), ) upload = drive.CreateFile( { 'parents': [{ 'kind': 'drive#fileLink', 'id': drive_dir }], 'title': filerealname, }, ) upload.SetContentFile(filename) upload.Upload() upload.InsertPermission( { 'type': 'anyone', 'value': 'anyone', 'role': 'reader' }, ) await edit_or_reply( message, text='Uploaded!\nDownload link: [{}]({})'.format( filerealname, upload['alternateLink'], ), ) elif len(message.text.split(), ) == 3 and message.text.split()[1] == 'mirror': await edit_or_reply(message, text='Mirroring...') driveid = await get_driveid(message.text.split()[2]) if not driveid: await edit_or_reply( message, text='Invaild URL!', ) return filename = await get_driveinfo(driveid) if not filename: await edit_or_reply( message, text='Invaild URL!', ) return mirror = (drive.auth.service.files().copy( fileId=driveid, body={ 'parents': [{ 'kind': 'drive#fileLink', 'id': drive_dir }], 'title': filename, }, ).execute()) new_permission = { 'type': 'anyone', 'value': 'anyone', 'role': 'reader', } drive.auth.service.permissions().insert( fileId=mirror['id'], body=new_permission, ).execute() await edit_or_reply( message, text='Done!\nDownload link: [{}]({})'.format( filename, mirror['alternateLink'], ), ) elif len(message.text.split(), ) == 2 and message.text.split()[1] == 'tgmirror': if message.reply_to_message: await edit_or_reply(message, text='__Downloading...__') c_time = time.time() if message.reply_to_message.photo: if message.reply_to_message.caption: nama = f'{message.reply_to_message.caption}.png'.replace( ' ', '_', ) else: nama = f'photo_{message.reply_to_message.photo.date}.png' await client.download_media( message.reply_to_message.photo, file_name='skynoid/downloads/' + nama, progress=lambda d, t: client.loop.create_task( progressdl(d, t, message, c_time, 'Downloading...'), ), ) elif message.reply_to_message.animation: if message.reply_to_message.caption: nama = f'{message.reply_to_message.caption}.gif'.replace( ' ', '_', ) else: nama = 'giphy_{}-{}.gif'.format( message.reply_to_message.animation.date, message.reply_to_message.animation.file_size, ) await client.download_media( message.reply_to_message.animation, file_name='skynoid/downloads/' + nama, progress=lambda d, t: client.loop.create_task( progressdl(d, t, message, c_time, 'Downloading...'), ), ) elif message.reply_to_message.video: if message.reply_to_message.caption: nama = f'{message.reply_to_message.caption}.mp4'.replace( ' ', '_', ).replace('.mkv', '') else: nama = 'video_{}-{}.mp4'.format( message.reply_to_message.video.date, message.reply_to_message.video.file_size, ) await client.download_media( message.reply_to_message.video, file_name='skynoid/downloads/' + nama, progress=lambda d, t: client.loop.create_task( progressdl(d, t, message, c_time, 'Downloading...'), ), ) elif message.reply_to_message.sticker: if not message.reply_to_message.caption: nama = 'sticker_{}_{}.webp'.format( message.reply_to_message.sticker.date, message.reply_to_message.sticker.set_name, ) else: nama = f'{message.reply_to_message.caption}.webp'.replace( ' ', '_', ) await client.download_media( message.reply_to_message.sticker, file_name='skynoid/downloads/' + nama, progress=lambda d, t: client.loop.create_task( progressdl(d, t, message, c_time, 'Downloading...'), ), ) elif message.reply_to_message.audio: if message.reply_to_message.caption: nama = f'{message.reply_to_message.caption}.mp3'.replace( ' ', '_', ) else: nama = 'audio_{}.mp3'.format( message.reply_to_message.audio.date, ) await client.download_media( message.reply_to_message.audio, file_name='skynoid/downloads/' + nama, progress=lambda d, t: client.loop.create_task( progressdl(d, t, message, c_time, 'Downloading...'), ), ) elif message.reply_to_message.voice: if message.reply_to_message.caption: nama = f'{message.reply_to_message.caption}.ogg'.replace( ' ', '_', ) else: nama = 'audio_{}.ogg'.format( message.reply_to_message.voice.date, ) await client.download_media( message.reply_to_message.voice, file_name='skynoid/downloads/' + nama, progress=lambda d, t: client.loop.create_task( progressdl(d, t, message, c_time, 'Downloading...'), ), ) elif message.reply_to_message.document: nama = f'{message.reply_to_message.document.file_name}' await client.download_media( message.reply_to_message.document, file_name='skynoid/downloads/' + nama, progress=lambda d, t: client.loop.create_task( progressdl(d, t, message, c_time, 'Downloading...'), ), ) else: await edit_or_reply(message, text='Unknown file!') return upload = drive.CreateFile( { 'parents': [{ 'kind': 'drive#fileLink', 'id': drive_dir }], 'title': nama, }, ) upload.SetContentFile('skynoid/downloads/' + nama) upload.Upload() upload.InsertPermission( { 'type': 'anyone', 'value': 'anyone', 'role': 'reader' }, ) await edit_or_reply( message, text='Done!\nDownload link: [{}]({})'.format( nama, upload['alternateLink'], ), ) os.remove('skynoid/downloads/' + nama) else: await edit_or_reply( message, text='Reply document to mirror it to gdrive', ) elif len(message.text.split(), ) == 3 and message.text.split()[1] == 'urlmirror': await edit_or_reply(message, text='Downloading...') URL = message.text.split()[2] nama = URL.split('/')[-1] time_dl = await download_url(URL, nama) if 'Downloaded' not in time_dl: await edit_or_reply( message, text='Failed to download file, invaild url!', ) return await edit_or_reply( message, text=f'Downloaded with {time_dl}.\nNow uploading...', ) upload = drive.CreateFile( { 'parents': [ { 'kind': 'drive#fileLink', 'id': drive_dir, }, ], 'title': nama, }, ) upload.SetContentFile('skynoid/downloads/' + nama) upload.Upload() upload.InsertPermission( { 'type': 'anyone', 'value': 'anyone', 'role': 'reader' }, ) await edit_or_reply( message, text='Done!\nDownload link: [{}]({})'.format( nama, upload['alternateLink'], ), ) os.remove('skynoid/downloads/' + nama) else: await edit_or_reply( message, text='Usage:\n-> `gdrive download <url/gid>`\n' '->`gdrive upload <file>`\n' '->`gdrive mirror <url/gid>`\n\nFor ' 'more information about this, go to your assistant.', )