Esempio n. 1
0
async def prevent_approved(c: Mizuhara, m: Message):
    x = app_db.all_approved(m.chat.id)
    LOGGER.info(x)
    ul = []
    for j in x:
        ul.append(j.user_id)
    for i in ul:
        await c.restrict_chat_member(
            chat_id=m.chat.id,
            user_id=i,
            permissions=ChatPermissions(
                can_send_messages=True,
                can_send_media_messages=True,
                can_send_stickers=True,
                can_send_animations=True,
                can_send_games=True,
                can_use_inline_bots=True,
                can_add_web_page_previews=True,
                can_send_polls=True,
                can_change_info=True,
                can_invite_users=True,
                can_pin_messages=True,
            ),
        )
        LOGGER.info(f"Approved {i} in {m.chat.id}")
        await asyncio.sleep(0.2)

    return
Esempio n. 2
0
    async def start(self):
        await super().start()

        me = await self.get_me()  # Get bot info from pyrogram client
        LOGGER.info("Starting bot...")
        """Redis Content Setup!"""
        await self.get_admins()  # Load admins in cache
        set_key("SUPPORT_STAFF", SUPPORT_STAFF)  # Load SUPPORT_STAFF in cache
        set_key("BOT_ID", int(me.id))  # Save Bot ID in Redis!
        """Redis Content Setup!"""

        # Show in Log that bot has started
        LOGGER.info(
            f"Pyrogram v{__version__}\n(Layer - {layer}) started on @{me.username}"
        )
        LOGGER.info(load_cmds(ALL_PLUGINS))
        LOGGER.info(f"Redis Keys Loaded: {allkeys()}")

        # Send a message to MESSAGE_DUMP telling that the bot has started and has loaded all plugins!
        await self.send_message(
            MESSAGE_DUMP,
            (f"<b><i>Bot started on Pyrogram v{__version__} (Layer - {layer})</i></b>\n\n"
             "<b>Loaded Plugins:</b>\n"
             f"<i>{list(HELP_COMMANDS.keys())}</i>\n"
             "<b>Redis Keys Loaded:</b>\n"
             f"<i>{allkeys()}</i>"),
        )

        LOGGER.info("Bot Started Successfully!")
Esempio n. 3
0
async def del_blacklist(c: Mizuhara, m: Message):
    try:
        user_list = []
        approved_users = app_db.all_approved(m.chat.id)
        for auser in approved_users:
            user_list.append(int(auser.user_id))
        async for i in m.chat.iter_members(filter="administrators"):
            user_list.append(i.user.id)
        if m.from_user.id in user_list:
            del user_list  # Reset Admin list, just in case new admins are added!
            return
        if m.text:
            chat_filters = db.get_chat_blacklist(m.chat.id)
            if not chat_filters:
                return
            for trigger in chat_filters:
                pattern = r"( |^|[^\w])" + trigger + r"( |$|[^\w])"
                match = regex_searcher(pattern, m.text.lower())
                if not match:
                    continue
                if match:
                    try:
                        await m.delete()
                    except Exception as ef:
                        LOGGER.info(ef)
                    break
    except AttributeError:
        pass  # Skip attribute errors!
Esempio n. 4
0
async def gban_watcher(c: Mizuhara, m: Message):
    try:
        if db.is_user_gbanned(m.from_user.id):
            try:
                await c.kick_chat_member(m.chat.id, m.from_user.id)
                await m.reply_text((
                    f"This user ({mention_html(m.from_user.first_name, m.from_user.id)}) "
                    "has been banned globally!\n\n"
                    f"To get unbanned appeal at {SUPPORT_GROUP}"), )
                LOGGER.info(f"Banned user {m.from_user.id} in {m.chat.id}")
                return
            except (errors.ChatAdminRequired or errors.UserAdminInvalid):
                # Bot not admin in group and hence cannot ban users!
                # TO-DO - Improve Error Detection
                LOGGER.info(
                    f"User ({m.from_user.id}) is admin in group {m.chat.name} ({m.chat.id})"
                )
                pass
            except Exception as excp:
                await c.send_message(
                    MESSAGE_DUMP,
                    f"<b>Gban Watcher Error!</b>\n<b>Chat:</b> {m.chat.id}\n<b>Error:</b> `{excp}`",
                )
    except AttributeError:
        pass  # Skip attribute errors!
    return
Esempio n. 5
0
async def migrate_chat(old_chat, new_chat):
    LOGGER.info(f"Migrating from {str(old_chat)} to {str(new_chat)}")
    userdb.migrate_chat(old_chat, new_chat)
    langdb.migrate_chat(old_chat, new_chat)
    ruledb.migrate_chat(old_chat, new_chat)
    bldb.migrate_chat(old_chat, new_chat)
    notedb.migrate_chat(old_chat, new_chat)
    LOGGER.info("Successfully migrated!")
Esempio n. 6
0
 async def stop(self, *args):
     # Send a message to MESSAGE_DUMP telling that the bot has stopped!
     await self.send_message(
         MESSAGE_DUMP,
         "<i><b>Bot Stopped!</b></i>",
     )
     await super().stop()
     # Flush Redis data
     try:
         flushredis()
         LOGGER.info("Flushed Redis!")
     except Exception as ef:
         LOGGER.error(ef)
     LOGGER.info("Bot Stopped.\nkthxbye!")
Esempio n. 7
0
async def reload_admins(c: Mizuhara, m: Message):

    _ = GetLang(m).strs

    res = await admin_check(c, m)
    if not res:
        return

    ADMINDICT = get_key("ADMINDICT")  # Load ADMINDICT from string

    try:
        adminlist = []
        async for i in m.chat.iter_members(filter="administrators"):
            adminlist.append(i.user.id)
        ADMINDICT[str(m.chat.id)] = adminlist
        set_key("ADMINDICT", ADMINDICT)
        await m.reply_text(_("admin.reloadedadmins"))
        LOGGER.info(f"Reloaded admins for {m.chat.title}({m.chat.id})")
    except Exception as ef:
        await m.reply_text(_("admin.useadmincache"))
        LOGGER.error(ef)

    return
Esempio n. 8
0
    async def get_admins(self):
        LOGGER.info("Begin caching admins...")
        begin = time.time()
        c = self

        # Flush Redis data
        try:
            flushredis()
        except Exception as ef:
            LOGGER.error(ef)

        # Get bot info
        me = await self.get_me()

        all_chats = userdb.get_all_chats() or []  # Get list of all chats
        LOGGER.info(f"{len(all_chats)} chats loaded.")
        ADMINDICT = {}
        for chat in all_chats:
            adminlist = []
            try:
                async for i in c.iter_chat_members(chat_id=chat.chat_id,
                                                   filter="administrators"):
                    adminlist.append(i.user.id)

                ADMINDICT[str(
                    chat.chat_id)] = adminlist  # Remove the last space

                LOGGER.info(
                    f"Set {len(adminlist)} admins for {chat.chat_id}\n{adminlist}"
                )
                del adminlist  # Delete list var
            except errors.PeerIdInvalid:
                pass
            except Exception as ef:
                LOGGER.error(ef)

        try:
            set_key("ADMINDICT", ADMINDICT)
            del ADMINDICT
            end = time.time()
            LOGGER.info(
                f"Set admin list cache!\nTime Taken: {round(end-begin, 2)}s")
        except Exception as ef:
            LOGGER.error(f"Could not set ADMINDICT!\n{ef}")