Ejemplo n.º 1
0
def button(bot: Bot, update: Update) -> str:
    query = update.callback_query  # type: Optional[CallbackQuery]
    user = update.effective_user  # type: Optional[User]
    match = re.match(r"rm_warn\((.+?)\)", query.data)
    if match:
        user_id = match.group(1)
        chat = update.effective_chat  # type: Optional[Chat]
        if not is_user_admin(chat, int(user.id)):
            query.answer(
                text=
                "You are not authorized to remove this warn! Only administrators may remove warns.",
                show_alert=True)
            return ""
        res = sql.remove_warn(user_id, chat.id)
        if res:
            update.effective_message.edit_text("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(
                "{} has already has 0 warns.".format(
                    mention_html(user.id, user.first_name)),
                parse_mode=ParseMode.HTML)

    return ""
Ejemplo n.º 2
0
def rmwarn_handler(bot: Bot, update: Update) -> str:
    chat = update.effective_chat
    query = update.callback_query
    user = update.effective_user
    match = re.match(r"rm_warn\((.+?)\)", query.data)
    if match:
        user_id = match.group(1)
        if not is_user_admin(chat, int(user.id)):
            query.answer(text=tld(chat.id, 'warns_remove_admin_only'),
                         show_alert=True)
            return ""
        res = sql.remove_warn(user_id, chat.id)
        if res:
            update.effective_message.edit_text(tld(
                chat.id, 'warns_remove_success').format(
                    mention_html(user.id, user.first_name)),
                                               parse_mode=ParseMode.HTML)
            user_member = chat.get_member(user_id)
            return tld(chat.id, 'warns_remove_log_channel').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(tld(
                chat.id, 'warns_user_has_no_warns').format(
                    mention_html(user.id, user.first_name)),
                                               parse_mode=ParseMode.HTML)

    return ""
Ejemplo n.º 3
0
def remove_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.remove_warn(user_id, chat.id)
        message.reply_text(tld(chat.id, 'warns_latest_remove_success'))
        warned = chat.get_member(user_id).user
        return tld(chat.id, 'warns_remove_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 ""
Ejemplo n.º 4
0
def remove_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.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 ""