Exemple #1
0
def pin(bot: Bot, update: Update, args: List[str]) -> str:
    user = update.effective_user
    chat = update.effective_chat
    message = update.effective_message

    is_group = chat.type not in ["private", "channel"]

    prev_message = update.effective_message.reply_to_message

    if user_can_pin(chat, user, bot.id) is False:
        message.reply_text("You are missing rights to pin a message!")
        return ""

    is_silent = True
    if len(args) >= 1:
        is_silent = args[0].lower() not in ["notify", "loud", "violent"]

    if prev_message and is_group:
        try:
            bot.pinChatMessage(chat.id,
                               prev_message.message_id,
                               disable_notification=is_silent)
        except BadRequest as excp:
            if excp.message != "Chat_not_modified":
                raise
        return ("<b>{}:</b>"
                "\n#PINNED"
                "\n<b>Admin:</b> {}".format(
                    html.escape(chat.title),
                    mention_html(user.id, user.first_name)))

    return ""
Exemple #2
0
def unpin(bot: Bot, update: Update) -> str:
    chat = update.effective_chat
    user = update.effective_user
    if user_can_pin(chat, user, bot.id) is False:
        message = update.effective_message

        message.reply_text("You are missing rights to unpin a message!")
        return ""

    try:
        bot.unpinChatMessage(chat.id)
    except BadRequest as excp:
        if excp.message != "Chat_not_modified":
            raise

    return ("<b>{}:</b>"
            "\n#UNPINNED"
            "\n<b>Admin:</b> {}".format(html.escape(chat.title),
                                        mention_html(user.id,
                                                     user.first_name)))
Exemple #3
0
def unpinall(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message

    if user_can_pin(chat, user, context.bot.id) is False:
        message.reply_text("You are missing rights to unpin messages!")
        return ""

    try:
        context.bot.unpinAllChatMessages(chat.id)
    except BadRequest as excp:
        if excp.message == "Chat_not_modified":
            pass
        else:
            raise

    return ("<b>{}:</b>"
            "\n#UNPINNED ALL"
            "\n<b>Admin:</b> {}".format(html.escape(chat.title),
                                        mention_html(user.id,
                                                     user.first_name)))
Exemple #4
0
def pin(update, context):
    args = context.args
    user = update.effective_user
    chat = update.effective_chat
    message = update.effective_message

    is_group = chat.type != "private" and chat.type != "channel"

    prev_message = update.effective_message.reply_to_message

    if user_can_pin(chat, user, context.bot.id) is False:
        message.reply_text("You are missing rights to pin a message!")
        return ""

    is_silent = True
    if len(args) >= 1:
        is_silent = not (args[0].lower() == "notify" or args[0].lower()
                         == "loud" or args[0].lower() == "violent")

    if prev_message and is_group:
        try:
            context.bot.pinChatMessage(
                chat.id,
                prev_message.message_id,
                disable_notification=is_silent,
            )
        except BadRequest as excp:
            if excp.message == "Chat_not_modified":
                pass
            else:
                raise
        return ("<b>{}:</b>"
                "\n#PINNED"
                "\n<b>Admin:</b> {}".format(
                    html.escape(chat.title),
                    mention_html(user.id, user.first_name)))

    return ""