Ejemplo n.º 1
0
def delete_join(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    join = update.effective_message.new_chat_members
    if can_delete(chat, bot.id):
        del_join = sql.get_del_pref(chat.id)
        if del_join and update.message:
            update.message.delete()
Ejemplo n.º 2
0
def del_lockables(bot: Bot, update: Update):

    chat = update.effective_chat
    message = update.effective_message

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(
                chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text(
                                "I see a bot, and I've been told to stop them joining... "
                                "but I'm not admin!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text(
                            "Only admins are allowed to add bots to this chat!."
                        )
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Ejemplo n.º 3
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(
                    "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] == "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 "<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(
                    "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 ""
Ejemplo n.º 4
0
def rest_handler(bot: Bot, update: Update):

    msg = update.effective_message
    chat = update.effective_chat
    for restriction, filter in RESTRICTION_TYPES.items():
        if filter(msg) and sql.is_restr_locked(
                chat.id, restriction) and can_delete(chat, bot.id):
            try:
                msg.delete()
            except BadRequest as excp:
                if excp.message == "Message to delete not found":
                    pass
                else:
                    LOGGER.exception("ERROR in restrictions")
            break