예제 #1
0
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str:
    message = update.effective_message
    chat = update.effective_chat
    user = update.effective_user

    user_id = extract_user(message, args)

    if user_id:
        sql.reset_warns(user_id, chat.id)
        message.reply_text(tld(chat.id, 'warns_reset_success'))
        warned = chat.get_member(user_id).user
        return tld(chat.id, 'warns_reset_log_channel').format(
            html.escape(chat.title), mention_html(user.id, user.first_name),
            mention_html(warned.id, warned.first_name), warned.id)
    else:
        message.reply_text(tld(chat.id, 'common_err_no_user'))
    return ""
예제 #2
0
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str:
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    user_id = extract_user(message, args)

    if user_id:
        sql.reset_warns(user_id, chat.id)
        message.reply_text("Warnings have been reset!")
        warned = chat.get_member(user_id).user
        return "<b>{}:</b>" \
               "\n#RESETWARNS" \
               "\n<b>Admin:</b> {}" \
               "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name),
                                                            mention_html(warned.id, warned.first_name),
                                                            warned.id)
    else:
        message.reply_text("No user has been designated!")
    return ""
예제 #3
0
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str:
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    user_id = extract_user(message, args)

    if user_id:
        sql.reset_warns(user_id, chat.id)
        message.reply_text("Warnings ഒക്കെ reset ചെയ്തിട്ടുണ്ട്!")
        warned = chat.get_member(user_id).user
        return "<b>{}:</b>" \
               "\n#RESETWARNS" \
               "\n<b>Admin:</b> {}" \
               "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name),
                                                            mention_html(warned.id, warned.first_name),
                                                            warned.id)
    else:
        message.reply_text(
            "ആരുടെ warnings ആണ് reset ചെയ്യേണ്ടത് എന്നു പറഞ്ഞില്ലല്ലോ?")
    return ""
예제 #4
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("അഡ്മിൻ ആണ്... warn ചെയ്യാൻ പറ്റില്ല!")
        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 = "{} warnings, {} നെ എടുത്തു വെളിയിൽ കളഞ്ഞു!".format(
                limit, mention_html(user.id, user.first_name))

        else:  # ban
            chat.kick_member(user.id)
            reply = "{} warnings, {} ന് ബണ്ണ് കൊടുത്തു വിട്ടിട്ടുണ്ട്!".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 = []
        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),
                                                                  reason, num_warns, limit)

    else:
        keyboard = InlineKeyboardMarkup([[
            InlineKeyboardButton("Remove warn",
                                 callback_data="rm_warn({})".format(user.id))
        ]])

        reply = "{} has been WARNED! \nCount: {}/{}".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
예제 #5
0
def warn(user: User,
         chat: Chat,
         reason: str,
         message: Message,
         warner: User = None) -> str:
    bot = dispatcher.bot

    if is_user_admin(chat, user.id):
        message.reply_text(tld(chat.id, 'warns_warn_admin_no_warn'))
        return ""

    if warner:
        warner_tag = mention_html(warner.id, warner.first_name)
    else:
        warner_tag = tld(chat.id, 'warns_warn_admin_autofilter')

    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 = tld(chat.id, 'warns_max_warn_kick').format(
                limit, mention_html(user.id, user.first_name))

        else:  # ban
            chat.kick_member(user.id)
            reply = tld(chat.id, 'warns_max_warn_ban').format(
                limit, mention_html(user.id, user.first_name))

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

        keyboard = []
        log_reason = tld(chat.id, 'warns_warn_ban_log_channel').format(
            html.escape(chat.title), warner_tag,
            mention_html(user.id, user.first_name), user.id, reason, num_warns,
            limit)

    else:
        keyboard = [[
            InlineKeyboardButton(tld(chat.id, 'warns_btn_remove_warn'),
                                 callback_data="rm_warn({})".format(user.id))
        ]]
        rules = rules_sql.get_rules(chat.id)

        if rules:
            keyboard[0].append(
                InlineKeyboardButton(tld(chat.id, 'warns_btn_rules'),
                                     url="t.me/{}?start={}".format(
                                         bot.username, chat.id)))

        reply = tld(chat.id, 'warns_user_warned').format(
            mention_html(user.id, user.first_name), num_warns, limit)
        if reason:
            reply += tld(chat.id, 'warns_latest_warn_reason').format(
                html.escape(reason))

        log_reason = tld(chat.id, 'warns_warn_log_channel').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=InlineKeyboardMarkup(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=InlineKeyboardMarkup(keyboard),
                               parse_mode=ParseMode.HTML,
                               quote=False)
        else:
            raise
    return log_reason
예제 #6
0
def warn(user: User,
         chat: Chat,
         reason: str,
         message: Message,
         warner: User = None) -> str:
    bot = dispatcher.bot

    if is_user_admin(chat, user.id):
        message.reply_text("I'm not going to warn an admin!")
        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 = "{} warnings, {} has been kicked!".format(
                limit, mention_html(user.id, user.first_name))

        else:  # ban
            chat.kick_member(user.id)
            reply = "{} 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 = []
        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 = [[
            InlineKeyboardButton("тЪая╕П Remove warn",
                                 callback_data="rm_warn({})".format(user.id))
        ]]
        rules = rules_sql.get_rules(chat.id)

        if rules:
            keyboard[0].append(
                InlineKeyboardButton("ЁЯУЭ Rules",
                                     url="t.me/{}?start={}".format(
                                         bot.username, chat.id)))

        reply = "{} <b>has been warned!</b>\nThey have {}/{} warnings.".format(
            mention_html(user.id, user.first_name), num_warns, limit)
        if reason:
            reply += "\nThe latest warning was because:\n<code>{}</code>".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=InlineKeyboardMarkup(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=InlineKeyboardMarkup(keyboard),
                               parse_mode=ParseMode.HTML,
                               quote=False)
        else:
            raise
    return log_reason
예제 #7
0
파일: warns.py 프로젝트: MhdRezza/hitsuki
def reset_warns(update, context):
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = context.args

    user_id = extract_user(message, args)

    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'] is 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 and user_id != "error":
        sql.reset_warns(user_id, chat.id)
        if conn:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Peringatan telah disetel ulang pada *{}*!").format(
                       chat_name),
                parse_mode="markdown")
        else:
            send_message(
                update.effective_message,
                tl(update.effective_message,
                   "Peringatan telah disetel ulang!"))
        warned = chat.get_member(user_id).user
        return "<b>{}:</b>" \
               "\n#RESETWARNS" \
               "\n<b>Admin:</b> {}" \
               "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
                                                            mention_html(user.id, user.first_name),
                                                            mention_html(warned.id, warned.first_name),
                                                            warned.id)
    else:
        send_message(
            update.effective_message,
            tl(update.effective_message, "Tidak ada pengguna yang ditunjuk!"))
    return ""
예제 #8
0
파일: warns.py 프로젝트: MhdRezza/hitsuki
def warn(user: User,
         chat: Chat,
         reason: str,
         message: Message,
         warner: User = None,
         conn=False) -> str:
    if is_user_admin(chat, user.id):
        return ""

    if warner:
        warner_tag = mention_html(warner.id, warner.first_name)
    else:
        warner_tag = tl(chat.id, "Filter peringatan otomatis.")

    limit, soft_warn, warn_mode = 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 not soft_warn:
            if not warn_mode:
                chat.unban_member(user.id)
                reply = tl(chat.id,
                           "{} peringatan, {} telah ditendang!").format(
                               limit, mention_html(user.id, user.first_name))
            elif warn_mode == 1:
                chat.unban_member(user.id)
                reply = tl(chat.id,
                           "{} peringatan, {} telah ditendang!").format(
                               limit, mention_html(user.id, user.first_name))
            elif warn_mode == 2:
                chat.kick_member(user.id)
                reply = tl(chat.id,
                           "{} peringatan, {} telah diblokir!").format(
                               limit, mention_html(user.id, user.first_name))
            elif warn_mode == 3:
                message.bot.restrict_chat_member(chat.id,
                                                 user.id,
                                                 can_send_messages=False)
                reply = tl(chat.id,
                           "{} peringatan, {} telah dibisukan!").format(
                               limit, mention_html(user.id, user.first_name))
        else:
            chat.kick_member(user.id)
            reply = tl(chat.id, "{} peringatan, {} telah diblokir!").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(tl(chat.id, "Hapus peringatan"),
                                 callback_data="rm_warn({})".format(user.id)),
            InlineKeyboardButton(tl(chat.id, "Peraturan"),
                                 url="t.me/{}?start={}".format(
                                     dispatcher.bot.username, chat.id))
        ]])

        if num_warns + 1 == limit:
            if not warn_mode:
                action_mode = tl(chat.id, "tendang")
            elif warn_mode == 1:
                action_mode = tl(chat.id, "tendang")
            elif warn_mode == 2:
                action_mode = tl(chat.id, "blokir")
            elif warn_mode == 3:
                action_mode = tl(chat.id, "bisukan")
            reply = tl(
                chat.id,
                "{} punya {}/{} peringatan... Jika anda di peringati lagi maka kamu akan di {}!"
            ).format(mention_html(user.id, user.first_name), num_warns, limit,
                     action_mode)
        else:
            reply = tl(chat.id,
                       "{} punya {}/{} peringatan... Hati-hati!").format(
                           mention_html(user.id, user.first_name), num_warns,
                           limit)
        if reason:
            reply += tl(chat.id,
                        "\nAlasan pada peringatan terakhir:\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:
        if conn:
            send_message_raw(chat.id,
                             reply,
                             reply_markup=keyboard,
                             parse_mode=ParseMode.HTML)
        else:
            send_message_raw(chat.id,
                             reply,
                             reply_to_message_id=message.message_id,
                             reply_markup=keyboard,
                             parse_mode=ParseMode.HTML)
        # send_message(update.effective_message, reply, reply_markup=keyboard, parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            if conn:
                message.bot.sendMessage(chat.id,
                                        reply,
                                        reply_markup=keyboard,
                                        parse_mode=ParseMode.HTML)
            else:
                try:
                    message.bot.sendMessage(
                        chat.id,
                        reply,
                        reply_to_message_id=message.message_id,
                        reply_markup=keyboard,
                        parse_mode=ParseMode.HTML,
                        quote=False)
                except BadRequest:
                    message.bot.sendMessage(chat.id,
                                            reply,
                                            reply_markup=keyboard,
                                            parse_mode=ParseMode.HTML,
                                            quote=False)
            # send_message(update.effective_message, reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False)
        else:
            raise
    return log_reason