import discord
from asyncjisho import Jisho
from discord.ext import commands
from discord.ext.commands import Cog

from bot import BeattieBot
from context import BContext
from utils.paginator import Paginator


class Dictionary(Cog):
    jisho_url = "http://jisho.org/search/{}"
    urban_url = "http://api.urbandictionary.com/v0/define"

    def __init__(self, bot: BeattieBot):
        self.jisho = Jisho(session=bot.session)

    @commands.command(name="jisho")
    async def jisho_(self, ctx: BContext, *, keywords: str) -> None:
        """Get results from Jisho.org, Japanese dictionary"""
        async with ctx.typing():
            data = await self.jisho.lookup(keywords)
        if not data:
            await ctx.send("No words found.")
            return
        results = []
        size = len(data)
        for i, res in enumerate(data, 1):
            res = {k: "\n".join(set(v)) or "None" for k, v in res.items()}
            res["english"] = ", ".join(res["english"].split("\n"))
            embed = discord.Embed()
            embed.url = self.jisho_url.format("%20".join(keywords.split()))
            embed.title = keywords
            embed.add_field(name="Words", value=res["words"])
            embed.add_field(name="Readings", value=res["readings"])
            embed.add_field(name="Parts of Speech", value=res["parts_of_speech"])
            embed.add_field(name="Meanings", value=res["english"])
            embed.set_footer(text="Page {}/{}".format(i, size))
            embed.color = discord.Color(0x56D926)
            results.append(embed)
        paginator = Paginator(results)
        await paginator.start(ctx)

    @commands.command(aliases=["ud", "urban", "urbandict"])
    async def urbandictionary(self, ctx: BContext, *, word: str) -> None:
        """Look up a word on urbandictionary.com"""
        params = {"term": word}
        get = ctx.bot.get
        async with ctx.typing(), get(self.urban_url, params=params) as resp:
            data = await resp.json()
        try:
            results = data["list"]
            results[0]
        except IndexError:
            await ctx.send("Word not found.")
        else:
            embeds = []
            size = len(results)
            for i, res in enumerate(results, 1):
                embed = discord.Embed()
                embed.title = res["word"]
                embed.url = res["permalink"]
                embed.description = res["definition"]
                embed.color = discord.Color(0xE86222)
                embed.set_footer(text="Page {}/{}".format(i, size))
                embeds.append(embed)
            paginator = Paginator(embeds)
            await paginator.start(ctx)


def setup(bot: BeattieBot) -> None:
    bot.add_cog(Dictionary(bot))

@@ -456,16 +456,39 @@
 =%22jisho%22
+, aliases=%5B%22%E3%81%98%E3%81%97%E3%82%87%22, %22%E8%BE%9E%E6%9B%B8%22%5D
 )%0A    as

Add japanese aliases for jisho