Exemple #1
0
def notes_for_chat(update: Update, context: CallbackContext):
    """
    List out all the notes in a chat
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check exception
    if update.effective_chat.id in get_command_exception_chats("notes"):
        return

    # get list of notes for the chat
    notes = get_notes_for_chat(update.effective_chat.id)

    if notes:
        reply = "***Saved notes in chat***"
        for note in notes:
            reply += f"\n- `{note}`"
        reply += emojize(
            "\n\nI remember all of this! Praise me lots! :grinning_cat_face:")

        update.effective_message.reply_markdown(reply)

    else:
        update.effective_message.reply_text(
            "No one told me to remember anything, so I got high on catnip instead....."
        )
Exemple #2
0
def pin(update: Update, context: CallbackContext):
    """
    Pin a message in the chat
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check if user has enough perms
    if update.effective_chat.id not in get_command_exception_chats("admin"):
        user = update.effective_chat.get_member(update.effective_user.id)
        if not user.can_pin_messages and user.status != "creator":
            update.effective_message.reply_markdown(
                "Ask your sugar daddy to give you perms required to use the method `CanPinMessages`."
            )
            return

    # check if bot has perms to pin a message
    if (update.effective_chat.type == "supergroup"
            and not update.effective_chat.get_member(
                context.bot.id).can_pin_messages) or (
                    update.effective_chat.type == "channel"
                    and not update.effective_chat.get_member(
                        context.bot.id).can_edit_messages):
        update.effective_message.reply_text(
            "Bribe your sugar daddy with some catnip and ask him to allow me to pin messages..."
        )
        return

    # check if there is a message to pin
    if not update.effective_message.reply_to_message:
        update.effective_message.reply_text(
            "I'm a cat, not a psychic! Reply to the message you want to pin..."
        )
        return

    # for future usage
    add_user(
        user_id=update.effective_message.reply_to_message.from_user.id,
        username=update.effective_message.reply_to_message.from_user.username,
    )

    # Don't always loud pin
    if context.args:
        disable_notification = context.args[0].lower() in ("silent", "quiet")
    else:
        disable_notification = None

    # pin the message
    context.bot.pin_chat_message(
        update.effective_chat.id,
        update.effective_message.reply_to_message.message_id,
        disable_notification=disable_notification,
    )
Exemple #3
0
def reply(update: Update, context: CallbackContext) -> None:
    """
    Reply when a filter is triggered
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check for exception
    if update.effective_chat.id in get_command_exception_chats("filter"):
        return

    # check if there is any text to check
    msg = update.effective_message
    text = msg.caption if msg.text is None else msg.text
    if text is None:
        return

    # make sure it doesn't reply to message trying to stop or reset a trigger
    if search(r"^/(stop|filter)(@\S+)? .+", text):
        return

    # get triggers for the chat
    triggers = get_triggers_for_chat(update.effective_chat.id)

    for trigger in triggers:
        pattern = r"( |^|[^\w])" + escape(
            trigger) + r"( |$|[^\w])"  # regex for text containing the trigger

        if search(pattern, text, flags=IGNORECASE):
            log(update, f"reply to filter trigger `{trigger}`")

            # get content and type to reply in response to trigger
            content, filter_type = get_filter(update.effective_chat.id,
                                              trigger)

            # send reply according to type
            if filter_type == "text":
                msg.reply_markdown(content)
            elif filter_type == "sticker":
                msg.reply_sticker(content)
            elif filter_type == "document":
                msg.reply_document(content)
            elif filter_type == "photo":
                msg.reply_photo(content)
            elif filter_type == "audio":
                msg.reply_audio(content)
            elif filter_type == "voice":
                msg.reply_voice(content)
            elif filter_type == "video":
                msg.reply_video(content)

            break
Exemple #4
0
def purge(update: Update, context: CallbackContext):
    """
    Delete all messages from quoted message
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check if user has enough perms
    if update.effective_chat.type != "private" and update.effective_chat.id not in get_command_exception_chats(
            "admin"):
        user = update.effective_chat.get_member(update.effective_user.id)
        if not user.can_delete_messages and user.status != "creator":
            update.effective_message.reply_markdown(
                "Ask your sugar daddy to give you perms required to use the method `CanDeleteMessages`."
            )
            return

    # check if bot has perms to delete a message
    if (update.effective_chat.type != "private"
            and not update.effective_chat.get_member(
                context.bot.id).can_delete_messages):
        update.effective_message.reply_text(
            "Bribe your sugar daddy with some catnip and ask him to allow me to delete messages..."
        )
        return

    # check if start point is given
    if not update.effective_message.reply_to_message:
        update.effective_message.reply_text(
            "I'm a cat, not a psychic! Reply to the message you want to start deleting from..."
        )
        return

    # for future usage
    add_user(
        user_id=update.effective_message.reply_to_message.from_user.id,
        username=update.effective_message.reply_to_message.from_user.username,
    )

    # delete messages
    for id_ in range(update.effective_message.message_id - 1,
                     update.effective_message.reply_to_message.message_id - 1,
                     -1):
        try:
            context.bot.delete_message(update.effective_chat.id, id_)
        except BadRequest:
            continue

    update.effective_message.reply_text("Just like we do it in china....")
Exemple #5
0
def sauce(update: Update, context: CallbackContext) -> None:
    """
    Fetch the doujin for all the sauces given by user, make telegraph article and send it to user for easy reading
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check if any args were given
    if not context.args:
        update.effective_message.reply_text(
            "Please give some codes to fetch, this cat can't read your mind..."
        )
        return

    # check if exception for sauce is added in current chat
    exception = update.effective_chat.id in get_command_exception_chats(
        "sauce")

    # iterate over each given sauce and fetch the doujin
    for digits in context.args:
        # get basic info
        title, data, image_tags = get_info(digits)

        # create telegraph article for the doujin
        telegraph = Telegraph()
        telegraph.create_account(short_name='neko-chan-telebot')
        article_path = telegraph.create_page(title,
                                             html_content=image_tags)['path']

        # add details to the reply to be sent to the user
        text_blob = f"<code>{digits}</code>\n<a href='https://telegra.ph/{article_path}'>{title}</a>"
        for key, value in data.items():
            if value:
                text_blob += f"\n\n<code>{key}</code>\n{value}"

        # send message
        if exception:
            update.message.reply_html(text_blob)
        else:
            context.bot.send_message(chat_id=update.effective_user.id,
                                     text=text_blob,
                                     parse_mode=ParseMode.HTML)

    # if called from a chat without exception in it, then send him a reminder to check it
    if not exception and update.effective_chat.type != "private":
        update.message.reply_markdown(
            f"[Let's enjoy this together in our private chat...](https://t.me/{escape_markdown(context.bot.username)}"
        )
Exemple #6
0
def del_note_in_chat(update: Update, context: CallbackContext):
    """
    Delete a note from the chat
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check for exception
    if update.effective_chat.id in get_command_exception_chats("notes"):
        return

    if context.args:
        # iterate over the triggers given and delete them from DB
        for name in context.args:
            update.effective_message.reply_markdown(del_note(chat=update.effective_chat.id, name=name))
    else:
        update.effective_message.reply_markdown(
            "Oi, you can't make me forget something without reminding me of what to forget, baka!"
        )
Exemple #7
0
def list_filters(update: Update, context: CallbackContext):
    """
    List all the filter triggers in a chat
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check for exception
    if update.effective_chat.id in get_command_exception_chats("filter"):
        return

    filters = get_triggers_for_chat(update.effective_chat.id)
    if filters:
        update.message.reply_markdown(
            "Active filter triggers in this chat are as follows -\n`" +
            "`\n`".join(filters) + "`")
    else:
        update.message.reply_markdown(
            emojize("No active filters in this chat :crying_cat_face:"))
Exemple #8
0
def del_filter_handler(update: Update, context: CallbackContext):
    """
    Delete a filter from the chat
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check for exception
    if update.effective_chat.id in get_command_exception_chats("filter"):
        return

    if context.args:
        # iterate over the triggers given and delete them from DB
        for trigger in context.args:
            update.effective_message.reply_markdown(
                del_filter(chat=update.effective_chat.id, trigger=trigger))
    else:
        update.effective_message.reply_markdown(
            "I can't stop meowing if you don't tell me what to stop meowing to, baka!"
        )
Exemple #9
0
def fetch_note(update: Update, context: CallbackContext):
    """
    Fetch note
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check exception
    if update.effective_chat.id in get_command_exception_chats("notes"):
        return

    if update.effective_message.text[0] == "#":
        name = update.effective_message.text[1:]
    elif context.args:
        name = context.args[0]
    else:
        update.effective_message.reply_text(
            "I can't fetch a note if you don't tell me it's name, baka!")
        return

    # get note
    content, content_type = get_note(update.effective_chat.id, name)

    # send reply according to type
    if content_type == "text":
        update.effective_message.reply_markdown(content)
    elif content_type == "sticker":
        update.effective_message.reply_sticker(content)
    elif content_type == "document":
        update.effective_message.reply_document(content)
    elif content_type == "photo":
        update.effective_message.reply_photo(content)
    elif content_type == "audio":
        update.effective_message.reply_audio(content)
    elif content_type == "voice":
        update.effective_message.reply_voice(content)
    elif content_type == "video":
        update.effective_message.reply_video(content)
Exemple #10
0
def add_note_in_chat(update: Update, context: CallbackContext):
    """
    Add a note in the chat
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check exception
    if update.effective_chat.id in get_command_exception_chats("notes"):
        return

    # for ease of reference
    msg = update.effective_message

    # get name and content from the message
    try:
        name, content = msg.text_markdown.split(None, 2)[1:]
    except ValueError:
        try:
            name = context.args[0]
            content = None
        except IndexError:
            msg.reply_markdown("No name, No content....\n\nYou could've at least come with some catnip\n`._.`")
            return

    # set kwargs to be passed to add_note function
    kwargs = {"chat": update.effective_chat.id, "name": name.replace(r"\_", "_").replace(r"\*", "*")}

    # add content and content type to kwargs

    if content is not None:
        kwargs["content"] = content
        kwargs["content_type"] = "text"

    elif msg.reply_to_message:
        # for future usage
        add_user(
            user_id=update.effective_message.reply_to_message.from_user.id,
            username=update.effective_message.reply_to_message.from_user.username,
        )

        if msg.reply_to_message.text_markdown:
            kwargs["content"] = msg.reply_to_message.text_markdown
            kwargs["content_type"] = "text"

        elif msg.reply_to_message.sticker:
            kwargs["content"] = msg.reply_to_message.sticker.file_id
            kwargs["content_type"] = "sticker"

        elif msg.reply_to_message.document:
            kwargs["content"] = msg.reply_to_message.document.file_id
            kwargs["content_type"] = "document"

        elif msg.reply_to_message.photo:
            kwargs["content"] = msg.reply_to_message.photo[-1].file_id
            kwargs["content_type"] = "photo"

        elif msg.reply_to_message.audio:
            kwargs["content"] = msg.reply_to_message.audio.file_id
            kwargs["content_type"] = "audio"

        elif msg.reply_to_message.voice:
            kwargs["content"] = msg.reply_to_message.voice.file_id
            kwargs["content_type"] = "voice"

        elif msg.reply_to_message.video:
            kwargs["content"] = msg.reply_to_message.video.file_id
            kwargs["content_type"] = "video"

        else:
            msg.reply_markdown("This cat isn't a random reply generator, baka! Give some content to reply with......")
            return

    else:
        msg.reply_markdown("This cat isn't a random reply generator, baka! Give some content to reply with......")
        return

    # save note and reply to user
    msg.reply_markdown(add_note(**kwargs))
Exemple #11
0
    def wrapper(update: Update, context: CallbackContext, *args, **kwargs):
        if update.effective_chat.type != "private" and update.effective_chat.id not in get_command_exception_chats(
                "admin"):
            # check bot
            if not update.effective_chat.get_member(
                    context.bot.id).can_restrict_members:
                update.effective_message.reply_markdown(
                    "Ask your sugar daddy to give me perms required to use the method `CanRestrictMembers`."
                )
                return

            # check user
            user = update.effective_chat.get_member(update.effective_user.id)
            if not user.can_restrict_members and user.status != "creator":
                update.effective_message.reply_markdown(
                    "Ask your sugar daddy to give you perms required to use the method `CanRestrictMembers`."
                )
                return

        func(update, context, *args, **kwargs)
Exemple #12
0
def demote(update: Update, context: CallbackContext):
    """
    Demote a user to remove admin rights
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check if user has enough perms
    if update.effective_chat.id not in get_command_exception_chats("admin"):
        user = update.effective_chat.get_member(update.effective_user.id)
        if not user.can_promote_members and user.status != "creator":
            update.effective_message.reply_markdown(
                "Ask your sugar daddy to give you perms required to use the method `CanPromoteMembers`."
            )
            return

    # get bot member object to check it's perms
    bot: ChatMember = update.effective_chat.get_member(context.bot.id)

    # check if bot can demote users
    if not bot.can_promote_members:
        update.effective_message.reply_markdown(
            "Ask your sugar daddy to give me perms required to use the method `CanPromoteMembers`."
        )
        return

    # get member to demote
    try:
        user_id, username = get_user_from_message(update.effective_message)
    except UserError:
        update.effective_message.reply_text(
            "Reply to a message by the user or give username of user you want to demote..."
        )
        return
    except UserRecordError as e:
        update.effective_message.reply_text(e.message)
        return

    # demote member
    if update.effective_chat.get_member(user_id).status != "administrator":
        update.effective_message.reply_text(
            "What are you gonna demote a pleb to?")
        return

    try:
        context.bot.promote_chat_member(
            chat_id=update.effective_chat.id,
            user_id=user_id,
            can_change_info=False,
            can_post_messages=False,
            can_edit_messages=False,
            can_delete_messages=False,
            can_invite_users=False,
            can_restrict_members=False,
            can_pin_messages=False,
            can_promote_members=False,
        )

        update.effective_message.reply_markdown(
            emojize(
                f"{mention_markdown(user_id, username)} has been thrown down from the council of admins to rot with the"
                f" rest of you plebs :grinning_cat_face_with_smiling_eyes:"))

    except BadRequest:
        update.effective_message.reply_text(
            "This cat can't meow at it's superiors.... and neither can I change their perms or title."
        )
Exemple #13
0
def promote(update: Update, context: CallbackContext):
    """
    Promote a user to give him admin rights
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check if user has enough perms
    if update.effective_chat.id not in get_command_exception_chats("admin"):
        user = update.effective_chat.get_member(update.effective_user.id)
        if not user.can_promote_members and user.status != "creator":
            update.effective_message.reply_markdown(
                "Ask your sugar daddy to give you perms required to use the method `CanPromoteMembers`."
            )
            return

    # get bot member object to check it's perms
    bot: ChatMember = update.effective_chat.get_member(context.bot.id)

    # check if bot can promote users
    if not bot.can_promote_members:
        update.effective_message.reply_markdown(
            "Ask your sugar daddy to give me perms required to use the method `CanPromoteMembers`."
        )
        return

    # get member to promote
    try:
        user_id, username = get_user_from_message(update.effective_message)
    except UserError:
        update.effective_message.reply_text(
            "Reply to a message by the user or give username of user you want to promote..."
        )
        return
    except UserRecordError as e:
        update.effective_message.reply_text(e.message)
        return

    # promote member
    reply = ""
    try:
        context.bot.promote_chat_member(
            chat_id=update.effective_chat.id,
            user_id=user_id,
            can_change_info=bot.can_change_info,
            can_post_messages=bot.can_post_messages,
            can_edit_messages=bot.can_edit_messages,
            can_delete_messages=bot.can_delete_messages,
            can_invite_users=bot.can_invite_users,
            can_restrict_members=bot.can_restrict_members,
            can_pin_messages=bot.can_pin_messages,
            can_promote_members=bot.can_promote_members,
        )
        reply += f"Everyone say NyaHello to {mention_markdown(user_id, username)}, our new admin!"

        # get all args other than the username
        useful_args = []
        for arg in context.args:
            if username not in arg:
                useful_args.append(arg)

        if useful_args:
            title = " ".join(useful_args)
            context.bot.set_chat_administrator_custom_title(
                update.effective_chat.id, user_id, title)
            reply += f"\nThey have been granted the title of `{title}`."

        update.effective_message.reply_markdown(reply.strip())

    except BadRequest:
        update.effective_message.reply_text(
            "This cat can't meow at it's superiors.... and neither can I change their perms or title."
        )
Exemple #14
0
def kang(update: Update, context: CallbackContext) -> None:
    """
    Add a sticker to user's pack
    :param update: object representing the incoming update.
    :param context: object containing data about the bot_action call.
    """
    # check for exception, but skip exception if user is a superuser
    if update.effective_user.id not in config.SUPERUSERS and update.effective_chat.id in get_command_exception_chats(
            "kang"):
        return

    msg = update.effective_message
    user = update.effective_user
    bot = context.bot

    # get sticker pack of user
    try:
        is_animated = msg.reply_to_message.sticker.is_animated
    except AttributeError:
        is_animated = False
    packs = _get_packs(user, bot, is_animated)
    if packs:
        pack_num, pack = packs[-1]
        pack_name = pack.name
        pack_title = pack.title
    else:
        # default pack number and name of the first pack
        pack_num = 0
        pack_name = "a" + str(user.id)
        if is_animated:
            pack_name += "_animated"
        pack_name += "_by_" + bot.username
        pack_title = f"{user.id}'s "
        if is_animated:
            pack_title += "animated "
        pack_title += "kang pack"

    # file name to download sticker file as
    rendum_str = uuid4()
    kang_sticker = f"{user.id}_{rendum_str}_kang_sticker." + "tgs" if is_animated else "png"

    # If user has replied to some message
    if is_animated:
        # future usage
        add_user(
            user_id=update.effective_message.reply_to_message.from_user.id,
            username=update.effective_message.reply_to_message.from_user.
            username,
        )

        # download sticker
        sticker = msg.reply_to_message.sticker
        context.bot.get_file(sticker.file_id).download(kang_sticker)

        # add to pack
        try:
            bot.add_sticker_to_set(user_id=user.id,
                                   name=pack_name,
                                   tgs_sticker=open(kang_sticker, 'rb'),
                                   emojis=sticker.emoji)
            msg.reply_markdown(
                f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
                + f"\nEmoji is: {sticker.emoji}")

        except TelegramError as e:
            if e.message == "Stickerset_invalid":
                _make_pack(msg, user, open(kang_sticker, 'rb'), sticker.emoji,
                           bot, pack_name, pack_num, is_animated)

            elif e.message == "Invalid sticker emojis":
                msg.reply_text("Invalid emoji(s).")

            elif e.message == "Stickers_too_much":
                msg.reply_text(
                    "Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc."
                )

            elif e.message == "Internal Server Error: sticker set not found (500)":
                msg.reply_markdown(
                    f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
                    + f"\nEmoji is : {sticker.emoji}")

    elif msg.reply_to_message:
        # future usage
        add_user(
            user_id=update.effective_message.reply_to_message.from_user.id,
            username=update.effective_message.reply_to_message.from_user.
            username,
        )

        # get sticker file
        if msg.reply_to_message.sticker:
            file_id = msg.reply_to_message.sticker.file_id
        elif msg.reply_to_message.photo:
            file_id = msg.reply_to_message.photo[-1].file_id
        elif msg.reply_to_message.document:
            file_id = msg.reply_to_message.document.file_id
        else:
            msg.reply_text(
                "Nyet, can't kang that. Even if you bribe me with catnip.")
            return

        # download sticker file
        bot.get_file(file_id).download(kang_sticker)

        # get emoji(s) for sticker
        if context.args:
            sticker_emoji = str(context.args[0])
        elif msg.reply_to_message.sticker and msg.reply_to_message.sticker.emoji:
            sticker_emoji = msg.reply_to_message.sticker.emoji
        else:
            sticker_emoji = "🤔"

        # resize image
        im = _resize(kang_sticker)

        if not msg.reply_to_message.sticker:
            im.save(kang_sticker, "PNG")

        # add to sticker pack
        try:
            bot.add_sticker_to_set(user_id=user.id,
                                   name=pack_name,
                                   png_sticker=open(kang_sticker, 'rb'),
                                   emojis=sticker_emoji)
            msg.reply_markdown(
                f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
                + f"\nEmoji is: {sticker_emoji}")

        except OSError:
            msg.reply_text(
                "I can only kang images.\nAnd catnip. If I'm feeling like it.")
            return

        except TelegramError as e:
            if e.message == "Stickerset_invalid":
                _make_pack(msg, user, open(kang_sticker, 'rb'), sticker_emoji,
                           bot, pack_name, pack_num)

            elif e.message == "Sticker_png_dimensions":
                im.save(kang_sticker, "PNG")
                bot.add_sticker_to_set(user_id=user.id,
                                       name=pack_name,
                                       png_sticker=open(kang_sticker, 'rb'),
                                       emojis=sticker_emoji)
                msg.reply_markdown(
                    f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
                    + f"\nEmoji is: {sticker_emoji}")

            elif e.message == "Invalid sticker emojis":
                msg.reply_text("Invalid emoji(s).")

            elif e.message == "Stickers_too_much":
                msg.reply_text(
                    "Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc."
                )

            elif e.message == "Internal Server Error: sticker set not found (500)":
                msg.reply_markdown(
                    f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
                    + f"\nEmoji is : {sticker_emoji}")

    elif context.args:
        # get the emoji to use as sticker and the emojis to set to said sticker
        png_sticker = context.args[0]
        try:
            sticker_emoji = context.args[1]
        except IndexError:
            sticker_emoji = "🤔"

        # fetch the image for the emoji
        urlretrieve(png_sticker, kang_sticker)
        im = _resize(kang_sticker)
        im.save(kang_sticker, "PNG")

        # add to pack
        try:
            msg.reply_photo(photo=open(kang_sticker, 'rb'))
            bot.add_sticker_to_set(user_id=user.id,
                                   name=pack_name,
                                   png_sticker=open(kang_sticker, 'rb'),
                                   emojis=sticker_emoji)
            msg.reply_markdown(
                f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
                + f"\nEmoji is: {sticker_emoji}")

        except OSError:
            msg.reply_text(
                "I can only kang images.\nAnd catnip. If I'm feeling like it.")
            return

        except TelegramError as e:
            if e.message == "Stickerset_invalid":
                _make_pack(msg, user, open(kang_sticker, 'rb'), sticker_emoji,
                           bot, pack_name, pack_num)

            elif e.message == "Sticker_png_dimensions":
                im.save(kang_sticker, "PNG")
                bot.add_sticker_to_set(user_id=user.id,
                                       name=pack_name,
                                       png_sticker=open(kang_sticker, 'rb'),
                                       emojis=sticker_emoji)
                msg.reply_markdown(
                    f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
                    + f"\nEmoji is : {sticker_emoji}")

            elif e.message == "Invalid sticker emojis":
                msg.reply_text("Invalid emoji(s).")

            elif e.message == "Stickers_too_much":
                msg.reply_text(
                    "Meowtastic news! This loser just maxed out his pack size. Press F to pay respecc."
                )

            elif e.message == "Internal Server Error: sticker set not found (500)":
                msg.reply_markdown(
                    f"Sticker successfully added to [{pack_title}](t.me/addstickers/{pack_name})"
                    + f"\nEmoji is : {sticker_emoji}")

    else:
        msg.reply_markdown("Please reply to a sticker, or image to kang it!")

    # delete stray files
    if os.path.isfile(kang_sticker):
        os.remove(kang_sticker)
Exemple #15
0
def sauce(update: Update, context: CallbackContext) -> None:
    """
    Fetch the doujin for all the sauces given by user, make telegraph article and send it to user for easy reading
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check if any args were given
    if not context.args:
        update.effective_message.reply_text(
            "Please give some codes to fetch, this cat can't read your mind..."
        )
        return

    # check if exception for sauce is added in current chat
    exception = update.effective_chat.id in get_command_exception_chats(
        "sauce")

    # iterate over each given sauce and fetch the doujin
    for digits in context.args:
        try:
            code = int(digits)
        except ValueError:
            update.effective_message.reply_markdown(
                f"If you don't know that sauce codes must be only digits, you shouldn't be using this command. "
                f"`{digits}` is not a sauce, just a sign of your ignorance.")
            continue

        # check if doujin exists
        if not Hentai.exists(code):
            update.effective_message.reply_markdown(
                f"Doujin for `{code}` doesn't exist, Donald... Please don't use your nuclear launch codes here 😿"
            )
            continue

        # Fetch doujin data
        doujin = Hentai(code)

        # make dict with data to be displayed for the doujin
        data = {
            "Title":
            f'<a href="{doujin.url}">{doujin.title(Format.Pretty)}</a>',
            "Tags": _generate_anchor_tags(doujin.tag),
            "Characters": _generate_anchor_tags(doujin.character),
            "Parodies": _generate_anchor_tags(doujin.parody),
            "Artists": _generate_anchor_tags(doujin.artist),
            "Groups": _generate_anchor_tags(doujin.group),
            "Languages": _generate_anchor_tags(doujin.language),
            "Categories": _generate_anchor_tags(doujin.category),
        }

        # add details to the reply to be sent to the user
        text_blob = "\n\n".join(f"{key}\n{value}"
                                for key, value in data.items())

        # button with nhentai link
        markup = InlineKeyboardMarkup.from_button(
            InlineKeyboardButton(text="Link to nHentai", url=doujin.url))

        # send message
        if exception:
            update.message.reply_photo(
                photo=doujin.image_urls[0],
                caption=text_blob,
                parse_mode=ParseMode.HTML,
                reply_markup=markup,
            )
        else:
            context.bot.send_photo(
                chat_id=update.effective_user.id,
                photo=doujin.image_urls[0],
                caption=text_blob,
                parse_mode=ParseMode.HTML,
                reply_markup=markup,
            )

    # if called from a chat without exception in it, then send him a reminder to check it
    if not exception and update.effective_chat.type != "private":
        update.message.reply_text(
            "Let's enjoy this together, without anybody else distracting us...",
            reply_markup=InlineKeyboardMarkup.from_button(
                InlineKeyboardButton(
                    text="Go to Private Chat",
                    url=context.bot.link,
                )),
        )
Exemple #16
0
def add_filter_handler(update: Update, context: CallbackContext):
    """
    Add a filter in a chat
    :param update: object representing the incoming update.
    :param context: object containing data about the command call.
    """
    # check for exception
    if update.effective_chat.id in get_command_exception_chats("filter"):
        return

    # for ease of reference
    msg = update.effective_message

    # get trigger and content from the message
    try:
        trigger, content = msg.text_markdown.split(None, 2)[1:]
    except ValueError:
        try:
            trigger = msg.text.split()[1]
            content = None
        except IndexError:
            msg.reply_markdown(
                "No trigger, No content....\n\nYou could've at least come with some catnip\n`._.`"
            )
            return

    trigger = trigger.replace(r"\_", "_").replace(r"\*", "*")

    # set kwargs to be passed to add_filter function
    kwargs = {'chat': update.effective_chat.id, 'trigger': trigger}

    # add content and filter type to kwargs

    if content is not None:
        kwargs['content'] = content
        kwargs['filter_type'] = "text"

    elif msg.reply_to_message:
        # for future usage
        add_user(
            user_id=update.effective_message.reply_to_message.from_user.id,
            username=update.effective_message.reply_to_message.from_user.
            username,
        )

        if msg.reply_to_message.text_markdown:
            kwargs['content'] = msg.reply_to_message.text_markdown
            kwargs['filter_type'] = "text"

        elif msg.reply_to_message.sticker:
            kwargs['content'] = msg.reply_to_message.sticker.file_id
            kwargs['filter_type'] = "sticker"

        elif msg.reply_to_message.document:
            kwargs['content'] = msg.reply_to_message.document.file_id
            kwargs['filter_type'] = "document"

        elif msg.reply_to_message.photo:
            kwargs['content'] = msg.reply_to_message.photo[-1].file_id
            kwargs['filter_type'] = "photo"

        elif msg.reply_to_message.audio:
            kwargs['content'] = msg.reply_to_message.audio.file_id
            kwargs['filter_type'] = "audio"

        elif msg.reply_to_message.voice:
            kwargs['content'] = msg.reply_to_message.voice.file_id
            kwargs['filter_type'] = "voice"

        elif msg.reply_to_message.video:
            kwargs['content'] = msg.reply_to_message.video.file_id
            kwargs['filter_type'] = "video"

        else:
            msg.reply_markdown(
                "This cat isn't a random reply generator, baka! Give some content to reply with......"
            )
            return

    else:
        msg.reply_markdown(
            "This cat isn't a random reply generator, baka! Give some content to reply with......"
        )
        return

    # add filter in DB
    msg.reply_markdown(add_filter(**kwargs))