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 += "│ • {}\n".format(x) 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 pin_message(client, message): if message.chat.type in ["group", "supergroup"]: can_pin = await admin_check(message) if can_pin: try: if message.reply_to_message: disable_notification = True if len(message.command) >= 2 and message.command[1] in [ "alert", "notify", "loud", ]: disable_notification = False await client.pin_chat_message( message.chat.id, message.reply_to_message.message_id, disable_notification=disable_notification, ) else: await edit_or_reply(message, text=tld("pin_message")) await asyncio.sleep(5) await message.delete() except Exception as e: await edit_or_reply(message, text="`Error!`\n" f"**Log:** `{e}`") return else: await edit_or_reply(message, text=tld("denied_permission")) await asyncio.sleep(5) await message.delete() else: await message.delete()
async def kick_user(client, message): if message.chat.type in ["group", "supergroup"]: chat_id = message.chat.id can_kick = await admin_check(message) if can_kick: try: if message.reply_to_message: user_id = message.reply_to_message.from_user.id else: usr = await client.get_users(message.command[1]) user_id = usr.id except IndexError: await edit_or_reply(message, text="must give a user to kick") return try: get_mem = await client.get_chat_member(chat_id, user_id) await client.kick_chat_member(chat_id, get_mem.user.id, int(time.time() + 45)) await message.delete() except ChatAdminRequired: await edit_or_reply(message, text=tld("denied_permission")) return except Exception as e: await edit_or_reply(message, text="`Error!`\n" f"**Log:** `{e}`") return else: await edit_or_reply(message, text=tld("denied_permission")) else: await message.delete()
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 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 kick_user(client, message): if message.chat.type in ['group', 'supergroup']: chat_id = message.chat.id can_kick = await admin_check(message) if can_kick: try: if message.reply_to_message: user_id = message.reply_to_message.from_user.id else: usr = await client.get_users(message.command[1]) user_id = usr.id except IndexError: await edit_or_reply(message, text='Give me a user to kick') return try: get_mem = await client.get_chat_member(chat_id, user_id) await client.kick_chat_member( chat_id, get_mem.user.id, int(time.time() + 45), ) await message.delete() except ChatAdminRequired: await edit_or_reply(message, text=tld('denied_permission')) return except Exception as e: await edit_or_reply( message, text='`Error occured!`\n' f'**Log:** `{e}`', ) return else: await edit_or_reply(message, text=tld('denied_permission')) else: await message.delete()
async def unpin_message(client, message): if message.chat.type in ["group", "supergroup"]: chat_id = message.chat.id can_pin = await admin_check(message) if can_pin: try: await client.unpin_chat_message(chat_id) except UsernameInvalid: await edit_or_reply(message, text="`invalid username`") return except PeerIdInvalid: await edit_or_reply(message, text="`invalid username or userid`") return except UserIdInvalid: await edit_or_reply(message, text="`invalid userid`") return except ChatAdminRequired: await edit_or_reply(message, text=tld("denied_permission")) return except Exception as e: await edit_or_reply(message, text=f"`Error!`\n**Log:** `{e}`") return else: await edit_or_reply(message, text=tld("denied_permission")) else: await message.delete()
async def pin_message(client, message): if message.chat.type in ['group', 'supergroup']: can_pin = await admin_check(message) if can_pin: try: if message.reply_to_message: disable_notification = True if len(message.command) >= 2 and message.command[1] in [ 'alert', 'notify', 'loud', ]: disable_notification = False await client.pin_chat_message( message.chat.id, message.reply_to_message.message_id, disable_notification=disable_notification, ) else: await edit_or_reply(message, text=tld('pin_message')) await asyncio.sleep(5) await message.delete() except Exception as e: await edit_or_reply( message, text='`Error occured!`\n' f'**Log:** `{e}`', ) return else: await edit_or_reply(message, text=tld('denied_permission')) await asyncio.sleep(5) await message.delete() else: await message.delete()
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", 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 = [ [ 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"), ], [ 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"), ], [ 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("РЌђ№ИЈ", callback_data="language_back")], ] try: await query.message.edit( text, parse_mode="markdown", reply_markup=InlineKeyboardMarkup(buttons), ) await query.answer() except errors.exceptions.bad_request_400.MessageNotModified: return
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', 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'), ), 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 get_text_settings(): me = await is_userbot_run() 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 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 NANA_IMG: await message.reply_photo( NANA_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 invite_link(client, message): if message.chat.type in ["group", "supergroup"]: chat_name = message.chat.title can_invite = await admin_check(message) if can_invite: try: link = await client.export_chat_invite_link(message.chat.id) await edit_or_reply(message, text=tld("invite_link").format( chat_name, link)) except Exception as e: print(e) await edit_or_reply(message, text=tld("denied_permission")) else: await message.delete()
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'Nana 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 demote_usr(client, message): if message.chat.type in ['group', 'supergroup']: chat_id = message.chat.id can_demote = await admin_check(message) if can_demote: try: if message.reply_to_message: user_id = message.reply_to_message.from_user.id else: usr = await client.get_users(message.command[1]) user_id = usr.id except IndexError: await edit_or_reply(message, text='I cant demote the void xD') return try: await client.promote_chat_member( chat_id, user_id, can_change_info=False, can_delete_messages=False, can_restrict_members=False, can_invite_users=False, can_pin_messages=False, ) await message.delete() except ChatAdminRequired: await edit_or_reply(message, text=tld('denied_permission')) await asyncio.sleep(5) await message.delete() return else: await message.delete()
async def reboot_bot(client, query): try: await restart_all() except ConnectionError: await client.answer_callback_query(query.id, tld("settings_bot_stoprestart_err")) return text = await get_text_settings() text += tld("settings_stats_botrestart") button = await get_button_settings() 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_bot_restarting"))
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 alive_func(answers): buttons = InlineKeyboard(row_width=1) try: me = await app.get_me() except ConnectionError: me = None nana_stats = 'stopped' if not me else 'alive' buttons.add(InlineKeyboardButton( '🏓', callback_data='alive_message', ), ) answers.append( InlineQueryResultArticle( title='Alive', description='Nana Userbot', input_message_content=InputTextMessageContent( tld('alive_str').format( nana_stats, USERBOT_VERSION, __version__, python_version(), DB_AVAILABLE, ), parse_mode='markdown', disable_web_page_preview=True, ), reply_markup=buttons, ), )
async def view_perm(client, message): """view group permission.""" if message.chat.type in ["group", "supergroup"]: v_perm = "" vmsg = "" vmedia = "" vstickers = "" vanimations = "" vgames = "" vinlinebots = "" vwebprev = "" vpolls = "" vinfo = "" vinvite = "" vpin = "" v_perm = await client.get_chat(message.chat.id) def convert_to_emoji(val: bool): if val: return "<code>True</code>" return "<code>False</code>" vmsg = convert_to_emoji(v_perm.permissions.can_send_messages) vmedia = convert_to_emoji(v_perm.permissions.can_send_media_messages) vstickers = convert_to_emoji(v_perm.permissions.can_send_stickers) vanimations = convert_to_emoji(v_perm.permissions.can_send_animations) vgames = convert_to_emoji(v_perm.permissions.can_send_games) vinlinebots = convert_to_emoji(v_perm.permissions.can_use_inline_bots) vwebprev = convert_to_emoji( v_perm.permissions.can_add_web_page_previews) vpolls = convert_to_emoji(v_perm.permissions.can_send_polls) vinfo = convert_to_emoji(v_perm.permissions.can_change_info) vinvite = convert_to_emoji(v_perm.permissions.can_invite_users) vpin = convert_to_emoji(v_perm.permissions.can_pin_messages) if v_perm is not None: try: await edit_or_reply( message, text=tld("permission_view_str").format( vmsg, vmedia, vstickers, vanimations, vgames, vinlinebots, vwebprev, vpolls, vinfo, vinvite, vpin, ), ) except Exception as e: await edit_or_reply(message, text="`Error!`\n" f"**Log:** `{e}`") else: await message.delete()
async def unmute(client, message): if message.chat.type in ["group", "supergroup"]: can_unmute = await admin_check(message) if can_unmute: try: if message.reply_to_message: user_id = message.reply_to_message.from_user.id else: usr = await client.get_users(message.command[1]) user_id = usr.id except IndexError: await edit_or_reply(message, text="must give a user to unmute") return try: await client.restrict_chat_member( chat_id=message.chat.id, user_id=user_id, permissions=unmute_permissions, ) await message.delete() except ChatAdminRequired: await edit_or_reply(message, text=tld("denied_permission")) return except Exception as e: await edit_or_reply(message, text="`Error!`\n" f"**Log:** `{e}`") return else: await message.delete()
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='`@dank_as_fuck 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 unmute(client, message): if message.chat.type in ['group', 'supergroup']: can_unmute = await admin_check(message) if can_unmute: try: if message.reply_to_message: user_id = message.reply_to_message.from_user.id else: usr = await client.get_users(message.command[1]) user_id = usr.id except IndexError: await edit_or_reply(message, text='Give me a user to mute') return try: await client.restrict_chat_member( chat_id=message.chat.id, user_id=user_id, permissions=unmute_permissions, ) await message.delete() except ChatAdminRequired: await edit_or_reply(message, text=tld('denied_permission')) return except Exception as e: await edit_or_reply( message, text='`Error occured!`\n' f'**Log:** `{e}`', ) return else: await message.delete()
async def ban_usr(client, message): if message.chat.type in ['group', 'supergroup']: chat_id = message.chat.id can_ban = await admin_check(message) if can_ban: try: if message.reply_to_message: user_id = message.reply_to_message.from_user.id else: usr = await client.get_users(message.command[1]) user_id = usr.id except IndexError: await edit_or_reply(message, text='I cant ban a void xD') return if user_id: try: await client.kick_chat_member(chat_id, user_id) await message.delete() except UsernameInvalid: await edit_or_reply(message, text='`Invalid username`') return except PeerIdInvalid: await edit_or_reply( message, text='`Invalid username or ID`', ) return except UserIdInvalid: await edit_or_reply(message, text='`invalid userid`') return except ChatAdminRequired: await edit_or_reply(message, text=tld('denied_permission')) return except Exception as e: await edit_or_reply(message, text=f'**Log:** `{e}`') return else: await edit_or_reply(message, text=tld('denied_permission')) return else: await message.delete()
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 = InlineKeyboardMarkup([[ InlineKeyboardButton(text=tld("help_btn"), callback_data="help_back"), ]]) if NANA_IMG: await message.reply_photo( NANA_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_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"Nana 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 = InlineKeyboardMarkup([[ InlineKeyboardButton(tld("update_now_btn"), callback_data="update_now") ]]) await setbot.send_message(Owner, text, reply_markup=button, parse_mode="markdown")
async def deleted_clean(client, message): cmd = message.command chat_id = message.chat.id get_group = await client.get_chat(chat_id) clean_tag = ' '.join(cmd[1:]) rm_delaccs = 'clean' in clean_tag can_clean = await admin_check(message) del_stats = '`No deleted accounts found in this chat.`' del_users = 0 if rm_delaccs: if can_clean: await edit_or_reply( message, text='`Removing deleted accounts in this chat...`', ) del_admins = 0 del_total = 0 async for member in client.iter_chat_members(chat_id): if member.user.is_deleted: try: await client.kick_chat_member( chat_id, member.user.id, int(time.time() + 45), ) except UserAdminInvalid: del_users -= 1 del_admins += 1 except FloodWait as e: await asyncio.sleep(e.x) del_users += 1 del_total += 1 del_stats = f'`Found` **{del_total}** `total accounts..`' await edit_or_reply(message, text=del_stats) await message.edit( f'**Finished Removing Deleted Accounts**:\n' f'Total Deleted Accounts: `{del_total}`\n' f'Removed Deleted Accounts: `{del_users}`\n' f'Chat: `{get_group.title}` (`{chat_id}`)', ) else: await edit_or_reply(message, text=tld('denied_permission')) else: async for member in client.iter_chat_members(chat_id): if member.user.is_deleted: del_users += 1 if del_users > 0: del_stats = '`Found` **{}** `in this chat.`'.format( del_users, ) await edit_or_reply(message, text=del_stats)
async def speedtestxyz_callback(client, query): if query.from_user.id in AdminSettings: await setbot.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 setbot.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 setbot.edit_inline_text(query.inline_message_id, replymsg, parse_mode="markdown") else: await client.answer_callback_query( query.id, "No, you are not allowed to do this", show_alert=False)
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', 'nana/modules/') repo.git.clean('-fd', 'nana/assistant/') repo.git.clean('-fd', 'nana/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, ), )