Reformatted everything to use less space

Cleaner to look at imo
pull/8/head
sgoudham 4 years ago
parent 5972de2e54
commit eb86d51247

@ -41,6 +41,29 @@ class WaifuCommandNotFound(Exception):
return f'{self.command} -> {self.message}' return f'{self.command} -> {self.message}'
async def get_airing_api(self, url):
"""Retreiving information about the airing shows/waifus"""
url = f"https://mywaifulist.moe/api/v1/{url}"
data = {'content-type': "application/json"}
# Searching API for the current airing shows
async with aiohttp.ClientSession() as session:
async with session.get(url, data=data, headers=self.headers) as resp:
# Store waifu's in dict when request is successful, else send an error
if resp.status == 200:
airing = await resp.json()
# Send error if something went wrong internally/while grabbing data from API
else:
await self.bot.generate_embed(ctx, desc="**Something went wrong with MyWaifuList!**")
# Close session
await session.close()
return airing
def store_dict(dict_, key, value): def store_dict(dict_, key, value):
"""Method to store waifu's in the new dict""" """Method to store waifu's in the new dict"""
@ -246,43 +269,50 @@ class Anime(Cog):
error = WaifuCommandNotFound(ctx.command, ctx) error = WaifuCommandNotFound(ctx.command, ctx)
await self.bot.generate_embed(ctx, desc=error.message) await self.bot.generate_embed(ctx, desc=error.message)
@airing.command(name="popular", aliases=["pop"]) @airing.command(name="trash", aliases=["worst", "garbage"])
@bot_has_permissions(embed_links=True, add_reactions=True) @bot_has_permissions(embed_links=True, add_reactions=True)
async def airing_popular(self, ctx): async def airing_trash(self, ctx):
"""Get the most popular waifus from the airing shows""" """Get the most popular waifus from the airing shows"""
# Local Variable i to allow the pages to be modified # Variables to set up the reaction menu
i = 0 i = 0
airing_trash = {}
trash_waifus = await get_airing_api(self, "airing/trash")
airing_best = {} # Store all the shows with the name as the key
url = "https://mywaifulist.moe/api/v1/airing/popular" for waifu in trash_waifus["data"]:
data = {'content-type': "application/json"} airing_trash[waifu["name"]] = {}
for value in waifu:
store_dict(airing_trash, waifu, value)
# Searching API for the current airing shows # Get the instance of the bot
async with aiohttp.ClientSession() as session: bot = ctx.guild.get_member(self.bot.user.id)
async with session.get(url, data=data, headers=self.headers) as resp:
# Store waifu's in dict when request is successful, else send an error
if resp.status == 200:
best_waifus = await resp.json()
# Send error if something went wrong internally/while grabbing data from API # Send the menu to the display
else: menu = HelpMenu(i, airing_trash, "waifu", self.bot, bot)
await self.bot.generate_embed(ctx, desc="**Something went wrong with MyWaifuList!**") await menu.start(ctx)
# Close session @airing.command(name="popular", aliases=["pop"])
await session.close() @bot_has_permissions(embed_links=True, add_reactions=True)
async def airing_popular(self, ctx):
"""Get the most popular waifus from the airing shows"""
# Variables to setup the reaction menu
i = 0
airing_popular = {}
popular_waifus = await get_airing_api(self, "airing/popular")
# Store all the shows with the name as the key # Store all the shows with the name as the key
for waifu in best_waifus["data"]: for waifu in popular_waifus["data"]:
airing_best[waifu["name"]] = {} airing_popular[waifu["name"]] = {}
for value in waifu: for value in waifu:
store_dict(airing_best, waifu, value) store_dict(airing_popular, waifu, value)
# Get the instance of the bot # Get the instance of the bot
bot = ctx.guild.get_member(self.bot.user.id) bot = ctx.guild.get_member(self.bot.user.id)
# Send the menu to the display # Send the menu to the display
menu = HelpMenu(i, airing_best, "waifu", self.bot, bot) menu = HelpMenu(i, airing_popular, "waifu", self.bot, bot)
await menu.start(ctx) await menu.start(ctx)
@airing.command(name="best") @airing.command(name="best")
@ -292,24 +322,8 @@ class Anime(Cog):
# Local Variable i to allow the pages to be modified # Local Variable i to allow the pages to be modified
i = 0 i = 0
airing_best = {} airing_best = {}
url = "https://mywaifulist.moe/api/v1/airing/best" best_waifus = await get_airing_api(self, "airing/best")
data = {'content-type': "application/json"}
# Searching API for the current airing shows
async with aiohttp.ClientSession() as session:
async with session.get(url, data=data, headers=self.headers) as resp:
# Store waifu's in dict when request is successful, else send an error
if resp.status == 200:
best_waifus = await resp.json()
# Send error if something went wrong internally/while grabbing data from API
else:
await self.bot.generate_embed(ctx, desc="**Something went wrong with MyWaifuList!**")
# Close session
await session.close()
# Store all the shows with the name as the key # Store all the shows with the name as the key
for waifu in best_waifus["data"]: for waifu in best_waifus["data"]:
@ -331,36 +345,20 @@ class Anime(Cog):
# Local Variable i to allow the pages to be modified # Local Variable i to allow the pages to be modified
i = 0 i = 0
anime_dict = {}
shows_dict = {} animes = await get_airing_api(self, "airing")
url = "https://mywaifulist.moe/api/v1/airing"
data = {'content-type': "application/json"}
# Searching API for the current airing shows
async with aiohttp.ClientSession() as session:
async with session.get(url, data=data, headers=self.headers) as resp:
# Store waifu's in dict when request is successful, else send an error
if resp.status == 200:
show_dict = await resp.json()
# Send error if something went wrong internally/while grabbing data from API
else:
await self.bot.generate_embed(ctx, desc="**Something went wrong with MyWaifuList!**")
# Close session
await session.close()
# Store all the shows with the name as the key # Store all the shows with the name as the key
for show in show_dict["data"]: for show in animes["data"]:
shows_dict[show["name"]] = {} anime_dict[show["name"]] = {}
for value in show: for value in show:
store_dict(shows_dict, show, value) store_dict(anime_dict, show, value)
# Get the instance of the bot # Get the instance of the bot
bot = ctx.guild.get_member(self.bot.user.id) bot = ctx.guild.get_member(self.bot.user.id)
# Send the menu to the display # Send the menu to the display
menu = HelpMenu(i, shows_dict, "anime", self.bot, bot) menu = HelpMenu(i, anime_dict, "anime", self.bot, bot)
await menu.start(ctx) await menu.start(ctx)
@command(name="search", aliases=["lookup"], usage="`<waifu|anime>`") @command(name="search", aliases=["lookup"], usage="`<waifu|anime>`")

Loading…
Cancel
Save