-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkitsu.py
88 lines (72 loc) · 3.87 KB
/
kitsu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import discord
import requests
from discord.ext import commands
API_URL = "https://kitsu.io/api/edge/"
#this is shit but meh...
class Kitsu:
@commands.command()
async def anime(self, ctx, query: str):
"""Look up anime"""
with requests.get(API_URL + "anime", params={"filter[text]": query}) as resp:
resp = resp.json()["data"]
if not resp:
return await ctx.send("The requested anime coudn't be found")
anime = resp[0]
title = f'{anime["attributes"]["canonicalTitle"]}'
anime_id = anime["id"]
url = f"https://kitsu.io/anime/{anime_id}"
embed = discord.Embed(title=f"{title}", color=0xFFD54F, url=url)
embed.description = anime["attributes"]["synopsis"][0:425] + "..."
embed.add_field(name="Average Rating",
value=anime["attributes"]["averageRating"])
embed.add_field(name="Popularity Rank",
value=anime["attributes"]["popularityRank"])
embed.add_field(name="Age Rating",
value=anime["attributes"]["ageRating"])
embed.add_field(name="Status", value=anime["attributes"]["status"])
thing = '' if not anime['attributes']['endDate'] else f' to {anime["attributes"]["endDate"]}'
embed.add_field(
name="Aired", value=f"{anime['attributes']['startDate']}{thing}")
embed.add_field(name="Episodes",
value=anime['attributes']["episodeCount"])
embed.add_field(name="Type", value=anime['attributes']["showType"])
embed.set_thumbnail(
url=anime['attributes']["posterImage"]["original"])
await ctx.send(embed=embed)
#######################################################################################################################
@commands.command()
async def manga(self, ctx, query: str):
"""Look up manga"""
with requests.get(API_URL + "manga", params={"filter[text]": query}) as resp:
resp = resp.json()["data"]
if not resp:
return await ctx.send("The requested manga coudn't be found")
manga = resp[0]
title = f'{manga["attributes"]["canonicalTitle"]}'
manga_id = manga["id"]
url = f"https://kitsu.io/manga/{manga_id}"
embed = discord.Embed(title=f"{title}", color=0xFFD54F, url=url)
embed.description = manga["attributes"]["synopsis"][0:425] + "..."
if manga["attributes"]["averageRating"]:
embed.add_field(name="Average Rating",
value=manga["attributes"]["averageRating"])
embed.add_field(name="Popularity Rank",
value=manga["attributes"]["popularityRank"])
if manga["attributes"]["ageRating"]:
embed.add_field(name="Age Rating",
value=manga["attributes"]["ageRating"])
embed.add_field(name="Status", value=manga["attributes"]["status"])
thing = '' if not manga['attributes']['endDate'] else f' to {manga["attributes"]["endDate"]}'
embed.add_field(
name="Published", value=f"{manga['attributes']['startDate']}{thing}")
if manga['attributes']['chapterCount']:
embed.add_field(name="Chapters",
value=manga['attributes']["chapterCount"])
embed.add_field(
name="Type", value=manga['attributes']["mangaType"])
embed.set_thumbnail(
url=manga['attributes']["posterImage"]["original"])
await ctx.send(embed=embed)
def setup(bot):
"""Set up the extension."""
bot.add_cog(Kitsu())