Example #1
0
async def locale_button(client, query):
    lang_match = re.findall(r"en-US|hi", 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]]))
        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("English (US) 🇺🇸",
                             callback_data="set_lang_en-US"),
        InlineKeyboardButton("Hindi 🇮🇳", callback_data="set_lang_hi")
    ]]
    await client.edit_message_text(chat_id=Owner,
                                   message_id=query.message.message_id,
                                   text=text,
                                   parse_mode='markdown',
                                   reply_markup=InlineKeyboardMarkup(buttons))
    await client.answer_callback_query(query.id)
Example #2
0
async def start(_client, 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"),
            InlineKeyboardButton('Language', callback_data='set_lang_')
        ]])
        if NANA_IMG:
            await setbot.send_photo(message.chat.id,
                                    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)
Example #3
0
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:
            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 edrep(message, text=teks)
Example #4
0
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") for a in alladmins
        if a.status in ["administrator", "creator"] and not a.user.is_bot
    ]

    if message.reply_to_message:
        if text:
            teks = '{}'.format(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")
Example #5
0
async def unban_usr(client, message):
    if message.chat.type in ["group", "supergroup"]:
        chat_id = message.chat.id
        can_unban = await admin_check(message)
        if can_unban:
            if message.reply_to_message:
                try:
                    get_mem = await client.get_chat_member(
                        chat_id, message.reply_to_message.from_user.id)
                    await client.unban_chat_member(chat_id, get_mem.user.id)
                    await message.delete()

                except Exception as e:
                    await edrep(message, text=f"**Log:** `{e}`")
                    return

            else:
                await edrep(message, text=tld('unban_user'))
                await asyncio.sleep(5)
                await message.delete()
                return
        else:
            await edrep(message, text=tld('denied_permission'))
            await asyncio.sleep(5)
            await message.delete()
    else:
        await message.delete()
Example #6
0
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:
                    await client.restrict_chat_member(
                        chat_id=message.chat.id,
                        user_id=message.reply_to_message.from_user.id,
                        permissions=unmute_permissions,
                    )
                else:
                    await edrep(message, text=tld('unmute_user'))
                    await asyncio.sleep(5)
                await message.delete()

            except Exception as e:
                await edrep(message, text=f'`Error!`\n**Log:** `{e}`')
                return
        else:
            await edrep(message, text=tld('denied_permission'))
            await asyncio.sleep(5)
            await message.delete()
    else:
        await message.delete()
Example #7
0
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:
            if message.reply_to_message:

                try:
                    get_mem = await client.get_chat_member(
                        chat_id, message.reply_to_message.from_user.id)
                    await client.kick_chat_member(chat_id, get_mem.user.id,
                                                  int(time.time() + 45))
                    await message.delete()
                except ChatAdminRequired:
                    await edrep(message, text=tld('denied_permission'))
                    await asyncio.sleep(5)
                    await message.delete()
                    return

                except Exception as e:
                    await edrep(message, text="`Error!`\n" f"**Log:** `{e}`")
                    return

            else:
                await edrep(message, text=tld('kick_user'))
                await asyncio.sleep(5)
                await message.delete()
                return

        else:
            await edrep(message, text=tld('denied_permission'))
            await asyncio.sleep(5)
            await message.delete()
    else:
        await message.delete()
Example #8
0
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 edrep(message, text="`invalid username`")
                return

            except PeerIdInvalid:
                await edrep(message, text="`invalid username or userid`")
                return

            except UserIdInvalid:
                await edrep(message, text="`invalid userid`")
                return

            except ChatAdminRequired:
                await edrep(message, text=tld('denied_permission'))
                return

            except Exception as e:
                await edrep(message, text=f"`Error!`\n**Log:** `{e}`")
                return
        else:
            await edrep(message, text=tld('denied_permission'))
    else:
        await message.delete()
Example #9
0
async def mute_hammer(client, message):
    if message.chat.type in ["group", "supergroup"]:
        can_mute = await admin_check(message)
        if can_mute:
            if message.reply_to_message:
                try:
                    if (len(message.text.split()) == 2
                            and message.text.split()[1] == "24"):
                        await client.restrict_chat_member(
                            chat_id=message.chat.id,
                            user_id=message.reply_to_message.from_user.id,
                            permissions=mute_permission,
                            until_date=int(time.time() + 86400),
                        )
                    else:
                        await client.restrict_chat_member(
                            chat_id=message.chat.id,
                            user_id=message.reply_to_message.from_user.id,
                            permissions=mute_permission,
                        )
                    await message.delete()
                except Exception as e:
                    await edrep(message, text="`Error!`\n" f"**Log:** `{e}`")
                    return
            else:
                await edrep(message, text=tld('mute_user'))
                await asyncio.sleep(5)
                await message.delete()
        else:
            await edrep(message, text=tld('denied_permission'))
            await asyncio.sleep(5)
            await message.delete()
    else:
        await message.delete()
Example #10
0
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 edrep(message, text=tld('pin_message'))
                    await asyncio.sleep(5)
                await message.delete()
            except Exception as e:
                await edrep(message, text="`Error!`\n" f"**Log:** `{e}`")
                return
        else:
            await edrep(message, text=tld('denied_permission'))
            await asyncio.sleep(5)
            await message.delete()
    else:
        await message.delete()
Example #11
0
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 edrep(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 edrep(message, text=tld('denied_permission'))
                return
            except Exception as e:
                await edrep(message, text="`Error!`\n" f"**Log:** `{e}`")
                return
        else:
            await edrep(message, text=tld('denied_permission'))
    else:
        await message.delete()
Example #12
0
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)
Example #13
0
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 = f"[{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 += f"\n - {tld('speed_test_isp')} `{result['client']['isp']}`"
            replymsg += f"\n - {tld('speed_test_download')} `{speed_convert(result['download'])}`"
            replymsg += (
                f"\n - {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
        )
Example #14
0
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"
                    ),
                    InlineKeyboardButton(
                        tld("language_btn"), callback_data="set_lang_"
                    ),
                ]
            ]
        )
        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,
            )
Example #15
0
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",
        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("🇺🇸", callback_data="set_lang_en-US"),
            InlineKeyboardButton("🇮🇳", callback_data="set_lang_hi"),
            InlineKeyboardButton("🇮🇱", callback_data="set_lang_he"),
            InlineKeyboardButton("🇮🇩", callback_data="set_lang_id"),
            InlineKeyboardButton("🇮🇷", callback_data="set_lang_fa"),
        ],
        [
            InlineKeyboardButton("🇯🇵", callback_data="set_lang_ja"),
            InlineKeyboardButton("🇬🇷", callback_data="set_lang_el"),
            InlineKeyboardButton("🇲🇻", callback_data="set_lang_dv"),
            InlineKeyboardButton("🇪🇸", callback_data="set_lang_es"),
            InlineKeyboardButton("🇩🇪", callback_data="set_lang_de"),
        ],
        [
            InlineKeyboardButton("🇱🇰", callback_data="set_lang_ta"),
            InlineKeyboardButton("🇧🇷", callback_data="set_lang_pt-br"),
            InlineKeyboardButton("🇸🇦", callback_data="set_lang_pt-ar"),
        ],
        [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
Example #16
0
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
Example #17
0
async def adminlist(client, message):
    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:
            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 += "│ • {}\n".format(x)
        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 += "│ • {}\n".format(x)
        if len(teks) >= 4096:
            await message.reply(message.chat.id, teks, reply_to_message_id=replyid)
            teks = ""
            toolong = True
    teks += tld('adminlist_three').format(len(badmin))
    for x in badmin:
        teks += "│ • {}\n".format(x)
        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 edrep(message, text=teks)
Example #18
0
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 edrep(message, text=tld('invite_link').format(chat_name, link))
            except Exception as e:
                print(e)
                await edrep(message, text=tld('denied_permission'))
    else:
        await message.delete()
Example #19
0
async def lang_back(_, query):
    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"
                ),
                InlineKeyboardButton(
                    tld("language_btn"),
                    callback_data="set_lang_"
                ),
            ]
        ]
    )
    if NANA_IMG:
        await query.message.edit_caption(
            tld("start_message").format(
                OwnerName,
                python_version(),
                userbot_stat,
                USERBOT_VERSION,
                ASSISTANT_VERSION,
                DB_AVAILABLE,
                db_stat,
            ),
        )
        await query.message.edit_reply_markup(buttons)
    else:
        await query.message.edit(
            tld("start_message").format(
                OwnerName,
                python_version(),
                userbot_stat,
                USERBOT_VERSION,
                ASSISTANT_VERSION,
                DB_AVAILABLE,
                db_stat,
            ),
            reply_markup=buttons,
        )
    await query.answer()
Example #20
0
async def mute_hammer(client, message):
    if message.chat.type in ['group', 'supergroup']:
        chat_id = message.chat.id
        can_mute = await admin_check(message)
        if can_mute:
            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 message.reply('some ooga booga')
                return
            try:
                await client.restrict_chat_member(chat_id=message.chat.id,
                                                  user_id=user_id,
                                                  permissions=mute_permission)
                await message.delete()
            except Exception as e:
                await edrep(message, text="`Error!`\n" f"**Log:** `{e}`")
                return
        else:
            await edrep(message, text=tld('denied_permission'))
    else:
        await message.delete()
Example #21
0
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()
Example #22
0
async def gdrive_helper(_client, message):
    if len(message.text.split()) == 1:
        gdriveclient = os.path.isfile("client_secrets.json")
        if HEROKU_API:
            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(
                "Hello, look like you're not logged in to google drive 🙂\nI can help you to login.\n\nFirst of all, "
                "you need to activate your google drive API\n1. [Go here]("
                "https://developers.google.com/drive/api/v3/quickstart/python), click **Enable the drive API**\n2. "
                "Login to your google account (skip this if you're already logged in)\n3. After logged in, "
                "click **Enable the drive API** again, and click **Download Client Configuration** button, "
                "download that.\n4. After downloaded that file, open that file then copy all of that content, "
                "back to telegram then do .credentials (copy the content of that file)  do without bracket \n\nAfter "
                "that, you can go next guide by type /gdrive")
            return

        gauth.LoadCredentialsFile("nana/session/drive")
        if gauth.credentials is None:
            try:
                authurl = gauth.GetAuthUrl()
            except:
                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("nana/session/drive")
        await message.reply("You have logged out of your account!\nTo login again, just type /gdrive")
    elif len(message.text.split()) == 2:
        try:
            gauth.Auth(message.text.split()[1])
        except pydrive.auth.AuthenticationError:
            await message.reply("Your Authentication code is Wrong!")
            return
        gauth.SaveCredentialsFile("nana/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'] == 'Nana Drive':
                await message.reply("Authentication successful!\nWelcome back!")
                return
        mkdir = drive.CreateFile({'title': 'Nana Drive', "mimeType": "application/vnd.google-apps.folder"})
        mkdir.Upload()
        await message.reply("Authentication successful!\nThe 'Nana Drive' folder has been created automatically!")
    else:
        await message.reply("Invaild args!\nCheck /gdrive for usage guide")
Example #23
0
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"))
Example #24
0
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 edrep(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 edrep(message, text=tld('denied_permission'))
                return
            except Exception as e:
                await edrep(message, text="`Error!`\n" f"**Log:** `{e}`")
                return
    else:
        await message.delete()
Example #25
0
async def locale_button(client, query):
    lang_match = re.findall(r"en-US|hi|he|id|fa|el|dv|es|ja", 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]]))
        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("🇺🇸 English (US)",
                                 callback_data="set_lang_en-US"),
            InlineKeyboardButton("🇮🇳 हिंदी", callback_data="set_lang_hi"),
        ],
        [
            InlineKeyboardButton("🇮🇱 עברית", callback_data="set_lang_he"),
            InlineKeyboardButton("🇮🇩 bahasa Indonesia",
                                 callback_data="set_lang_id"),
        ],
        [
            InlineKeyboardButton("🇮🇷 فارسی", callback_data="set_lang_fa"),
            InlineKeyboardButton("🇯🇵 日本人", callback_data="set_lang_ja"),
        ],
        [
            InlineKeyboardButton("🇬🇷 Ελληνικά", callback_data="set_lang_el"),
            InlineKeyboardButton("🇲🇻 ދިވެހި", callback_data="set_lang_dv"),
        ],
        [InlineKeyboardButton("🇪🇸 Espanol", callback_data="set_lang_es")],
    ]
    await client.edit_message_text(
        chat_id=Owner,
        message_id=query.message.message_id,
        text=text,
        parse_mode="markdown",
        reply_markup=InlineKeyboardMarkup(buttons),
    )
    await client.answer_callback_query(query.id)
Example #26
0
async def get_button_settings():
    me = await is_userbot_run()
    toggle = (tld("settings_userbot_stopbutton")
              if me else tld("settings_userbot_startbutton"))
    list_button = [
        [
            InlineKeyboardButton(toggle, callback_data="toggle_startbot"),
            InlineKeyboardButton(tld("settings_userbot_restartbutton"),
                                 callback_data="restart_bot"),
        ],
        [
            InlineKeyboardButton(tld("settings_setstickerbutton"),
                                 callback_data="setsticker")
        ],
    ]
    if HEROKU_API:
        list_button.append([
            InlineKeyboardButton(tld("settings_herokubutton"),
                                 callback_data="heroku_vars")
        ])
        list_button.append([
            InlineKeyboardButton(tld("settings_heroku_restartbutton"),
                                 callback_data="restart_heroku")
        ])
        list_button.append([
            InlineKeyboardButton(tld("settings_change_repo_button"),
                                 callback_data="change_repo")
        ])
    return InlineKeyboardMarkup(list_button)
Example #27
0
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 edrep(message, text="`cleaning deleted accounts from 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 edrep(message, text=del_stats)
            await message.edit(
                f"**Cleaned Deleted accounts**:\n"
                f"Total Deleted Accounts: `{del_total}`\n"
                f"Cleaned Deleted Accounts: `{del_users}`\n"
                f"Chat: `{get_group.title}` (`{chat_id}`)"
            )

        else:
            await edrep(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 = f"`Found` **{del_users}** `deleted accounts in this chat.`"
        await edrep(message, text=del_stats)
Example #28
0
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(
            f"Check update failed!\nDirectory {error} does not seems to be a git repository"
        )
        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")
Example #29
0
async def get_button_settings():
    me = await is_userbot_run()
    toggle = (tld("settings_userbot_stopbutton")
              if me else tld("settings_userbot_startbutton"))
    list_button = [
        [
            InlineKeyboardButton(toggle, callback_data="toggle_startbot"),
            InlineKeyboardButton(tld("settings_userbot_restartbutton"),
                                 callback_data="restart_bot"),
        ],
        [
            InlineKeyboardButton(tld("settings_setstickerbutton"),
                                 callback_data="setsticker")
        ],
        [
            InlineKeyboardButton("Select Branch",
                                 callback_data="change_branches")
        ],
    ]
    return InlineKeyboardMarkup(list_button)
Example #30
0
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 to get the list of possible commands.",
            reply_markup=buttons)
        return
    await help_parser(client, message.chat.id,
                      tld("help_str").format(", ".join(Command)))