Пример #1
0
def warn_user(update, context):
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    warner = update.effective_user  # type: Optional[User]
    user = update.effective_user
    args = context.args

    user_id, reason = extract_user_and_text(message, args)
    if user_id == "error":
        send_message(update.effective_message, tl(update.effective_message, reason))
        return ""

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    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

    check = context.bot.getChatMember(chat_id, context.bot.id)
    if check.status == 'member' or check['can_restrict_members'] == False:
        if conn:
            text = tl(update.effective_message, "Saya tidak bisa membatasi orang di {}! Pastikan saya sudah menjadi admin.").format(chat_name)
        else:
            text = tl(update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya sudah menjadi admin.")
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""

    if user_id:
        if conn:
            warning = warn(chat.get_member(user_id).user, chat, reason, message, warner, conn=True)
            send_message(update.effective_message, tl(update.effective_message, "Saya sudah memperingatinya pada grup *{}*").format(chat_name), parse_mode="markdown")
            return warning
        else:
            if message.reply_to_message and message.reply_to_message.from_user.id == user_id:
                return warn(message.reply_to_message.from_user, chat, reason, message.reply_to_message, warner)
            else:
                return warn(chat.get_member(user_id).user, chat, reason, message, warner)
    else:
        send_message(update.effective_message, tl(update.effective_message, "Tidak ada pengguna yang ditunjuk!"))
    return ""
Пример #2
0
def gban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message  # type: Optional[Message]

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("Anda sepertinya tidak mengacu pada pengguna.")
        return

    if int(user_id) in SUDO_USERS:
        message.reply_text(
            "Saya memata-matai, dengan mata kecil saya... perang pengguna sudo! Mengapa kalian saling berpaling? 😱"
        )
        return

    if int(user_id) in SUPPORT_USERS:
        message.reply_text(
            "OOOH seseorang mencoba untuk memblokir secara global pengguna dukungan! 😄 *mengambil popcorn*"
        )
        return

    if user_id == bot.id:
        message.reply_text(
            "😑 Sangat lucu, mari kita blokir secara global diri saya sendiri? Usaha yang bagus 😒"
        )
        return

    try:
        user_chat = bot.get_chat(user_id)
    except BadRequest as excp:
        message.reply_text(excp.message)
        return

    if user_chat.type != 'private':
        message.reply_text("Itu bukan pengguna!")
        return

    if sql.is_user_gbanned(user_id):
        if not reason:
            message.reply_text(
                "Pengguna ini sudah dilarang secara global; Saya akan mengubah alasannya, tetapi Anda belum memberi saya satu..."
            )
            return

        old_reason = sql.update_gban_reason(
            user_id, user_chat.username or user_chat.first_name, reason)
        if old_reason:
            message.reply_text(
                "Pengguna ini sudah gbanned, karena alasan berikut:\n"
                "<code>{}</code>\n"
                "Saya telah melakukan dan memperbaruinya dengan alasan baru Anda!"
                .format(html.escape(old_reason)),
                parse_mode=ParseMode.HTML)
        else:
            message.reply_text(
                "Pengguna ini sudah gbanned, tetapi tidak ada alasan yang ditetapkan; Saya telah melakukan dan memperbaruinya!"
            )

        return

    message.reply_text("*Kristal banned telah mengarah* 😉")

    banner = update.effective_user  # type: Optional[User]
    send_to_list(bot,
                 SUDO_USERS + SUPPORT_USERS,
                 "{} melarang secara global pengguna {} "
                 "karena:\n{}".format(
                     mention_html(banner.id, banner.first_name),
                     mention_html(user_chat.id, user_chat.first_name), reason
                     or "Tidak ada alasan yang diberikan"),
                 html=True)

    sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason)

    chats = get_all_chats()
    for chat in chats:
        chat_id = chat.chat_id

        # Check if this group has disabled gbans
        if not sql.does_chat_gban(chat_id):
            continue

        try:
            bot.kick_chat_member(chat_id, user_id)
        except BadRequest as excp:
            if excp.message in GBAN_ERRORS:
                pass
            else:
                message.reply_text(
                    "Tidak dapat melarang secara global karena: {}".format(
                        excp.message))
                send_to_list(
                    bot, SUDO_USERS + SUPPORT_USERS,
                    "Tidak dapat melarang secara global karena: {}".format(
                        excp.message))
                sql.ungban_user(user_id)
                return
        except TelegramError:
            pass

    send_to_list(bot, SUDO_USERS + SUPPORT_USERS,
                 "Melarang secara global selesai!")
    message.reply_text("Orang ini telah dilarang secara global.")
Пример #3
0
def temp_mute(bot: Bot, update: Update, args: List[str]) -> str:
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda sepertinya tidak mengacu pada pengguna."))
        return ""

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            update.effective_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

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya tidak dapat menemukan pengguna ini"))
            return ""
        else:
            raise

    if is_user_admin(chat, user_id, member):
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya benar-benar berharap dapat membisukan admin..."))
        return ""

    if user_id == bot.id:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Saya tidak akan membisukan diri saya sendiri, apakah kamu gila?"
            ))
        return ""

    check = bot.getChatMember(chat.id, user.id)
    if check['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda tidak punya hak untuk membatasi seseorang."))
        return ""

    if not reason:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Anda belum menetapkan waktu untuk menonaktifkan pengguna ini!"
            ))
        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#TMUTE" \
          "\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:
            bot.restrict_chat_member(chat.id,
                                     user_id,
                                     until_date=mutetime,
                                     can_send_messages=False)
            if conn:
                text = tl(update.effective_message,
                          "Dibisukan untuk *{}* pada *{}*!").format(
                              time_val, chat_name)
            else:
                text = tl(update.effective_message,
                          "Dibisukan untuk *{}*!").format(time_val)
            send_message(update.effective_message, text, parse_mode="markdown")
            return log
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message, "Pengguna ini sudah dibungkam."))

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            send_message(update.effective_message,
                         tl(update.effective_message,
                            "Dibisukan untuk *{}*!").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)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Yah sial, aku tidak bisa membisukan pengguna itu."))

    return ""
Пример #4
0
def unban(bot: Bot, update: Update, args: List[str]) -> str:
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user  # type: Optional[User]
    chat = update.effective_chat  # type: Optional[Chat]

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    user_id, reason = extract_user_and_text(message, args)

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    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

    if not user_id:
        return ""

    check = bot.getChatMember(chat_id, bot.id)
    if check.status == 'member':
        if conn:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru."
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
            )
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""
    else:
        if check['can_restrict_members'] == False:
            if conn:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru."
                ).format(chat_name)
            else:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
                )
            send_message(update.effective_message, text, parse_mode="markdown")
            return ""

    try:
        if conn:
            member = bot.getChatMember(chat_id, user_id)
        else:
            member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya tidak dapat menemukan pengguna ini"))
            return ""
        else:
            raise

    if user_id == bot.id:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Bagaimana saya akan unban diri saya sendiri jika saya tidak ada di sini...? 🤔"
            ))
        return ""

    if is_user_in_chat(chat, user_id):
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Mengapa Anda mencoba unban seseorang yang sudah ada di obrolan? 😑"
            ))
        return ""

    check = bot.getChatMember(chat.id, user.id)
    if check['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda tidak punya hak untuk membatasi seseorang."))
        return ""

    if conn:
        bot.unbanChatMember(chat_id, user_id)
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Ya, pengguna ini dapat bergabung pada {}! 😁").format(
                   chat_name))
    else:
        chat.unban_member(user_id)
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Ya, pengguna ini dapat bergabung! 😁"))

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

    return log
Пример #5
0
def kick(bot: Bot, update: Update, args: List[str]) -> str:
    currentchat = update.effective_chat  # type: Optional[Chat]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda sepertinya tidak mengacu pada pengguna."))
        return ""

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    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

    check = bot.getChatMember(chat_id, bot.id)
    if check.status == 'member':
        if conn:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru."
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
            )
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""
    else:
        if check['can_restrict_members'] == False:
            if conn:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru."
                ).format(chat_name)
            else:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
                )
            send_message(update.effective_message, text, parse_mode="markdown")
            return ""

    if not user_id:
        return ""

    try:
        if conn:
            member = bot.getChatMember(chat_id, user_id)
        else:
            member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya tidak dapat menemukan pengguna ini 😣"))
            return ""
        else:
            raise

    if user_id == bot.id:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Saya tidak akan menendang diri saya sendiri, apakah kamu gila? 😠"
            ))
        return ""

    if is_user_ban_protected(chat, user_id):
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Saya tidak bisa menendang orang ini karena dia adalah admin 😒"
            ))
        return ""

    if user_id == bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Yahhh aku tidak akan melakukan itu 😝"))
        return ""

    check = bot.getChatMember(chat.id, user.id)
    if check['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda tidak punya hak untuk membatasi seseorang."))
        return ""

    if conn:
        res = bot.unbanChatMember(chat_id,
                                  user_id)  # unban on current user = kick
    else:
        res = chat.unban_member(user_id)  # unban on current user = kick
    if res:
        if conn:
            bot.send_sticker(currentchat.id,
                             BAN_STICKER)  # banhammer marie sticker
            text = tl(update.effective_message,
                      "Tertendang pada *{}*! 😝").format(chat_name)
            send_message(update.effective_message, text, parse_mode="markdown")
        else:
            if message.text.split(None, 1)[0][1:] == "skick":
                update.effective_message.delete()
            else:
                bot.send_sticker(chat.id,
                                 BAN_STICKER)  # banhammer marie sticker
                text = tl(update.effective_message, "Tertendang! 😝")
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
        log = "<b>{}:</b>" \
              "\n#KICKED" \
              "\n<b>Admin:</b> {}" \
              "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
                                                           mention_html(user.id, user.first_name),
                                                           mention_html(member.user.id, member.user.first_name),
                                                           member.user.id)
        log += "\n<b>Reason:</b> {}".format(reason)

        return log

    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Yah sial, aku tidak bisa menendang pengguna itu 😒"))

    return ""
Пример #6
0
def ban(bot: Bot, update: Update, args: List[str]) -> str:
    currentchat = update.effective_chat  # type: Optional[Chat]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    user_id, reason = extract_user_and_text(message, args)

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    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

    check = bot.getChatMember(chat_id, bot.id)
    if check.status == 'member' or check['can_restrict_members'] == False:
        if conn:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru."
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
            )
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""

    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda sepertinya tidak mengacu pada pengguna."))
        return ""

    try:
        if conn:
            member = bot.getChatMember(chat_id, user_id)
        else:
            member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            if conn:
                text = tl(
                    update.effective_message,
                    "Saya tidak dapat menemukan pengguna ini pada *{}* 😣"
                ).format(chat_name)
            else:
                text = tl(update.effective_message,
                          "Saya tidak dapat menemukan pengguna ini 😣")
            send_message(update.effective_message, text, parse_mode="markdown")
            return ""
        else:
            raise

    if user_id == bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak akan BAN diri saya sendiri, apakah kamu gila? 😠"))
        return ""

    if is_user_ban_protected(chat, user_id, member):
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak bisa banned orang ini karena dia adalah admin 😒"))
        return ""

    if member['can_restrict_members'] == False:
        if conn:
            text = tl(
                update.effective_message,
                "Anda tidak punya hak untuk membatasi seseorang pada *{}*."
            ).format(chat_name)
        else:
            text = tl(update.effective_message,
                      "Anda tidak punya hak untuk membatasi seseorang.")
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""

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

    try:
        if conn:
            bot.kickChatMember(chat_id, user_id)
            bot.send_sticker(currentchat.id,
                             BAN_STICKER)  # banhammer marie sticker
            send_message(update.effective_message,
                         tl(update.effective_message,
                            "Terbanned pada *{}*! 😝").format(chat_name),
                         parse_mode="markdown")
        else:
            chat.kick_member(user_id)
            if message.text.split(None, 1)[0][1:] == "sban":
                update.effective_message.delete()
            else:
                bot.send_sticker(chat.id,
                                 BAN_STICKER)  # banhammer marie sticker
                send_message(update.effective_message,
                             tl(update.effective_message, "Terbanned! 😝"))
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            send_message(update.effective_message,
                         tl(update.effective_message, "Terbanned! 😝"),
                         quote=False)
            return log
        elif excp.message == "Message can't be deleted":
            pass
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR membanned pengguna %s di obrolan %s (%s) disebabkan oleh %s",
                user_id, chat.title, chat.id, excp.message)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Yah sial, aku tidak bisa banned pengguna itu 😒"))

    return ""
Пример #7
0
def temp_ban(bot: Bot, update: Update, args: List[str]) -> str:
    currentchat = update.effective_chat  # type: Optional[Chat]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id, update.effective_message)
    if spam == True:
        return

    user_id, reason = extract_user_and_text(message, args)

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    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

    check = bot.getChatMember(chat_id, bot.id)
    if check.status == 'member':
        if conn:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru."
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
            )
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""
    else:
        if check['can_restrict_members'] == False:
            if conn:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru."
                ).format(chat_name)
            else:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
                )
            send_message(update.effective_message, text, parse_mode="markdown")
            return ""

    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda sepertinya tidak mengacu pada pengguna."))
        return ""

    try:
        if conn:
            member = bot.getChatMember(chat_id, user_id)
        else:
            member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Saya tidak dapat menemukan pengguna ini 😣"))
            return ""
        else:
            raise

    if user_id == bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak akan BAN diri saya sendiri, apakah kamu gila? 😠"))
        return ""

    if is_user_ban_protected(chat, user_id, member):
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak bisa banned orang ini karena dia adalah admin 😒"))
        return ""

    if member['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda tidak punya hak untuk membatasi seseorang."))
        return ""

    if not reason:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda belum menetapkan waktu untuk banned pengguna ini!"))
        return ""

    split_reason = reason.split(None, 1)

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

        bantime = extract_time(message, time_val)

        if not bantime:
            return ""

    log = "<b>{}:</b>" \
          "\n#TEMPBAN" \
          "\n<b>Admin:</b> {}" \
          "\n<b>User:</b> {} (<code>{}</code>)" \
          "\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),
                                     member.user.id,
                                     time_val)
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        if conn:
            bot.kickChatMember(chat_id, user_id, until_date=bantime)
            bot.send_sticker(currentchat.id,
                             BAN_STICKER)  # banhammer marie sticker
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Banned! Pengguna diblokir untuk *{}* pada *{}*.").format(
                       time_val, chat_name),
                parse_mode="markdown")
        else:
            chat.kick_member(user_id, until_date=bantime)
            bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Banned! Pengguna diblokir untuk {}.").format(time_val))
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Banned! Pengguna diblokir untuk {}.").format(time_val),
                quote=False)
            return log
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Yah sial, aku tidak bisa menendang pengguna itu 😒"))

    return ""
Пример #8
0
def warn_user(bot: Bot, update: Update, args: List[str]) -> str:
    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id)
    if spam == True:
        return update.effective_message.reply_text(
            "Saya kecewa dengan anda, saya tidak akan mendengar kata-kata anda sekarang!"
        )
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    warner = update.effective_user  # type: Optional[User]
    user = update.effective_user

    user_id, reason = extract_user_and_text(message, args)

    conn = connected(bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type == "private":
            update.effective_message.reply_text(
                "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

    check = bot.getChatMember(chat_id, bot.id)
    if check.status == 'member' or check['can_restrict_members'] == False:
        if conn:
            text = "Saya tidak bisa membatasi orang di {}! Pastikan saya sudah menjadi admin.".format(
                chat_name)
        else:
            text = "Saya tidak bisa membatasi orang di sini! Pastikan saya sudah menjadi admin."
        message.reply_text(text, parse_mode="markdown")
        return ""

    if user_id:
        if conn:
            warning = warn(chat.get_member(user_id).user,
                           chat,
                           reason,
                           message,
                           warner,
                           conn=True)
            update.effective_message.reply_text(
                "Saya sudah memperingatinya pada grup *{}*".format(chat_name),
                parse_mode="markdown")
            return warning
        else:
            if message.reply_to_message and message.reply_to_message.from_user.id == user_id:
                return warn(message.reply_to_message.from_user, chat, reason,
                            message.reply_to_message, warner)
            else:
                return warn(
                    chat.get_member(user_id).user, chat, reason, message,
                    warner)
    else:
        message.reply_text("Tidak ada pengguna yang ditunjuk!")
    return ""
Пример #9
0
def gban(update, context):
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id, reason = extract_user_and_text(message, args)
    if user_id == "error":
        send_message(update.effective_message,
                     tl(update.effective_message, reason))
        return ""

    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "You don't seem to be referring to a user."))
        return

    if int(user_id) in SUDO_USERS:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "I spy, with my little eye... a sudo user war! Why are you guys turning on each other? 😱"
            ))
        return

    if int(user_id) in SUPPORT_USERS:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "OOOH someone's trying to gban a support User! 😄 *grabs popcorn*"
            ))
        return

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "😑 So funny, lets gban myself why don't I? Nice try. 😒"))
        return

    try:
        user_chat = context.bot.get_chat(user_id)
    except BadRequest as excp:
        send_message(update.effective_message, excp.message)
        return

    if user_chat.type != 'private':
        send_message(update.effective_message,
                     tl(update.effective_message, "That's not a user!"))
        return

    if sql.is_user_gbanned(user_id):
        if not reason:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "This user is already gbanned; I'd change the reason, but you haven't given me one..."
                ))
            return

        old_reason = sql.update_gban_reason(
            user_id, user_chat.username or user_chat.first_name, reason)
        if old_reason:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "This user is already gbanned, for the following reason:\n"
                    "<code>{}</code>\n"
                    "\nI've gone and updated it with your new reason!").format(
                        html.escape(old_reason)),
                parse_mode=ParseMode.HTML)
        else:
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "This user is already gbanned, but had no reason set; I've gone and updated it!"
                ))

        return

    send_message(update.effective_message,
                 tl(update.effective_message, "*It's gban time!* 😉"))

    banner = update.effective_user  # type: Optional[User]
    context.bot.send_message(
        MESSAGE_DUMP,
        tl(update.effective_message, "{} is gbanning user {} "
           "because:\n{}").format(
               mention_html(banner.id, banner.first_name),
               mention_html(user_chat.id, user_chat.first_name), reason
               or tl(update.effective_message, "No reason given")),
        parse_mode=ParseMode.HTML)

    sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason)

    chats = get_all_chats()
    for chat in chats:
        chat_id = chat.chat_id

        # Check if this group has disabled gbans
        if not sql.does_chat_gban(chat_id):
            continue

        try:
            context.bot.kick_chat_member(chat_id, user_id)
        except BadRequest as excp:
            if excp.message in GBAN_ERRORS:
                pass
            else:
                send_message(
                    update.effective_message,
                    tl(update.effective_message,
                       "Could not gban due to: {}").format(excp.message))
                context.bot.send_message(
                    MESSAGE_DUMP,
                    tl(update.effective_message,
                       "Could not gban due to: {}").format(excp.message))
                sql.ungban_user(user_id)
                return
        except TelegramError:
            pass

    context.bot.send_message(MESSAGE_DUMP,
                             tl(update.effective_message, "gban complete!"))
    send_message(update.effective_message,
                 tl(update.effective_message, "Person has been gbanned."))
Пример #10
0
def kick(update, context):
    currentchat = update.effective_chat  # type: Optional[Chat]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id, reason = extract_user_and_text(message, args)
    if user_id == "error":
        send_message(update.effective_message,
                     tl(update.effective_message, reason))
        return ""

    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Anda sepertinya tidak mengacu pada pengguna."))
        return ""

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    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

    check = context.bot.getChatMember(chat_id, context.bot.id)
    if check.status == 'member':
        if conn:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru."
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
            )
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""
    else:
        if check['can_restrict_members'] == False:
            if conn:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru."
                ).format(chat_name)
            else:
                text = tl(
                    update.effective_message,
                    "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru."
                )
            send_message(update.effective_message, text, parse_mode="markdown")
            return ""

    if not user_id:
        return ""

    try:
        if conn:
            member = context.bot.getChatMember(chat_id, user_id)
        else:
            member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            send_message(
                update.effective_message,
                tl(update.effective_message, "I can not find this user 😣"))
            return ""
        else:
            raise

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "I'm not going to kick myself, are you crazy? 😠"))
        return ""

    if is_user_ban_protected(chat, user_id):
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "I can not kick this guy because he is admin"))
        return ""

    if user_id == context.bot.id:
        send_message(update.effective_message,
                     tl(update.effective_message, "Yahhh I will not do it 😝"))
        return ""

    check = context.bot.getChatMember(chat.id, user.id)
    if check['can_restrict_members'] == False:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "You have no right to restrict a person."))
        return ""

    if conn:
        res = context.bot.unbanChatMember(
            chat_id, user_id)  # unban on current user = kick
    else:
        res = chat.unban_member(user_id)  # unban on current user = kick
    if res:
        if conn:
            context.bot.send_sticker(currentchat.id,
                                     BAN_STICKER)  # banhammer marie sticker
            text = tl(update.effective_message,
                      "Kicked in *{}*! 😝").format(chat_name)
            send_message(update.effective_message, text, parse_mode="markdown")
        else:
            if message.text.split(None, 1)[0][1:] == "skick":
                update.effective_message.delete()
            else:
                context.bot.send_sticker(
                    chat.id, BAN_STICKER)  # banhammer marie sticker
                text = tl(update.effective_message, "Kicked! 😝")
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
        log = "<b>{}:</b>" \
              "\n#KICKED" \
              "\n<b>Admin:</b> {}" \
              "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
                                                           mention_html(user.id, user.first_name),
                                                           mention_html(member.user.id, member.user.first_name),
                                                           member.user.id)
        log += "\n<b>Reason:</b> {}".format(reason)

        return log

    else:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Yah sial, aku tidak bisa menendang pengguna itu 😒"))

    return ""
Пример #11
0
def ban(update, context):
    currentchat = update.effective_chat  # type: Optional[Chat]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id, reason = extract_user_and_text(message, args)
    if user_id == "error":
        send_message(update.effective_message,
                     tl(update.effective_message, reason))
        return ""

    conn = connected(context.bot, update, chat, user.id, need_admin=True)
    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    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

    check = context.bot.getChatMember(chat_id, context.bot.id)
    if check.status == 'member' or check['can_restrict_members'] == False:
        if conn:
            text = tl(
                update.effective_message,
                "I can not restrict people on {}! Make sure that I am the admin and can appoint a new admin."
            ).format(chat_name)
        else:
            text = tl(
                update.effective_message,
                "I can not restrict people here! Make sure that I am the admin and can appoint a new admin."
            )
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""

    if not user_id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "You don't seem to be referring to a user."))
        return ""

    try:
        if conn:
            member = context.bot.getChatMember(chat_id, user_id)
        else:
            member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            if conn:
                text = tl(
                    update.effective_message,
                    "I can not find this user in *{}* 😣").format(chat_name)
            else:
                text = tl(update.effective_message,
                          "I can not find this user 😣")
            send_message(update.effective_message, text, parse_mode="markdown")
            return ""
        else:
            raise

    if user_id == context.bot.id:
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak akan BAN diri saya sendiri, apakah kamu gila? 😠"))
        return ""

    if is_user_ban_protected(chat, user_id, member):
        send_message(
            update.effective_message,
            tl(update.effective_message,
               "Saya tidak bisa banned orang ini karena dia adalah admin 😒"))
        return ""

    if member['can_restrict_members'] == False:
        if conn:
            text = tl(
                update.effective_message,
                "Anda tidak punya hak untuk membatasi seseorang pada *{}*."
            ).format(chat_name)
        else:
            text = tl(update.effective_message,
                      "Anda tidak punya hak untuk membatasi seseorang.")
        send_message(update.effective_message, text, parse_mode="markdown")
        return ""

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

    try:
        if conn:
            context.bot.kickChatMember(chat_id, user_id)
            context.bot.send_sticker(currentchat.id,
                                     BAN_STICKER)  # banhammer marie sticker
            send_message(update.effective_message,
                         tl(update.effective_message,
                            "Banned on *{}*! 😝").format(chat_name),
                         parse_mode="markdown")
        else:
            chat.kick_member(user_id)
            if message.text.split(None, 1)[0][1:] == "sban":
                update.effective_message.delete()
            else:
                context.bot.send_sticker(
                    chat.id, BAN_STICKER)  # banhammer marie sticker
                send_message(update.effective_message,
                             tl(update.effective_message, "Banned! 😝"))
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            send_message(update.effective_message,
                         tl(update.effective_message, "Banned! 😝"),
                         quote=False)
            return log
        elif excp.message == "Message can't be deleted":
            pass
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Well damn, I can't ban that User. 😒"))

    return ""