Пример #1
0
def unpin(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 a message!")
        return ""

    try:
        context.bot.unpinChatMessage(chat.id)
    except BadRequest as excp:
        if excp.message == "Chat_not_modified":
            pass
        elif excp.message == "Message to unpin not found":
            message.reply_text(
                "I can't see pined message, Maybe already unpined, or pin Message to old 🙂"
            )
        else:
            raise

    return ("<b>{}:</b>"
            "\n#UNPINNED"
            "\n<b>Admin:</b> {}".format(html.escape(chat.title),
                                        mention_html(user.id,
                                                     user.first_name)))
Пример #2
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 ""