Fixed manga too

This commit is contained in:
Adriene Hutchins 2020-03-23 20:23:10 -04:00
parent ddb5c1b193
commit bf8f29aa72
1 changed files with 39 additions and 42 deletions

View File

@ -159,52 +159,51 @@ Powered by kitsu.io"""
# Handling # Handling
async with ctx.typing(): async with ctx.typing():
async with aiohttp.ClientSession() as session: async with self.request.get(base + "manga", params={"filter[text]": query}) as resp:
async with session.get(base + "manga", params={"filter[text]": query}) as resp:
resp = await resp.json() resp = await resp.json()
resp = resp['data'] resp = resp['data']
if not resp: if not resp:
return await ctx.send("The requested manga coudn't be found") return await ctx.send("The requested manga coudn't be found")
manga = resp[0] manga = resp[0]
title = f'{manga["attributes"]["canonicalTitle"]}' title = f'{manga["attributes"]["canonicalTitle"]}'
manga_id = manga["id"] manga_id = manga["id"]
url = f"https://kitsu.io/manga/{manga_id}" url = f"https://kitsu.io/manga/{manga_id}"
embed = discord.Embed( embed = discord.Embed(
title=f"{title}", color=ctx.author.color, url=url) title=f"{title}", color=ctx.author.color, url=url)
embed.description = manga["attributes"]["synopsis"][0:425] + "..." embed.description = manga["attributes"]["synopsis"][0:425] + "..."
if manga["attributes"]["averageRating"]: if manga["attributes"]["averageRating"]:
embed.add_field(name="Average Rating", embed.add_field(name="Average Rating",
value=manga["attributes"]["averageRating"]) value=manga["attributes"]["averageRating"])
embed.add_field(name="Popularity Rank", embed.add_field(name="Popularity Rank",
value=manga["attributes"]["popularityRank"]) value=manga["attributes"]["popularityRank"])
if manga["attributes"]["ageRating"]: if manga["attributes"]["ageRating"]:
embed.add_field(name="Age Rating", embed.add_field(name="Age Rating",
value=manga["attributes"]["ageRating"]) value=manga["attributes"]["ageRating"])
embed.add_field( embed.add_field(
name="Status", value=manga["attributes"]["status"]) name="Status", value=manga["attributes"]["status"])
thing = '' if not manga['attributes'][ thing = '' if not manga['attributes'][
'endDate'] else f' to {manga["attributes"]["endDate"]}' 'endDate'] else f' to {manga["attributes"]["endDate"]}'
embed.add_field( embed.add_field(
name="Published", value=f"{manga['attributes']['startDate']}{thing}") name="Published", value=f"{manga['attributes']['startDate']}{thing}")
if manga['attributes']['chapterCount']: if manga['attributes']['chapterCount']:
embed.add_field(name="Chapters", embed.add_field(name="Chapters",
value=manga['attributes']["chapterCount"]) value=manga['attributes']["chapterCount"])
embed.add_field( embed.add_field(
name="Type", value=manga['attributes']["mangaType"]) name="Type", value=manga['attributes']["mangaType"])
embed.set_thumbnail( embed.set_thumbnail(
url=manga['attributes']["posterImage"]["original"]) url=manga['attributes']["posterImage"]["original"])
try: try:
await ctx.send(f"**{title}** - <{url}>", embed=embed) await ctx.send(f"**{title}** - <{url}>", embed=embed)
except Exception as e: except Exception :
aired = f"{manga['attributes']['startDate']}{thing}" aired = f"{manga['attributes']['startDate']}{thing}"
template = f""" template = f"""
url: {url} url: {url}
Title: {title} Title: {title}
Average Rating: {manga["attributes"]["averageRating"]} Average Rating: {manga["attributes"]["averageRating"]}
@ -216,9 +215,7 @@ Type: {manga['attributes']["showType"]}
Powered by kitsu.io""" Powered by kitsu.io"""
await ctx.send(template) await ctx.send(template)
await session.close()
def setup(bot): def setup(bot):