Exemplo n.º 1
0
def lock(update: Update, context: CallbackContext) -> str:
    chat = update.effective_chat
    message = update.effective_message
    bot = context.bot

    if can_delete(chat, bot.id):
        args = context.args
        if len(args) >= 1:
            user = update.effective_user
            if args[0] in LOCK_TYPES:
                sql.update_lock(chat.id, args[0], locked=True)
                message.reply_text(
                    "Locked {} messages for all non-admins!".format(args[0]))

                return (
                    f"<b>{html.escape(chat.title)}:</b>\n"
                    f"#LOCK\n"
                    f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
                    f"Locked <code>{args[0]}</code>.")

            elif args[0] in RESTRICTION_TYPES:
                sql.update_restriction(chat.id, args[0], locked=True)
                """
                if args[0] == "messages":
                    chat.set_permissions(can_send_messages=False)

                elif args[0] == "media":
                    chat.set_permissions(can_send_media_messages=False)

                elif args[0] == "other":
                    chat.set_permissions(can_send_other_messages=False)

                elif args[0] == "previews":
                    chat.set_permissions(can_add_web_page_previews=False)

                elif args[0] == "all":
                    chat.set_permissions(can_send_messages=False)
                """
                message.reply_text("Locked {} for all non-admins!".format(
                    args[0]))
                return (
                    f"<b>{html.escape(chat.title)}:</b>\n"
                    f"#LOCK\n"
                    f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
                    f"Locked <code>{args[0]}</code>.")

            else:
                message.reply_text(
                    "What are you trying to lock...? Try /locktypes for the list of lockables"
                )

    else:
        message.reply_text(
            "I'm not an administrator, or haven't got delete rights.")

    return ""
Exemplo n.º 2
0
def unlock(update: Update, context: CallbackContext) -> str:
    bot = context.bot
    chat = update.effective_chat
    message = update.effective_message

    if is_user_admin(chat, message.from_user.id):
        args = context.args
        if len(args) >= 1:
            user = update.effective_user
            if args[0] in LOCK_TYPES:
                sql.update_lock(chat.id, args[0], locked=False)
                message.reply_text(f"Unlocked {args[0]} for everyone!")
                return (
                    f"<b>{html.escape(chat.title)}:</b>\n"
                    f"#UNLOCK\n"
                    f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
                    f"Unlocked <code>{args[0]}</code>.")

            elif args[0] in RESTRICTION_TYPES:
                sql.update_restriction(chat.id, args[0], locked=False)
                """
                #members = users_sql.get_chat_members(chat.id)
                if args[0] == "messages":
                    chat.set_permissions(can_send_messages=True)

                elif args[0] == "media":
                    chat.set_permissions(can_send_media_messages=True)

                elif args[0] == "other":
                    chat.set_permissions(can_send_other_messages=True)

                elif args[0] == "previews":
                    chat.set_permissions(can_add_web_page_previews=True)

                elif args[0] == "all":
                    chat.set_permissions(can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True, can_send_polls=True)
                """
                message.reply_text("Unlocked {} for everyone!".format(args[0]))

                return (
                    f"<b>{html.escape(chat.title)}:</b>\n"
                    f"#UNLOCK\n"
                    f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
                    f"Unlocked <code>{args[0]}</code>.")
            else:
                message.reply_text(
                    "What are you trying to unlock...? Try /locktypes for the list of lockables"
                )

        else:
            bot.sendMessage(chat.id, "What are you trying to unlock...?")

    return ""