Ejemplo n.º 1
0
def start(bot: Bot, update: Update, args: List[str]):
    print("Start")
    chat = update.effective_chat  # type: Optional[Chat]
    query = update.callback_query
    if update.effective_chat.type == "private":
        if len(args) >= 1:
            if args[0].lower() == "help":
                send_help(update.effective_chat.id, (
                    chat.id, "send-help"
                ).format(
                    dispatcher.bot.first_name, "" if not ALLOW_EXCL else tld(
                        chat.id,
                        "\nAll commands can either be used with `/` or `!`.\n")
                ))

            elif args[0].lower().startswith("stngs_"):
                match = re.match("stngs_(.*)", args[0].lower())
                chat = dispatcher.bot.getChat(match.group(1))

                if is_user_admin(chat, update.effective_user.id):
                    send_settings(match.group(1),
                                  update.effective_user.id,
                                  user=False)
                else:
                    send_settings(match.group(1),
                                  update.effective_user.id,
                                  user=True)

            elif args[0][1:].isdigit() and "rules" in IMPORTED:
                IMPORTED["rules"].send_rules(update, args[0], from_pm=True)

        else:
            send_start(bot, update)
    else:
        update.effective_message.reply_text("Yo, whadup? 🙂")
Ejemplo n.º 2
0
def enforce_gban(update, context):
    # Not using @restrict handler to avoid spamming - just ignore if cant gban.
    if sql.does_chat_gban(update.effective_chat.id) and update.effective_chat.get_member(context.bot.id).can_restrict_members:
        user = update.effective_user
        chat = update.effective_chat
        msg = update.effective_message

        if user and not is_user_admin(chat, user.id):
            check_and_ban(update, user.id)

        if msg.new_chat_members:
            new_members = update.effective_message.new_chat_members
            for mem in new_members:
                check_and_ban(update, mem.id)

        if msg.reply_to_message:
            user = msg.reply_to_message.from_user
            if user and not is_user_admin(chat, user.id):
                check_and_ban(update, user.id, should_message=False)
Ejemplo n.º 3
0
def enforce_gmute(bot: Bot, update: Update):
    # Not using @restrict handler to avoid spamming - just ignore if cant gmute.
    if sql.does_chat_gmute(
            update.effective_chat.id) and update.effective_chat.get_member(
                bot.id).can_restrict_members:
        user = update.effective_user  # type: Optional[User]
        chat = update.effective_chat  # type: Optional[Chat]
        msg = update.effective_message  # type: Optional[Message]

        if user and not is_user_admin(chat, user.id):
            check_and_mute(bot, update, user.id, should_message=True)
        if msg.new_chat_members:
            new_members = update.effective_message.new_chat_members
            for mem in new_members:
                check_and_mute(bot, update, mem.id, should_message=True)
        if msg.reply_to_message:
            user = msg.reply_to_message.from_user  # type: Optional[User]
            if user and not is_user_admin(chat, user.id):
                check_and_mute(bot, update, user.id, should_message=True)
Ejemplo n.º 4
0
def kickme(bot: Bot, update: Update):
    user_id = update.effective_message.from_user.id
    if is_user_admin(update.effective_chat, user_id):
        update.effective_message.reply_text("I wish I could... but you're an admin.")
        return

    res = update.effective_chat.unban_member(user_id)  # unban on current user = kick
    if res:
        update.effective_message.reply_text("No problem.")
    else:
        update.effective_message.reply_text("Huh? I can't :/")
Ejemplo n.º 5
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("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":
                    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 "<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(
                    "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 ""
Ejemplo n.º 6
0
def kickme(update, context):
    user_id = update.effective_message.from_user.id
    if is_user_admin(update.effective_chat, user_id):
        update.effective_message.reply_text(
            "Yeahhh.. not gonna kick an admin.")
        return

    res = update.effective_chat.unban_member(
        user_id)  # unban on current user = kick
    if res:
        update.effective_message.reply_text("Yeah, you're right Get Out!..")
    else:
        update.effective_message.reply_text("Huh? I can't :/")
Ejemplo n.º 7
0
def start(update, context):
    args = context.args
    print("Start")
    chat = update.effective_chat  # type: Optional[Chat]
    query = update.callback_query
    if update.effective_chat.type == "private":
        if len(args) >= 1:
            if args[0].lower() == "help":
                send_help(update.effective_chat.id, HELP_STRINGS)
            elif args[0].lower() == "about":
                update.effective_message.reply_photo(
                    LUCIFER_IMG,
                    ABOUT_STRINGS,
                    reply_markup=InlineKeyboardMarkup(BUTTONS_ABOUT),
                    parse_mode=ParseMode.MARKDOWN,
                    timeout=60,
                    disable_web_page_preview=True)
            elif args[0].lower() == "knights":
                context.bot.send_message(update.effective_chat.id,
                                         KNIGHTS_STRINGS,
                                         parse_mode=ParseMode.MARKDOWN,
                                         disable_web_page_preview=True)
            elif args[0].lower() == "howto":
                context.bot.send_message(update.effective_chat.id,
                                         HOWTO_STRINGS,
                                         parse_mode=ParseMode.MARKDOWN,
                                         disable_web_page_preview=True)
            elif args[0].lower().startswith("stngs_"):
                match = re.match("stngs_(.*)", args[0].lower())
                chat = dispatcher.bot.getChat(match.group(1))

                if is_user_admin(chat, update.effective_user.id):
                    send_settings(match.group(1),
                                  update.effective_user.id,
                                  user=False)
                else:
                    send_settings(match.group(1),
                                  update.effective_user.id,
                                  user=True)

            elif args[0][1:].isdigit() and "rules" in IMPORTED:
                IMPORTED["rules"].send_rules(update, args[0], from_pm=True)

        else:
            update.effective_message.reply_video(
                HELP_PANEL_STRING.lucifer_GIF,
                reply_markup=InlineKeyboardMarkup(BUTTONS_START),
                parse_mode=ParseMode.MARKDOWN)
    else:
        update.effective_message.reply_text("Yo, whadup? 🙂")
Ejemplo n.º 8
0
def mute(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    if user_can_ban(chat, user, context.bot.id) == False:
        message.reply_text(
            "You don't have enough rights to restrict someone from talking!")
        return ""

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(
            "You'll need to either give me a username to mute, or reply to someone to be muted."
        )
        return ""

    if user_id == context.bot.id:
        message.reply_text("Yeahh... I'm not muting myself!")
        return ""

    member = chat.get_member(int(user_id))

    if member:
        if is_user_admin(chat, user_id, member=member):
            message.reply_text(
                "Well i'm not gonna stop an admin from talking!")

        elif member.can_send_messages is None or member.can_send_messages:
            context.bot.restrict_chat_member(
                chat.id,
                user_id,
                permissions=ChatPermissions(can_send_messages=False))
            message.reply_text("👍🏻 muted! 🤐")
            return "<b>{}:</b>" \
                   "\n#MUTE" \
                   "\n<b>Admin:</b> {}" \
                   "\n<b>User:</b> {}".format(html.escape(chat.title),
                                              mention_html(user.id, user.first_name),
                                              mention_html(member.user.id, member.user.first_name))

        else:
            message.reply_text("This user is already taped 🤐")
    else:
        message.reply_text("This user isn't in the chat!")

    return ""
Ejemplo n.º 9
0
        def check_update(self, update):
            chat = update.effective_chat
            user = update.effective_user

            if super().check_update(update):

                # Should be safe since check_update passed.
                command = update.effective_message.text_html.split(None, 1)[0][1:].split('@')[0]

                # disabled, admincmd, user admin
                if sql.is_command_disabled(chat.id, command):
                    if command in ADMIN_CMDS and is_user_admin(chat, user.id):
                        return True

                # not disabled
                else:
                    return True
Ejemplo n.º 10
0
def get_settings(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]
    args = msg.text.split(None, 1)

    # ONLY send settings in PM
    if chat.type != chat.PRIVATE:
        if is_user_admin(chat, user.id):
            text = "Click here to get this chat's settings, as well as yours."
            msg.reply_text(text,
                           reply_markup=InlineKeyboardMarkup(
                               [[InlineKeyboardButton(text="Settings",
                                                      url="t.me/{}?start=stngs_{}".format(
                                                          bot.username, chat.id))]]))
        else:
            text = "Click here to check your settings."

    else:
        send_settings(chat.id, user.id, True)
Ejemplo n.º 11
0
def banme(update, context):
    user_id = update.effective_message.from_user.id
    chat = update.effective_chat
    user = update.effective_user
    if is_user_admin(update.effective_chat, user_id):
        update.effective_message.reply_text("Yeahhh.. not gonna ban an admin.")
        return

    res = update.effective_chat.kick_member(user_id)
    if res:
        update.effective_message.reply_text("Yes, you're right! GTFO..")
        log = "<b>{}:</b>" \
              "\n#BANME" \
              "\n<b>User:</b> {}" \
              "\n<b>ID:</b> <code>{}</code>".format(html.escape(chat.title),
                                                    mention_html(user.id, user.first_name), user_id)
        return log

    else:
        update.effective_message.reply_text("Huh? I can't :/")
Ejemplo n.º 12
0
def banme(bot: Bot, update: Update):
    user_id = update.effective_message.from_user.id
    chat = update.effective_chat
    user = update.effective_user
    if is_user_admin(update.effective_chat, user_id):
        update.effective_message.reply_text("I wish I could... but you're an admin.")
        return

    res = update.effective_chat.kick_member(user_id)  
    if res:
        update.effective_message.reply_text("No problem, banned.")
        log = "<b>{}:</b>" \
              "\n#BANME" \
              "\n<b>User:</b> {}" \
              "\n<b>ID:</b> <code>{}</code>".format(html.escape(chat.title),
                                                    mention_html(user.id, user.first_name), user_id)
        return log
    
    else:
        update.effective_message.reply_text("Huh? I can't :/")
Ejemplo n.º 13
0
def check_user(user_id: int, bot: Bot, chat: Chat) -> Optional[str]:
    if not user_id:
        reply = "You don't seem to be referring to a user."
        return reply

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            reply = "I can't seem to find this user"
            return reply
        else:
            raise

    if user_id == bot.id:
        reply = "I'm not gonna MUTE myself, How high are you?"
        return reply

    if is_user_admin(chat, user_id, member):
        reply = "I really wish I could mute admins."
        return reply

    return None
Ejemplo n.º 14
0
        def check_update(self, update):
            if isinstance(update, Update) and update.effective_message:
                message = update.effective_message

                if message.text and len(message.text) > 1:
                    fst_word = message.text.split(None, 1)[0]
                    if len(fst_word) > 1 and any(
                            fst_word.startswith(start)
                            for start in CMD_STARTERS):
                        args = message.text.split()[1:]
                        command = fst_word[1:].split('@')
                        command.append(message.bot.username)

                        if not (command[0].lower() in self.command
                                and command[1].lower()
                                == message.bot.username.lower()):
                            return None

                        filter_result = self.filters(update)
                        if filter_result:
                            chat = update.effective_chat
                            user = update.effective_user
                            # disabled, admincmd, user admin
                            if sql.is_command_disabled(chat.id,
                                                       command[0].lower()):
                                # check if command was disabled
                                is_disabled = command[
                                    0] in ADMIN_CMDS and is_user_admin(
                                        chat, user.id)
                                if not is_disabled:
                                    return None
                                else:
                                    return args, filter_result

                            return args, filter_result
                        else:
                            return False
Ejemplo n.º 15
0
def warn(user: User,
         chat: Chat,
         reason: str,
         message: Message,
         warner: User = None) -> str:

    if is_user_admin(chat, user.id):
        # message.reply_text("Damn admins, They are too far to be One Punched!")
        return ""

    if warner:
        warner_tag = mention_html(warner.id, warner.first_name)
    else:
        warner_tag = "Automated warn filter."

    limit, soft_warn = sql.get_warn_setting(chat.id)
    num_warns, reasons = sql.warn_user(user.id, chat.id, reason)
    if num_warns >= limit:
        sql.reset_warns(user.id, chat.id)
        if soft_warn:  # kick
            chat.unban_member(user.id)
            reply = f"{limit} warnings, {mention_html(user.id, user.first_name)} with a normal warn! "

        else:  # ban
            chat.kick_member(user.id)
            reply = f"{limit} warnings, {mention_html(user.id, user.first_name)} with a Serious warn "

        for warn_reason in reasons:
            reply += f"\n - {html.escape(warn_reason)}"

        keyboard = []
        log_reason = (
            f"<b>{html.escape(chat.title)}:</b>\n"
            f"#WARN_BAN\n"
            f"<b>Admin:</b> {warner_tag}\n"
            f"<b>User:</b> {mention_html(user.id, user.first_name)}\n"
            f"<b>Reason:</b> {reason}\n"
            f"<b>Counts:</b> <code>{num_warns}/{limit}</code>")

    else:

        keyboard = InlineKeyboardMarkup([{
            InlineKeyboardButton("Remove warn",
                                 callback_data="rm_warn({})".format(user.id)),
            InlineKeyboardButton(text="Rules",
                                 url="t.me/{}?start={}".format(
                                     "lucifer_Probot", chat.id))
        }])

        reply = f"{mention_html(user.id, user.first_name)} has {num_warns}/{limit} warnings... watch out!"
        if reason:
            reply += f"\nReason for last warn:\n{html.escape(reason)}"

        log_reason = (
            f"<b>{html.escape(chat.title)}:</b>\n"
            f"#WARNn<b>Admin:</b> {warner_tag}\n"
            f"<b>User:</b> {mention_html(user.id, user.first_name)}\n"
            f"<b>Reason:</b> {reason}\n"
            f"<b>Counts:</b> <code>{num_warns}/{limit}</code>")

    try:
        message.reply_text(reply,
                           reply_markup=keyboard,
                           parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text(reply,
                               reply_markup=keyboard,
                               parse_mode=ParseMode.HTML,
                               quote=False)
        else:
            raise
    return log_reason
Ejemplo n.º 16
0
def check_flood(update, context) -> str:
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]

    if not user:  # ignore channels
        return ""

    # ignore admins
    if is_user_admin(chat, user.id):
        sql.update_flood(chat.id, None)
        return ""

    should_ban = sql.update_flood(chat.id, user.id)
    if not should_ban:
        return ""

    try:
        getmode, getvalue = sql.get_flood_setting(chat.id)
        if getmode == 1:
            chat.kick_member(user.id)
            execstrings = ("Banned")
            tag = "BANNED"
        elif getmode == 2:
            chat.kick_member(user.id)
            chat.unban_member(user.id)
            execstrings = ("Kicked")
            tag = "KICKED"
        elif getmode == 3:
            context.bot.restrict_chat_member(
                chat.id,
                user.id,
                permissions=ChatPermissions(can_send_messages=False))
            execstrings = ("Muted")
            tag = "MUTED"
        elif getmode == 4:
            bantime = extract_time(msg, getvalue)
            chat.kick_member(user.id, until_date=bantime)
            execstrings = ("Banned for {}".format(getvalue))
            tag = "TBAN"
        elif getmode == 5:
            mutetime = extract_time(msg, getvalue)
            context.bot.restrict_chat_member(
                chat.id,
                user.id,
                until_date=mutetime,
                permissions=ChatPermissions(can_send_messages=False))
            execstrings = ("Muted for {}".format(getvalue))
            tag = "TMUTE"
        send_message(
            update.effective_message,
            "Great, I like to leave flooding to natural disasters but you, "
            "you were just a disappointment. {}!".format(execstrings))

        return "<b>{}:</b>" \
               "\n#{}" \
               "\n<b>User:</b> {}" \
               "\nFlooded the group.".format(tag, html.escape(chat.title),
                                             mention_html(user.id, user.first_name))

    except BadRequest:
        msg.reply_text(
            "I can't restrict people here, give me permissions first! Until then, I'll disable anti-flood."
        )
        sql.set_flood(chat.id, 0)
        return "<b>{}:</b>" \
               "\n#INFO" \
               "\nDon't have enough permission to restrict users so automatically disabled anti-flood".format(chat.title)
Ejemplo n.º 17
0
def temp_mute(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    if user_can_ban(chat, user, context.bot.id) == False:
        message.reply_text(
            "You don't have enough rights to restrict someone from talking!")
        return ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return ""

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return ""
        else:
            raise

    if is_user_admin(chat, user_id, member):
        message.reply_text("I really wish I could mute admins...")
        return ""

    if user_id == context.bot.id:
        message.reply_text("I'm not gonna MUTE myself, are you crazy?")
        return ""

    if not reason:
        message.reply_text(
            "You haven't specified a time to mute this user for!")
        return ""

    split_reason = reason.split(None, 1)

    time_val = split_reason[0].lower()
    if len(split_reason) > 1:
        reason = split_reason[1]
    else:
        reason = ""

    mutetime = extract_time(message, time_val)

    if not mutetime:
        return ""

    log = "<b>{}:</b>" \
          "\n#TEMP MUTED" \
          "\n<b>Admin:</b> {}" \
          "\n<b>User:</b> {}" \
          "\n<b>Time:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name),
                                     mention_html(member.user.id, member.user.first_name), time_val)
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        if member.can_send_messages is None or member.can_send_messages:
            context.bot.restrict_chat_member(
                chat.id,
                user_id,
                until_date=mutetime,
                permissions=ChatPermissions(can_send_messages=False))
            message.reply_text("shut up! 🤐 Taped for {}!".format(time_val))
            return log
        else:
            message.reply_text("This user is already muted.")

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text("shut up! 🤐 Taped for {}!".format(time_val),
                               quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR muting user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            message.reply_text("Well damn, I can't mute that user.")

    return ""
Ejemplo n.º 18
0
def warn(user: User,
         chat: Chat,
         reason: str,
         message: Message,
         warner: User = None) -> str:
    if is_user_admin(chat, user.id):
        message.reply_text("Damn admins, can't even be warned!")
        return ""

    if warner:
        warner_tag = mention_html(warner.id, warner.first_name)
    else:
        warner_tag = "Automated warn filter."

    limit, soft_warn = sql.get_warn_setting(chat.id)
    num_warns, reasons = sql.warn_user(user.id, chat.id, reason)
    if num_warns >= limit:
        sql.reset_warns(user.id, chat.id)
        if soft_warn:  # kick
            chat.unban_member(user.id)
            reply = "That's {} warnings, {} has been kicked!".format(
                limit, mention_html(user.id, user.first_name))

        else:  # ban
            chat.kick_member(user.id)
            reply = "That's{} warnings, {} has been banned!".format(
                limit, mention_html(user.id, user.first_name))

        for warn_reason in reasons:
            reply += "\n - {}".format(html.escape(warn_reason))

        #message.bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
        keyboard = None
        log_reason = "<b>{}:</b>" \
                     "\n#WARN_BAN" \
                     "\n<b>Admin:</b> {}" \
                     "\n<b>User:</b> {} (<code>{}</code>)" \
                     "\n<b>Reason:</b> {}"\
                     "\n<b>Counts:</b> <code>{}/{}</code>".format(html.escape(chat.title),
                                                                  warner_tag,
                                                                  mention_html(user.id, user.first_name),
                                                                  user.id, reason, num_warns, limit)

    else:
        keyboard = InlineKeyboardMarkup([{
            InlineKeyboardButton("Remove warn",
                                 callback_data="rm_warn({})".format(user.id)),
            InlineKeyboardButton(text="Rules",
                                 url="t.me/{}?start={}".format(
                                     "lucifer_Probot", chat.id))
        }])

        reply = "User {} has {}/{} warnings... watch out!".format(
            mention_html(user.id, user.first_name), num_warns, limit)
        if reason:
            reply += "\nReason for last warn:\n{}".format(html.escape(reason))

        log_reason = "<b>{}:</b>" \
                     "\n#WARN" \
                     "\n<b>Admin:</b> {}" \
                     "\n<b>User:</b> {} (<code>{}</code>)" \
                     "\n<b>Reason:</b> {}"\
                     "\n<b>Counts:</b> <code>{}/{}</code>".format(html.escape(chat.title),
                                                                  warner_tag,
                                                                  mention_html(user.id, user.first_name),
                                                                  user.id, reason, num_warns, limit)

    try:
        message.reply_text(reply,
                           reply_markup=keyboard,
                           parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text(reply,
                               reply_markup=keyboard,
                               parse_mode=ParseMode.HTML,
                               quote=False)
        else:
            raise
    return log_reason
Ejemplo n.º 19
0
 def check_update(self, update):
     return super().check_update(update) and not (
         sql.is_restr_locked(update.effective_chat.id, 'messages') and
         not is_user_admin(update.effective_chat, update.effective_user.id))
Ejemplo n.º 20
0
def unlock(update, context) -> str:
	args = context.args
	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:
			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 = ("Unlocked {} messages for everyone in {}!".format(ltype, chat_name))
				else:
					if update.effective_message.chat.type == "private":
						send_message(update.effective_message, "This command is meant to use in group not in PM")
						return ""
					chat = update.effective_chat
					chat_id = update.effective_chat.id
					chat_name = update.effective_message.chat.title
					text = ("Unlocked {} messages for everyone!".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 = ("Unlocked {} for everyone in {}!".format(ltype, chat_name))
				else:
					if update.effective_message.chat.type == "private":
						send_message(update.effective_message, "This command is meant to use in group not in PM")
						return ""
					chat = update.effective_chat
					chat_id = update.effective_chat.id
					chat_name = update.effective_message.chat.title
					text = ("Unlocked {} for everyone!".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, "What are you trying to unlock...? Try /locktypes for the list of lockables.")

		else:
			send_message(update.effective_message, "What are you trying to unlock...?")

	return ""