Esempio n. 1
0
def __import_data__(chat_id, data):
    # set chat locks
    locks = data.get('locks', {})
    for itemlock in locks:
        if itemlock in LOCK_TYPES:
            sql.update_lock(chat_id, itemlock, locked=True)
        elif itemlock in RESTRICTION_TYPES:
            sql.update_restriction(chat_id, itemlock, locked=True)
        else:
            pass
Esempio n. 2
0
def unlock(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    if is_user_admin(chat, message.from_user.id):
        if len(args) >= 1:
            if args[0] in LOCK_TYPES:
                sql.update_lock(chat.id, args[0], locked=False)
                message.reply_text(tld(chat.id,
                                       "locks_unlock_success").format(args[0]),
                                   parse_mode=ParseMode.MARKDOWN)
                return "<b>{}:</b>" \
                       "\n#UNLOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nUnlocked <code>{}</code>.".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name), args[0])

            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":
                #     unrestr_members(bot, chat.id, members, media=False, other=False, previews=False)

                # elif args[0] == "media":
                #     unrestr_members(bot, chat.id, members, other=False, previews=False)

                # elif args[0] == "other":
                #     unrestr_members(bot, chat.id, members, previews=False)

                # elif args[0] == "previews":
                #     unrestr_members(bot, chat.id, members)

                # elif args[0] == "all":
                #     unrestr_members(bot, chat.id, members, True, True, True, True)

                message.reply_text(tld(chat.id,
                                       "locks_unlock_success").format(args[0]),
                                   parse_mode=ParseMode.MARKDOWN)

                return "<b>{}:</b>" \
                       "\n#UNLOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nUnlocked <code>{}</code>.".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name), args[0])
            else:
                message.reply_text(tld(chat.id, "locks_type_invalid"))

        else:
            bot.sendMessage(chat.id, tld(chat.id, "locks_unlock_no_type"))

    return ""
Esempio n. 3
0
def unlock(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    if is_user_admin(chat, message.from_user.id):
        if len(args) >= 1:
            if args[0] in LOCK_TYPES:
                sql.update_lock(chat.id, args[0], locked=False)
                message.reply_text(tld(chat.id, "Unlocked {} for everyone!").format(args[0]))
                return "<b>{}:</b>" \
                       "\n#UNLOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nUnlocked <code>{}</code>.".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name), args[0])

            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":
                    unrestr_members(bot, chat.id, members, media=False, other=False, previews=False)

                elif args[0] == "media":
                    unrestr_members(bot, chat.id, members, other=False, previews=False)

                elif args[0] == "other":
                    unrestr_members(bot, chat.id, members, previews=False)

                elif args[0] == "previews":
                    unrestr_members(bot, chat.id, members)

                elif args[0] == "all":
                    unrestr_members(bot, chat.id, members, True, True, True, True)
                """
                message.reply_text(tld(chat.id, "Unlocked {} for everyone!").format(args[0]))

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

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

    return ""
Esempio n. 4
0
def lock(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    if can_delete(chat, bot.id):
        if len(args) >= 1:
            if args[0] in LOCK_TYPES:
                sql.update_lock(chat.id, args[0], locked=True)
                message.reply_text(tld(chat.id, "Locked {} messages for all non-admins!").format(args[0]))

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

            elif args[0] in RESTRICTION_TYPES:
                sql.update_restriction(chat.id, args[0], locked=True)
                if args[0] == "previews":
                    members = users_sql.get_chat_members(str(chat.id))
                    restr_members(bot, chat.id, members, messages=True, media=True, other=True)

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

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

    else:
        message.reply_text(
            tld(chat.id, "Make sure I'm a group administrator and have permission to delete messages, then try again."))

    return ""
Esempio n. 5
0
def lock(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    if can_delete(chat, bot.id):
        if len(args) >= 1:
            if args[0] in LOCK_TYPES:
                sql.update_lock(chat.id, args[0], locked=True)
                message.reply_text(tld(chat.id,
                                       "locks_lock_success").format(args[0]),
                                   parse_mode=ParseMode.MARKDOWN)

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

            elif args[0] in RESTRICTION_TYPES:
                sql.update_restriction(chat.id, args[0], locked=True)
                message.reply_text(tld(chat.id,
                                       "locks_lock_success").format(args[0]),
                                   parse_mode=ParseMode.MARKDOWN)
                return "<b>{}:</b>" \
                       "\n#LOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nLocked <code>{}</code>.".format(html.escape(chat.title),
                                                          mention_html(user.id, user.first_name), args[0])

            else:
                message.reply_text(tld(chat.id, "locks_type_invalid"))
        else:
            message.reply_text(tld(chat.id, "locks_lock_no_type"))

    else:
        message.reply_text(tld(chat.id, "locks_bot_not_admin"))

    return ""
Esempio n. 6
0
def unlock(update, context) -> str:
    args = context.args
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    if is_user_admin(chat, message.from_user.id):
        if len(args) >= 1:
            ltype = args[0].lower()
            if ltype in LOCK_TYPES:
                # Connection check
                conn = connected(context.bot,
                                 update,
                                 chat,
                                 user.id,
                                 need_admin=True)
                if conn:
                    chat = dispatcher.bot.getChat(conn)
                    chat_id = conn
                    chat_name = chat.title
                    text = tl(
                        update.effective_message,
                        "Tidak terkunci *{}* untuk semua orang pada *{}*!"
                    ).format(ltype, chat_name)
                else:
                    if update.effective_message.chat.type == "private":
                        send_message(
                            update.effective_message,
                            tl(
                                update.effective_message,
                                "Anda bisa lakukan command ini pada grup, bukan pada PM"
                            ))
                        return ""
                    chat = update.effective_chat
                    chat_id = update.effective_chat.id
                    chat_name = update.effective_message.chat.title
                    text = tl(
                        update.effective_message,
                        "Tidak terkunci *{}* untuk semua orang!").format(ltype)
                sql.update_lock(chat.id, ltype, locked=False)
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
                return "<b>{}:</b>" \
                       "\n#UNLOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nUnlocked <code>{}</code>.".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name), ltype)

            elif ltype in UNLOCK_CHAT_RESTRICTION:
                # Connection check
                conn = connected(context.bot,
                                 update,
                                 chat,
                                 user.id,
                                 need_admin=True)
                if conn:
                    chat = dispatcher.bot.getChat(conn)
                    chat_id = conn
                    chat_name = chat.title
                    text = tl(
                        update.effective_message,
                        "Izin tidak terkunci *{}* untuk semua orang pada *{}*!"
                    ).format(ltype, chat_name)
                else:
                    if update.effective_message.chat.type == "private":
                        send_message(
                            update.effective_message,
                            tl(
                                update.effective_message,
                                "Anda bisa lakukan command ini pada grup, bukan pada PM"
                            ))
                        return ""
                    chat = update.effective_chat
                    chat_id = update.effective_chat.id
                    chat_name = update.effective_message.chat.title
                    text = tl(
                        update.effective_message,
                        "Izin tidak terkunci *{}* untuk semua orang!").format(
                            ltype)

                current_permission = context.bot.getChat(chat_id).permissions
                context.bot.set_chat_permissions(
                    chat_id=chat_id,
                    permissions=get_permission_list(
                        eval(str(current_permission)),
                        UNLOCK_CHAT_RESTRICTION[ltype.lower()]))

                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")

                return "<b>{}:</b>" \
                       "\n#UNLOCK" \
                       "\n<b>Admin:</b> {}" \
                       "\nUnlocked <code>{}</code>.".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name), ltype)
            else:
                send_message(
                    update.effective_message,
                    tl(
                        update.effective_message,
                        "Apa yang Anda coba untuk membuka kunci...? Coba /locktypes untuk daftar kunci yang dapat dikunci"
                    ))

        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Apa yang Anda coba untuk buka kunci...?"))

    return ""