예제 #1
0
def warns(update, context):
    message = update.effective_message
    chat = update.effective_chat
    args = context.args
    user = update.effective_user
    user_id = extract_user(message, args) or update.effective_user.id

    conn = connected(context.bot, update, chat, user.id, need_admin=False)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if chat.type == "private":
            return
        else:
            chat_id = update.effective_chat.id
            chat_name = chat.title

    result = sql.get_warns(user_id, chat_id)

    num = 1
    if result and result[0] != 0:
        num_warns, reasons = result
        limit, _ = sql.get_warn_setting(chat_id)

        if reasons:
            if conn:
                text = "This user has {}/{} warnings, in *{}* for the following reasons:".format(
                    num_warns, limit, chat_name
                )
            else:
                text = (
                    "This user has {}/{} warnings, for the following reasons:".format(
                        num_warns,
                        limit,
                    )
                )
            for reason in reasons:
                text += "\n {}. {}".format(num, reason)
                num += 1

            msgs = split_message(text)
            for msg in msgs:
                update.effective_message.reply_text(msg, parse_mode="markdown")
        else:
            update.effective_message.reply_text(
                "User has {}/{} warnings, but no reasons for any of them.".format(
                    num_warns, limit
                ),
                parse_mode="markdown",
            )
    else:
        update.effective_message.reply_text("This user hasn't got any warnings!")
예제 #2
0
def blacklist(update, context):
    chat = update.effective_chat
    user = update.effective_user
    args = context.args

    conn = connected(context.bot, update, chat, user.id, need_admin=False)
    if conn:
        chat_id = conn
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if chat.type == "private":
            return
        else:
            chat_id = update.effective_chat.id
            chat_name = chat.title

    filter_list = "Current blacklisted words in <b>{}</b>:\n".format(chat_name)

    all_blacklisted = sql.get_chat_blacklist(chat_id)

    if len(args) > 0 and args[0].lower() == "copy":
        for trigger in all_blacklisted:
            filter_list += "<code>{}</code>\n".format(html.escape(trigger))
    else:
        for trigger in all_blacklisted:
            filter_list += " - <code>{}</code>\n".format(html.escape(trigger))

    # for trigger in all_blacklisted:
    #     filter_list += " - <code>{}</code>\n".format(html.escape(trigger))

    split_text = split_message(filter_list)
    for text in split_text:
        if filter_list == "Current blacklisted words in <b>{}</b>:\n".format(
                chat_name):
            send_message(
                update.effective_message,
                "No blacklisted words in <b>{}</b>!".format(chat_name),
                parse_mode=ParseMode.HTML,
            )
            return
        send_message(update.effective_message, text, parse_mode=ParseMode.HTML)