Esempio n. 1
0
def remove_warns(update, context):
    message = update.effective_message
    chat = update.effective_chat
    user = update.effective_user
    args = context.args
    user_id = extract_user(message, args)

    if user_id:
        sql.remove_warn(user_id, chat.id)
        message.reply_text("Last warn has been removed!")
        warned = chat.get_member(user_id).user
        return (
            "<b>{}:</b>"
            "\n#UNWARN"
            "\n<b>• Admin:</b> {}"
            "\n<b>• User:</b> {}"
            "\n<b>• ID:</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 ""
Esempio n. 2
0
def button(update, context):
    query = update.callback_query
    user = update.effective_user
    match = re.match(r"rm_warn\((.+?)\)", query.data)
    if match:
        user_id = match.group(1)
        chat = update.effective_chat
        res = sql.remove_warn(user_id, chat.id)
        if res:
            update.effective_message.edit_text(
                "Last warn removed by {}.".format(
                    mention_html(user.id, user.first_name)
                ),
                parse_mode=ParseMode.HTML,
            )
            user_member = chat.get_member(user_id)
            return (
                "<b>{}:</b>"
                "\n#UNWARN"
                "\n<b>Admin:</b> {}"
                "\n<b>User:</b> {} (<code>{}</code>)".format(
                    html.escape(chat.title),
                    mention_html(user.id, user.first_name),
                    mention_html(user_member.user.id, user_member.user.first_name),
                    user_member.user.id,
                )
            )
        else:
            update.effective_message.edit_text(
                "This user already has no warns.", parse_mode=ParseMode.HTML
            )

    return ""