Пример #1
0
def gbanstat(bot: Bot, update: Update, args: List[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!"
        )
    if len(args) > 0:
        if args[0].lower() in ["on", "yes"]:
            sql.enable_gbans(update.effective_chat.id)
            update.effective_message.reply_text(
                "Saya telah mengaktifkan larangan global dalam grup ini. Ini akan membantu melindungi Anda "
                "dari spammer, karakter tidak menyenangkan, dan troll terbesar."
            )
        elif args[0].lower() in ["off", "no"]:
            sql.disable_gbans(update.effective_chat.id)
            update.effective_message.reply_text(
                "Saya telah menonaktifkan larangan global dalam grup ini. Larangan global tidak akan memengaruhi pengguna Anda "
                "lagi. Anda akan kurang terlindungi dari troll dan spammer sekalipun"
            )
    else:
        update.effective_message.reply_text(
            "Berikan saya beberapa argumen untuk memilih pengaturan! on/off, yes/no!\n\n"
            "Pengaturan Anda saat ini: {}\n"
            "Ketika Benar, setiap larangan global yang terjadi juga akan terjadi di grup Anda. "
            "Ketika Salah, mereka tidak akan meninggalkan Anda pada belas kasihan yang mungkin dari "
            "spammer.".format(sql.does_chat_gban(update.effective_chat.id)))
Пример #2
0
def GBAN_EDITBTN(bot: Bot, update: Update):
    query = update.callback_query
    user = update.effective_user
    print("User {} clicked button GBAN EDIT".format(user.id))
    chat_id = query.data.split("=")[1]
    isgban = sql.does_chat_gban(chat_id)
    if chat_id:
        button = []
        if isgban:
            sql.disable_gbans(chat_id)
            status = "❎ Tidak Aktif"
        else:
            sql.enable_gbans(chat_id)
            status = "✅ Aktif"
        chat = bot.get_chat(chat_id)
        text = "*{}* memiliki pengaturan berikut untuk modul *Welcomes/Goodbyes*:\n\n".format(
            escape_markdown(chat.title))
        text += "Obrolan ini memberlakukan *larangan global*: `{}`.".format(
            status)
        button.append([
            InlineKeyboardButton(text=status,
                                 callback_data="set_gstats={}".format(chat_id))
        ])
        button.append([
            InlineKeyboardButton(
                text="Kembali", callback_data="stngs_back({})".format(chat_id))
        ])
        query.message.edit_text(text=text,
                                parse_mode=ParseMode.MARKDOWN,
                                reply_markup=InlineKeyboardMarkup(button))
        bot.answer_callback_query(query.id)
Пример #3
0
def gbanstat(update, context):
    args = context.args
    if len(args) > 0:
        if args[0].lower() in ["on", "yes"]:
            sql.enable_gbans(update.effective_chat.id)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "I've enabled gbans in this group. This will help protect you from "
                    "spammers, unsavoury characters, and the biggest trolls."))
        elif args[0].lower() in ["off", "no"]:
            sql.disable_gbans(update.effective_chat.id)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "I've disabled gbans in this group. GBans wont affect your users anymore. "
                    "You'll be less protected from any trolls and spammers though!"
                ))
    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Give me some arguments to choose a setting! on/off, yes/no!\n\n"
                "Your current setting is: {}\n"
                "When True, any gbans that happen will also happen in your group. "
                "When False, they won't, leaving you at the possible mercy of "
                "spammers.").format(
                    sql.does_chat_gban(update.effective_chat.id)))
Пример #4
0
def gbanstat(update, context):
    args = context.args
    if len(args) > 0:
        if args[0].lower() in ["on", "yes"]:
            sql.enable_gbans(update.effective_chat.id)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Saya telah mengaktifkan larangan global dalam grup ini. Ini akan membantu melindungi Anda "
                    "dari spammer, karakter tidak menyenangkan, dan troll terbesar."
                ))
        elif args[0].lower() in ["off", "no"]:
            sql.disable_gbans(update.effective_chat.id)
            send_message(
                update.effective_message,
                tl(
                    update.effective_message,
                    "Saya telah menonaktifkan larangan global dalam grup ini. Larangan global tidak akan memengaruhi pengguna Anda "
                    "lagi. Anda akan kurang terlindungi dari troll dan spammer sekalipun"
                ))
    else:
        send_message(
            update.effective_message,
            tl(
                update.effective_message,
                "Berikan saya beberapa argumen untuk memilih pengaturan! on/off, yes/no!\n\n"
                "Pengaturan Anda saat ini: {}\n"
                "Ketika Benar, setiap larangan global yang terjadi juga akan terjadi di grup Anda. "
                "Ketika Salah, mereka tidak akan meninggalkan Anda pada belas kasihan yang mungkin dari "
                "spammer.").format(sql.does_chat_gban(
                    update.effective_chat.id)))
Пример #5
0
def ungban(update, context):
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id = extract_user(message, args)
    if not user_id:
        send_message(update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna."))
        return
    if user_id == "error":
        send_message(update.effective_message, tl(update.effective_message, "Error: Unknown user!"))
        return ""

    user_chat = context.bot.get_chat(user_id)
    if user_chat.type != 'private':
        send_message(update.effective_message, tl(update.effective_message, "Itu bukan pengguna!"))
        return

    if not sql.is_user_gbanned(user_id):
        send_message(update.effective_message, tl(update.effective_message, "Pengguna ini tidak dilarang secara global!"))
        return

    banner = update.effective_user  # type: Optional[User]

    send_message(update.effective_message, tl(update.effective_message, "Saya akan berikan {} kesempatan kedua, secara global.").format(user_chat.first_name))

    send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS,
                 tl(update.effective_message, "{} telah menghapus larangan global untuk pengguna {}").format(mention_html(banner.id, banner.first_name),
                                                   mention_html(user_chat.id, user_chat.first_name)),
                 html=True)

    sql.ungban_user(user_id)

    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:
            member = context.bot.get_chat_member(chat_id, user_id)
            if member.status == 'kicked':
                context.bot.unban_chat_member(chat_id, user_id)

        except BadRequest as excp:
            if excp.message in UNGBAN_ERRORS:
                pass
            else:
                send_message(update.effective_message, tl(update.effective_message, "Tidak dapat menghapus larangan secara global karena: {}").format(excp.message))
                context.bot.send_message(OWNER_ID, tl(update.effective_message, "Tidak dapat menghapus larangan secara global karena: {}").format(excp.message))
                return
        except TelegramError:
            pass

    send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "Menghapus larangan global selesai!"))

    send_message(update.effective_message, tl(update.effective_message, "Orang ini telah dihapus larangannya."))
Пример #6
0
def __chat_settings_btn__(chat_id, user_id):
    getstatus = sql.does_chat_gban(chat_id)
    if getstatus:
        status = "✅ Aktif"
    else:
        status = "❎ Tidak Aktif"
    button = []
    button.append([
        InlineKeyboardButton(text=status,
                             callback_data="set_gstats={}".format(chat_id))
    ])
    return button
Пример #7
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  # 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_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  # type: Optional[User]
            if user and not is_user_admin(chat, user.id):
                check_and_ban(update, user.id, should_message=False)
Пример #8
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.")
Пример #9
0
def __chat_settings__(chat_id, user_id):
    return "Obrolan ini memberlakukan *larangan global*: `{}`.".format(
        sql.does_chat_gban(chat_id))
Пример #10
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."))
Пример #11
0
def __chat_settings__(chat_id, user_id):
    return tl(user_id, "This chat is enforcing *gbans*: `{}`.").format(
        sql.does_chat_gban(chat_id))
Пример #12
0
def ungban(update, context):
    message = update.effective_message  # type: Optional[Message]
    args = context.args

    user_id = extract_user(message, args)
    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 user_id == "error":
        send_message(update.effective_message,
                     tl(update.effective_message, "Error: Unknown user!"))
        return ""

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

    if not sql.is_user_gbanned(user_id):
        send_message(update.effective_message,
                     tl(update.effective_message, "This user is not gbanned!"))
        return

    banner = update.effective_user  # type: Optional[User]

    send_message(
        update.effective_message,
        tl(update.effective_message,
           "I'll give {} a second chance, globally.").format(
               user_chat.first_name))

    context.bot.send_message(MESSAGE_DUMP,
                             tl(update.effective_message,
                                "{} has ungbanned user {}").format(
                                    mention_html(banner.id, banner.first_name),
                                    mention_html(user_chat.id,
                                                 user_chat.first_name)),
                             parse_mode=ParseMode.HTML)

    sql.ungban_user(user_id)

    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:
            member = context.bot.get_chat_member(chat_id, user_id)
            if member.status == 'kicked':
                context.bot.unban_chat_member(chat_id, user_id)

        except BadRequest as excp:
            if excp.message in UNGBAN_ERRORS:
                pass
            else:
                send_message(
                    update.effective_message,
                    tl(update.effective_message,
                       "Could not un-gban due to: {}").format(excp.message))
                context.bot.send_message(
                    OWNER_ID,
                    tl(update.effective_message,
                       "Could not un-gban due to: {}").format(excp.message))
                return
        except TelegramError:
            pass

    context.bot.send_message(MESSAGE_DUMP,
                             tl(update.effective_message, "un-gban complete!"))

    send_message(update.effective_message,
                 tl(update.effective_message, "Person has been un-gbanned."))