<commit_before>import plumeria.util.http as http
from plumeria import config
from plumeria.command import commands, CommandError
from plumeria.command.parse import Text
from plumeria.message.mappings import build_mapping
from plumeria.util.collections import SafeStructure
from plumeria.util.ratelimit import rate_limit


@commands.register("haveibeenpwned", "pwned", category="Search", params=[Text('query')])
@rate_limit(burst_size=4)
async def have_i_been_pwned(message, query):
    """
    Checks where an account (specified by account name or email address) exists
    on sites that have experienced data breaches.

    Example::

        pwned <EMAIL>

    """
    r = await http.get("https://haveibeenpwned.com/api/v2/breachedaccount/" + query, headers=[
        ('User-Agent', 'Plumeria chat bot (+https://gitlab.com/sk89q/Plumeria)')
    ])

    if not len(r.text().strip()):
        raise CommandError("Account not found! (That's good.)")

    results = SafeStructure(r.json())

    return build_mapping(
        [(e.Title, "{} ({} breached) ({})".format(e.BreachDate, e.PwnCount, ", ".join(e.DataClasses))) for e in
         results])<commit_msg>Handle missing accounts on HaveIBeenPwned properly.<commit_after>import plumeria.util.http as http
from plumeria import config
from plumeria.command import commands, CommandError
from plumeria.command.parse import Text
from plumeria.message.mappings import build_mapping
from plumeria.util.collections import SafeStructure
from plumeria.util.ratelimit import rate_limit


@commands.register("haveibeenpwned", "pwned", category="Search", params=[Text('query')])
@rate_limit(burst_size=4)
async def have_i_been_pwned(message, query):
    """
    Checks where an account (specified by account name or email address) exists
    on sites that have experienced data breaches.

    Example::

        pwned <EMAIL>

    """
    try:
        r = await http.get("https://haveibeenpwned.com/api/v2/breachedaccount/" + query, headers=[
            ('User-Agent', 'Plumeria chat bot (+https://gitlab.com/sk89q/Plumeria)')
        ])
    except http.BadStatusCodeError as e:
        if e.http_code == 404:
            raise CommandError("Account not found! (That's good.)")
        else:
            raise e

    results = SafeStructure(r.json())

    return build_mapping(
        [(e.Title, "{} ({} breached) ({})".format(e.BreachDate, e.PwnCount, ", ".join(e.DataClasses))) for e in
         results])
{'fraction_non_alphanumeric': 0.12336601307189543, 'fraction_numerical': 0.004493464052287581, 'mean_word_length': 3.7553398058252427, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1351042', 'n_tokens_mistral': 774, 'n_tokens_neox': 728, 'n_words': 196}