added anime and manga search command
This commit is contained in:
parent
9d1022caf1
commit
b1d64507a6
|
@ -1,43 +0,0 @@
|
|||
{
|
||||
"VERSION": "1.9 testing",
|
||||
"DESCRIPTION": "a minimalist search utility bot for discord, designed by taciturasa.",
|
||||
"REPO": "https://github.com/taciturasa/searchbot-discord",
|
||||
"SERVER": "https://discord.gg/4BpReNV",
|
||||
"TOKEN": "",
|
||||
"CACHE": false,
|
||||
"PREFIX": ["search!"],
|
||||
|
||||
"MAINTENANCE": false,
|
||||
"CASE_INSENSITIVE": true,
|
||||
"PREFIXLESS_DMS": true,
|
||||
"MENTION_ASSIST": true,
|
||||
"CUSTOM_HELP": true,
|
||||
|
||||
"PERMS": 378944,
|
||||
"BLOCKED": [],
|
||||
|
||||
"BOTLISTS": {
|
||||
"DBL": "",
|
||||
"DBOTS": "",
|
||||
"BOD": "",
|
||||
"DBLCOM": "",
|
||||
"BLSPACE": "",
|
||||
"TABFT_LINK": "",
|
||||
"DAD": ""
|
||||
},
|
||||
|
||||
"HOOKS": {
|
||||
"INFO_HOOK": "",
|
||||
"WARN_HOOK": "",
|
||||
"ERROR_HOOK": "",
|
||||
"DEBUG_HOOK": ""
|
||||
},
|
||||
|
||||
"RETHINK": {
|
||||
"DB": "",
|
||||
"USERNAME": "",
|
||||
"PASSWORD": "",
|
||||
"HOST": "",
|
||||
"PORT": null
|
||||
}
|
||||
}
|
|
@ -29,7 +29,6 @@ class Search(commands.Cog):
|
|||
with open('searxes.txt') as f:
|
||||
self.instances = f.read().split('\n')
|
||||
|
||||
|
||||
async def _search_logic(self, query: str, is_nsfw: bool = False,
|
||||
category: str = None) -> str:
|
||||
"""Provides search logic for all search commands."""
|
||||
|
@ -278,6 +277,96 @@ class Search(commands.Cog):
|
|||
)
|
||||
await ctx.send(msg)
|
||||
|
||||
@commands.command()
|
||||
async def anime(self, ctx, *, query: str):
|
||||
"""Lookup anime information online, uses the https://kitsu.io/ public API."""
|
||||
base = "https://kitsu.io/api/edge/"
|
||||
# Handling
|
||||
async with ctx.typing():
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(base + "anime", params={"filter[text]": query}) as resp:
|
||||
resp = await resp.json()
|
||||
resp = resp['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=ctx.author.color, 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"])
|
||||
embed.set_footer(
|
||||
text=f"Requested by {ctx.author.name} | Powered by kitsu.io", icon_url=ctx.author.avatar_url_as(format="png"))
|
||||
await ctx.send(embed=embed)
|
||||
session.close()
|
||||
|
||||
@commands.command()
|
||||
async def manga(self, ctx, *, query: str):
|
||||
"""Lookup manga information online, uses the https://kitsu.io/ public API."""
|
||||
base = "https://kitsu.io/api/edge/"
|
||||
# Handling
|
||||
async with ctx.typing():
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(base + "manga", params={"filter[text]": query}) as resp:
|
||||
resp = await resp.json()
|
||||
resp = resp['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=ctx.author.color, 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)
|
||||
session.close()
|
||||
|
||||
@commands.command()
|
||||
@commands.is_owner()
|
||||
async def rejson(self, ctx):
|
||||
|
@ -330,7 +419,6 @@ class Search(commands.Cog):
|
|||
name="Search Results"
|
||||
)
|
||||
|
||||
|
||||
# Sends result
|
||||
await ctx.send(msg)
|
||||
|
||||
|
|
Loading…
Reference in New Issue