<commit_before>import math

import discord
from discord.ext import commands
from discord.ext.commands.cooldowns import BucketType

from .exceptions import APIError, APINotFound
from .utils.chat import cleanup_xml_tags
from .utils.db import prepare_search


class AchievementsMixin:
    @commands.command(
        name="achievement", aliases=["achievementinfo", "ach", "achiev"])
    @commands.cooldown(1, 3, BucketType.user)
    async def achievementinfo(self, ctx, *, achievement):
        """Display achievement information and your completion status"""
        user = ctx.author
        cursor = self.db.achievements.find({
            "name": prepare_search(achievement)
        })
        choice = await self.selection_menu(ctx, cursor)
        if not choice:
            return
        try:
            doc = await self.fetch_key(user, ["progression"])
            endpoint = "account/achievements?id=" + str(choice["_id"])
            results = await self.call_api(endpoint, key=doc["key"])
        except APINotFound:
            results = {}
        except APIError as e:
            return await self.error_handler(ctx, e)
        embed = await self.ach_embed(ctx, results, choice)
        embed.set_author(name=doc["account_name"], icon_url=user.avatar_url)
        try:
            await ctx.send(
                "{.mention}, here is your achievement:".format(user),
                embed=embed)
        except discord.Forbidden:
            await ctx.send("Need permission to embed links")

    async def ach_embed(self, ctx, res, ach):
        description = cleanup_xml_tags(ach["description"])
        data = discord.Embed(
            title=ach["name"],
            description=description,
            color=await self.get_embed_color(ctx))
        if "icon" in ach:
            data.set_thumbnail(url=ach["icon"])
        data.add_field(
            name="Requirement", value=ach["requirement"], inline=False)
        tiers = ach["tiers"]
        repeated = res["repeated"] if "repeated" in res else 0<commit_msg>Fix error when achievement didnt have requirements<commit_after>import math

import discord
from discord.ext import commands
from discord.ext.commands.cooldowns import BucketType

from .exceptions import APIError, APINotFound
from .utils.chat import cleanup_xml_tags
from .utils.db import prepare_search


class AchievementsMixin:
    @commands.command(
        name="achievement", aliases=["achievementinfo", "ach", "achiev"])
    @commands.cooldown(1, 3, BucketType.user)
    async def achievementinfo(self, ctx, *, achievement):
        """Display achievement information and your completion status"""
        user = ctx.author
        cursor = self.db.achievements.find({
            "name": prepare_search(achievement)
        })
        choice = await self.selection_menu(ctx, cursor)
        if not choice:
            return
        try:
            doc = await self.fetch_key(user, ["progression"])
            endpoint = "account/achievements?id=" + str(choice["_id"])
            results = await self.call_api(endpoint, key=doc["key"])
        except APINotFound:
            results = {}
        except APIError as e:
            return await self.error_handler(ctx, e)
        embed = await self.ach_embed(ctx, results, choice)
        embed.set_author(name=doc["account_name"], icon_url=user.avatar_url)
        try:
            await ctx.send(
                "{.mention}, here is your achievement:".format(user),
                embed=embed)
        except discord.Forbidden:
            await ctx.send("Need permission to embed links")

    async def ach_embed(self, ctx, res, ach):
        description = cleanup_xml_tags(ach["description"])
        data = discord.Embed(
            title=ach["name"],
            description=description,
            color=await self.get_embed_color(ctx))
        if "icon" in ach:
            data.set_thumbnail(url=ach["icon"])
        requirement = ach.get("requirement")
        if requirement:
            data.add_field(
                name="Requirement", value=ach["requirement"], inline=False)
        tiers = ach["tiers"]
        repeated = res["repeated"] if "repeated" in res else 0
{'fraction_non_alphanumeric': 0.10794638583054093, 'fraction_numerical': 0.0014360938247965534, 'mean_word_length': 2.550552251486831, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4120353', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1158, 'n_words': 291}