Ejemplo n.º 1
0
async def stop_filter(_, m: Message):
    args = m.command

    if len(args) < 1:
        return await m.reply_text("What should I stop replying to?")

    chat_filters = db.get_all_filters(m.chat.id)
    act_filters = {j for i in chat_filters for j in i.split("|")}

    if not chat_filters:
        return await m.reply_text("No filters active here!")

    for keyword in act_filters:
        if keyword == m.text.split(None, 1)[1].lower():
            db.rm_filter(m.chat.id, m.text.split(None, 1)[1].lower())
            LOGGER.info(
                f"{m.from_user.id} removed filter ({keyword}) in {m.chat.id}")
            await m.reply_text(
                f"Фильтр был успешно удален в чате <b>{m.chat.title}</b>.", )
            await m.stop_propagation()

    await m.reply_text(
        "That's not a filter - Click: /filters to get currently active filters.",
    )
    await m.stop_propagation()
Ejemplo n.º 2
0
async def stop_filter(_, m: Message):
    args = m.command

    if len(args) < 2:
        await m.reply_text("What should I stop replying to?")
        return

    chat_filters = db.get_all_filters(m.chat.id)
    act_filters = {j for i in chat_filters for j in i.split("|")}

    if not chat_filters:
        await m.reply_text("No filters active here!")
        return

    for keyword in act_filters:
        if keyword == args[1]:
            db.rm_filter(m.chat.id, args[1])
            LOGGER.info(
                f"{m.from_user.id} removed filter ({keyword}) in {m.chat.id}")
            await m.reply_text(
                f"Okay, I'll stop replying to that filter and it's aliases in <b>{m.chat.title}</b>.",
            )
            await m.stop_propagation()

    await m.reply_text(
        "That's not a filter - Click: /filters to get currently active filters.",
    )
    await m.stop_propagation()
Ejemplo n.º 3
0
async def add_filter(_, m: Message):

    args = m.text.split(" ", 1)
    all_filters = db.get_all_filters(m.chat.id)
    actual_filters = {j for i in all_filters for j in i.split("|")}

    if (len(all_filters) >= 50) and (len(actual_filters) >= 150):
        await m.reply_text(
            "Only 50 filters and 150 aliases are allowed per chat!\nTo add more filters, remove the existing ones.",
        )
        return

    if not m.reply_to_message and len(m.text.split()) < 3:
        return await m.reply_text("Please read help section for how to save a filter!")

    if m.reply_to_message and len(args) < 2:
        return await m.reply_text("Please read help section for how to save a filter!")

    extracted = await split_quotes(args[1])
    keyword = extracted[0].lower()

    for k in keyword.split("|"):
        if k in actual_filters:
            return await m.reply_text(f"Filter <code>{k}</code> already exists!")

    if not keyword:
        return await m.reply_text(
            f"<code>{m.text}</code>\n\nError: You must give a name for this Filter!",
        )

    if keyword.startswith("<") or keyword.startswith(">"):
        return await m.reply_text("Cannot save a filter which starts with '<' or '>'")

    eee, msgtype, file_id = await get_filter_type(m)
    lol = eee if m.reply_to_message else extracted[1]
    teks = lol if msgtype == Types.TEXT else eee

    if not m.reply_to_message and msgtype == Types.TEXT and len(m.command) <= 2:
        return await m.reply_text(
            f"<code>{m.text}</code>\n\nError: There is no text in here!",
        )

    if not teks and not msgtype:
        return await m.reply_text(
            'Please provide keyword for this filter reply with!\nEnclose filter in <code>"double quotes"</code>',
        )

    if not msgtype:
        return await m.reply_text(
            "Please provide data for this filter reply with!",
        )

    add = db.save_filter(m.chat.id, keyword, teks, msgtype, file_id)
    LOGGER.info(f"{m.from_user.id} added new filter ({keyword}) in {m.chat.id}")
    if add:
        await m.reply_text(
            f"Saved filter for '<code>{', '.join(keyword.split('|'))}</code>' in <b>{m.chat.title}</b>!",
        )
    await m.stop_propagation()
Ejemplo n.º 4
0
async def rm_allfilters_callback(_, q: CallbackQuery):
    user_id = q.data.split(".")[-2]
    name = q.data.split(".")[-1]
    user_status = (await q.message.chat.get_member(user_id)).status
    if user_status != "creator":
        await q.message.edit((
            f"You're an admin {await mention_html(name, user_id)}, not owner!\n"
            "Stay in your limits!"), )
        return
    db.rm_all_filters(q.message.chat.id)
    await q.message.edit_text("Cleared all filters for {q.message.chat.id}")
    LOGGER.info(f"{user_id} removed all filter from {q.message.chat.id}")
    await q.answer("Cleared all Filters!", show_alert=True)
    return
Ejemplo n.º 5
0
async def view_filters(_, m: Message):
    LOGGER.info(f"{m.from_user.id} checking filters in {m.chat.id}")

    filters_chat = f"Список фильтров в чате <b>{m.chat.title}</b>:\n"
    all_filters = db.get_all_filters(m.chat.id)
    actual_filters = [j for i in all_filters for j in i.split("|")]

    if not actual_filters:
        await m.reply_text(f"Нет фильтров в чате {m.chat.title}")
        return

    filters_chat += "\n".join([
        f" • {' | '.join([f'<code>{i}</code>' for i in i.split('|')])}"
        for i in all_filters
    ], )
    return await m.reply_text(filters_chat, disable_web_page_preview=True)
Ejemplo n.º 6
0
async def view_filters(_, m: Message):

    LOGGER.info(f"{m.from_user.id} checking filters in {m.chat.id}")

    filters_chat = f"Filters in <b>{m.chat.title}</b>:\n"
    all_filters = db.get_all_filters(m.chat.id)
    actual_filters = [j for i in all_filters for j in i.split("|")]

    if not actual_filters:
        await m.reply_text(f"There are no filters in {m.chat.title}")
        return

    filters_chat += "\n".join([
        f" • {' | '.join([f'<code>{i}</code>' for i in i.split('|')])}"
        for i in all_filters
    ], )
    await m.reply_text(filters_chat)
    return
Ejemplo n.º 7
0
async def rm_allfilters_callback(_, q: CallbackQuery):
    user_id = q.from_user.id
    user_status = (await q.message.chat.get_member(user_id)).status
    if user_status not in {"creator", "administrator"}:
        await q.answer(
            "You're not even an admin, don't try this explosive shit!",
            show_alert=True,
        )
        return
    if user_status != "creator":
        await q.answer(
            "You're just an admin, not owner\nStay in your limits!",
            show_alert=True,
        )
        return
    db.rm_all_filters(q.message.chat.id)
    await q.message.edit_text(f"Cleared all filters for {q.message.chat.title}")
    LOGGER.info(f"{user_id} removed all filter from {q.message.chat.id}")
    await q.answer("Cleared all Filters!", show_alert=True)
    return
Ejemplo n.º 8
0
async def filters_watcher(c: Alita, m: Message):

    chat_filters = db.get_all_filters(m.chat.id)
    actual_filters = {j for i in chat_filters for j in i.split("|")}

    for trigger in actual_filters:
        pattern = r"( |^|[^\w])" + re_escape(trigger) + r"( |$|[^\w])"
        match = await regex_searcher(pattern, m.text.lower())
        if match:
            try:
                msgtype = await send_filter_reply(c, m, trigger)
                LOGGER.info(f"Replied with {msgtype} to {trigger} in {m.chat.id}")
            except Exception as ef:
                await m.reply_text(f"Error: {ef}")
                LOGGER.error(ef)
                LOGGER.error(format_exc())
            break
        continue
    return
Ejemplo n.º 9
0
async def send_filter_reply(c: Alita, m: Message, trigger: str):
    """Reply with assigned filter for the trigger"""
    getfilter = db.get_filter(m.chat.id, trigger)
    if m and not m.from_user:
        return

    if not getfilter:
        return await m.reply_text(
            "<b>Error:</b> Cannot find a type for this filter!!",
            quote=True,
        )

    msgtype = getfilter["msgtype"]
    if not msgtype:
        return await m.reply_text(
            "<b>Error:</b> Cannot find a type for this filter!!")

    try:
        # support for random filter texts
        splitter = "%%%"
        filter_reply = getfilter["filter_reply"].split(splitter)
        filter_reply = choice(filter_reply)
    except KeyError:
        filter_reply = ""

    parse_words = [
        "first",
        "last",
        "fullname",
        "id",
        "mention",
        "username",
        "chatname",
    ]
    text = await escape_mentions_using_curly_brackets(m, filter_reply,
                                                      parse_words)
    teks, button = await parse_button(text)
    button = await build_keyboard(button)
    button = InlineKeyboardMarkup(button) if button else None
    textt = teks
    try:
        if msgtype == Types.TEXT:
            if button:
                try:
                    await m.reply_text(
                        textt,
                        # parse_mode="markdown",
                        reply_markup=button,
                        disable_web_page_preview=True,
                        quote=True,
                    )
                    return
                except RPCError as ef:
                    await m.reply_text(
                        "An error has occured! Cannot parse note.",
                        quote=True,
                    )
                    LOGGER.error(ef)
                    LOGGER.error(format_exc())
                    return
            else:
                await m.reply_text(
                    textt,
                    # parse_mode="markdown",
                    quote=True,
                    disable_web_page_preview=True,
                )
                return

        elif msgtype in (
                Types.STICKER,
                Types.VIDEO_NOTE,
                Types.CONTACT,
                Types.ANIMATED_STICKER,
        ):
            await (await send_cmd(c, msgtype))(
                m.chat.id,
                getfilter["fileid"],
                reply_markup=button,
                reply_to_message_id=m.message_id,
            )
        else:
            await (await send_cmd(c, msgtype))(
                m.chat.id,
                getfilter["fileid"],
                caption=textt,
                #   parse_mode="markdown",
                reply_markup=button,
                reply_to_message_id=m.message_id,
            )
    except Exception as ef:
        await m.reply_text(f"Error in filters: {ef}")
        return msgtype

    return msgtype
Ejemplo n.º 10
0
async def add_filter(_, m: Message):

    args = m.text.split(None, 1)
    all_filters = db.get_all_filters(m.chat.id)
    actual_filters = {j for i in all_filters for j in i.split("|")}

    if (len(all_filters) >= 50) and (len(actual_filters) >= 120):
        await m.reply_text(
            "Only 50 filters and 120 aliases are allowed per chat!\nTo  add more filters, remove the existing ones.",
        )
        return

    if not m.reply_to_message and len(m.text.split()) < 3:
        await m.reply_text(
            "Please provide keyboard keyword for this filter to reply with!", )
        return

    if m.reply_to_message and len(args) < 2:
        await m.reply_text(
            "Please provide keyword for this filter to reply with!")
        return

    extracted = await split_quotes(args[1])
    keyword = extracted[0].lower()

    for k in keyword.split("|"):
        if k in actual_filters:
            await m.reply_text(f"Filter <code>{k}</code> already exists!")
            return

    teks, msgtype, file_id = await get_filter_type(m)

    if not m.reply_to_message and len(m.text.split()) >= 2:
        teks, _ = await parse_button(extracted[1])
        if not teks:
            await m.reply_text(
                "There is no filter message - You can't JUST have buttons, you need a message to go with it!",
            )
            return

    elif m.reply_to_message and len(m.text.split()) >= 2:
        if m.reply_to_message.text:
            text_to_parsing = m.reply_to_message.text
        elif m.reply_to_message.caption:
            text_to_parsing = m.reply_to_message.caption
        else:
            text_to_parsing = ""
        teks, _ = await parse_button(text_to_parsing)

    elif not teks and not msgtype:
        await m.reply_text(
            'Please provide keyword for this filter reply with!\nEnclose filter in <code>"double quotes"</code>',
        )
        return

    elif m.reply_to_message:

        if m.reply_to_message.text:
            text_to_parsing = m.reply_to_message.text
        elif m.reply_to_message.caption:
            text_to_parsing = m.reply_to_message.caption
        else:
            text_to_parsing = ""

        teks, _ = await parse_button(text_to_parsing)
        if (m.reply_to_message.text
                or m.reply_to_message.caption) and not teks:
            await m.reply_text(
                "There is no filter message - You can't JUST have buttons, you need a message to go with it!",
            )
            return

    else:
        await m.reply_text("Invalid filter!")
        return

    add = db.save_filter(m.chat.id, keyword, teks, msgtype, file_id)
    LOGGER.info(
        f"{m.from_user.id} added new filter ({keyword}) in {m.chat.id}")
    if add:
        await m.reply_text(
            f"Saved filter for '<code>{', '.join(keyword.split('|'))}</code>' in <b>{m.chat.title}</b>!",
        )
    await m.stop_propagation()