Beispiel #1
0
def set_warn_limit(update, context) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    args = context.args

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

    if args:
        if args[0].isdigit():
            if int(args[0]) < 3:
                send_message(
                    update.effective_message,
                    tl(update.effective_message,
                       "Batas peringatan minimum adalah 3!"))
            else:
                sql.set_warn_limit(chat.id, int(args[0]))
                if conn:
                    text = tl(
                        update.effective_message,
                        "Diperbarui batas untuk diperingatkan {} pada *{}*"
                    ).format(args[0], chat_name)
                else:
                    text = tl(
                        update.effective_message,
                        "Diperbarui batas untuk diperingatkan {}").format(
                            args[0])
                send_message(update.effective_message,
                             text,
                             parse_mode="markdown")
                return "<b>{}:</b>" \
                       "\n#SET_WARN_LIMIT" \
                       "\n<b>Admin:</b> {}" \
                       "\nSet the warn limit to <code>{}</code>".format(html.escape(chat.title),
                                                                        mention_html(user.id, user.first_name), args[0])
        else:
            send_message(update.effective_message,
                         tl(update.effective_message, "Beri aku angkanya!"))
    else:
        limit, soft_warn, warn_mode = sql.get_warn_setting(chat.id)
        if conn:
            text = tl(update.effective_message,
                      "Batas peringatan saat ini adalah {} pada *{}*").format(
                          limit, chat_name)
        else:
            text = tl(update.effective_message,
                      "Batas peringatan saat ini adalah {}").format(limit)
        send_message(update.effective_message, text, parse_mode="markdown")
    return ""
Beispiel #2
0
def set_warn_limit(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    msg = update.effective_message  # type: Optional[Message]

    if args:
        if args[0].isdigit():
            if int(args[0]) < 3:
                msg.reply_text("The minimum warn limit is 3!")
            else:
                sql.set_warn_limit(chat.id, int(args[0]))
                msg.reply_text("Updated the warn limit to {}".format(args[0]))
                return "<b>{}:</b>" \
                       "\n#SET_WARN_LIMIT" \
                       "\n<b>Admin:</b> {}" \
                       "\nSet the warn limit to <code>{}</code>".format(html.escape(chat.title),
                                                                        mention_html(user.id, user.first_name), args[0])
        else:
            msg.reply_text("Give me a number as an arg!")
    else:
        limit, soft_warn = sql.get_warn_setting(chat.id)

        msg.reply_text("The current warn limit is {}".format(limit))
    return ""
Beispiel #3
0
def set_warn_limit(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat
    user = update.effective_user
    msg = update.effective_message

    if args:
        if args[0].isdigit():
            if int(args[0]) < 1:
                msg.reply_text(tld(chat.id, 'warns_warnlimit_min_1'))
            else:
                sql.set_warn_limit(chat.id, int(args[0]))
                msg.reply_text(
                    tld(chat.id,
                        'warns_warnlimit_updated_success').format(args[0]))
                return tld(chat.id, 'warns_set_warn_limit_log_channel').format(
                    html.escape(chat.title),
                    mention_html(user.id, user.first_name), args[0])
        else:
            msg.reply_text(tld(chat.id, 'warns_warnlimit_invalid_arg'))
    else:
        limit, soft_warn = sql.get_warn_setting(chat.id)

        msg.reply_text(tld(chat.id, 'warns_warnlimit_current').format(limit))
    return ""