Пример #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(tld(chat.id, "admin_no_pin_perm"))
        return ""

    is_silent = True
    if args:
        is_silent = not args[0].lower() 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 f"<b>{html.escape(chat.title)}:</b>" \
            "\n#PINNED" \
               f"\n<b>• Admin:</b> {mention_html(user.id, user.first_name)}"

    return ""
Пример #2
0
def unpin(bot: Bot, update: Update) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message

    if user_can_pin(chat, user, bot.id) is False:
        message.reply_text(tld(chat.id, "admin_no_pin_perm"))
        return ""

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

    return f"<b>{html.escape(chat.title)}:</b>" \
           "\n#UNPINNED" \
           f"\n<b>• Admin:</b> {mention_html(user.id, user.first_name)}"