Added currently airing shows onto the commands

pull/8/head
sgoudham 4 years ago
parent d19eef4369
commit da10f47aea

@ -23,22 +23,25 @@ from discord.ext.commands import Cog, group, bot_has_permissions
my_waifu_list_auth = config('MYWAIFULIST_AUTH') my_waifu_list_auth = config('MYWAIFULIST_AUTH')
def store_waifus(waifus_dict, waifu, 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"""
waifus_dict[waifu["name"]][value] = waifu[value] dict_[key["name"]][value] = key[value]
def multiple_waifu_generator(self, bot): def multiple_dict_generator(self, bot):
"""Method to generate embed of multiple waifu's""" """Method to generate embed of multiple waifu's"""
embeds = [] embeds = []
for key in self.waifus_dict.values(): for key in self._dict.values():
embed = Embed(title=key["name"], description=f"{key['original_name']} | {key['type']}", embed = Embed(title=key["name"], description=f"{key['original_name']} | {key['type']}",
colour=bot.random_colour(), colour=bot.random_colour(),
url=key["url"]) url=key["url"])
embed.set_image(url=key["display_picture"]) embed.set_image(url=key["display_picture"])
embed.set_footer(text=f"❤️ {key['likes']} 🗑️ {key['trash']} | Powered by MyWaifuList") if "waifu" == self.type:
embed.set_footer(text=f"❤️ {key['likes']} 🗑️ {key['trash']} | Powered by MyWaifuList")
elif "show" == self.type:
embed.set_footer(text=f"{key['romaji_name']} | Powered by MyWaifuList")
embeds.append(embed) embeds.append(embed)
@ -69,23 +72,24 @@ def single_waifu_generator(self, waifu):
# Set up the Cog # Set up the Cog
class HelpMenu(menus.Menu): class HelpMenu(menus.Menu):
def __init__(self, i, waifu, bot, guild_bot): def __init__(self, i, _dict, _type, bot, guild_bot):
super().__init__(timeout=125.0, clear_reactions_after=True) super().__init__(timeout=125.0, clear_reactions_after=True)
self.waifus_dict = waifu self._dict = _dict
self.type = _type
self.i = i self.i = i
self.bot = bot self.bot = bot
self.waifu = multiple_waifu_generator(self, bot) self.dicts = multiple_dict_generator(self, bot)
self.guild_bot = guild_bot self.guild_bot = guild_bot
# Message to be sent on the initial command ~help # Message to be sent on the initial command ~help
async def send_initial_message(self, ctx, channel): async def send_initial_message(self, ctx, channel):
# Set the first embed to the first element in the pages[] # Set the first embed to the first element in the pages[]
initial = self.waifu[self.i] initial = self.dicts[self.i]
cur_page = self.i + 1 cur_page = self.i + 1
pages = len(self.waifu) pages = len(self.dicts)
initial.set_author(name=f"Page {cur_page}/{pages}") initial.set_author(name=f"Airing Shows | Page {cur_page}/{pages}")
# Send embed # Send embed
return await channel.send(embed=initial) return await channel.send(embed=initial)
@ -101,12 +105,12 @@ class HelpMenu(menus.Menu):
# Do nothing if the check does not return true # Do nothing if the check does not return true
if check(self.ctx): if check(self.ctx):
# Set self.i to (i - 1) remainder length of the array # Set self.i to (i - 1) remainder length of the array
self.i = (self.i - 1) % len(self.waifu) self.i = (self.i - 1) % len(self.dicts)
prev_page = self.waifu[self.i] prev_page = self.dicts[self.i]
cur_page = self.i + 1 cur_page = self.i + 1
pages = len(self.waifu) pages = len(self.dicts)
prev_page.set_author(name=f"Page {cur_page}/{pages}") prev_page.set_author(name=f"Airing Shows | Page {cur_page}/{pages}")
# Send the embed and remove the reaction of the user # Send the embed and remove the reaction of the user
await self.message.edit(embed=prev_page) await self.message.edit(embed=prev_page)
@ -124,12 +128,12 @@ class HelpMenu(menus.Menu):
# Do nothing if the check does not return true # Do nothing if the check does not return true
if check(self.ctx): if check(self.ctx):
# Set self.i to (i + 1) remainder length of the array # Set self.i to (i + 1) remainder length of the array
self.i = (self.i + 1) % len(self.waifu) self.i = (self.i + 1) % len(self.dicts)
next_page = self.waifu[self.i] next_page = self.dicts[self.i]
cur_page = self.i + 1 cur_page = self.i + 1
pages = len(self.waifu) pages = len(self.dicts)
next_page.set_author(name=f"Page {cur_page}/{pages}") next_page.set_author(name=f"Airing Shows | Page {cur_page}/{pages}")
# Send the embed and remove the reaction of the user # Send the embed and remove the reaction of the user
await self.message.edit(embed=next_page) await self.message.edit(embed=next_page)
@ -162,6 +166,51 @@ class Anime(Cog):
"""Printing out that Cog is ready on startup""" """Printing out that Cog is ready on startup"""
print(f"{self.__class__.__name__} Cog has been loaded!\n-----") print(f"{self.__class__.__name__} Cog has been loaded!\n-----")
@group(name="airing", invoke_without_command=True, case_insensitive=True)
@bot_has_permissions(embed_links=True, add_reactions=True)
async def airing_shows(self, ctx):
"""
Show's statiscs about airing shows and waifus
(UNDER CONSTRUCTION)
"""
pass
@airing_shows.command(name="shows", aliases=["currently", "current"])
@bot_has_permissions(embed_links=True, add_reactions=True)
async def shows(self, ctx):
"""Display the current airing shows"""
# Local Variable i to allow the index of the pages[] to be modified
i = 0
shows_dict = {}
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!**")
# Store all the shows with the name as the key
for show in show_dict["data"]:
shows_dict[show["name"]] = {}
for value in show:
store_dict(shows_dict, show, value)
# Get the instance of the bot
bot = ctx.guild.get_member(self.bot.user.id)
# Send the menu to the display
menu = HelpMenu(i, shows_dict, "show", self.bot, bot)
await menu.start(ctx)
@group(name="waifu", invoke_without_command=True, case_insensitive=True) @group(name="waifu", invoke_without_command=True, case_insensitive=True)
@bot_has_permissions(embed_links=True, add_reactions=True) @bot_has_permissions(embed_links=True, add_reactions=True)
async def waifu(self, ctx, *, name: str): async def waifu(self, ctx, *, name: str):
@ -198,7 +247,7 @@ class Anime(Cog):
if waifu["type"] in ["Waifu", "Husbando"]: if waifu["type"] in ["Waifu", "Husbando"]:
waifus_dict[waifu["name"]] = {} waifus_dict[waifu["name"]] = {}
for value in waifu: for value in waifu:
store_waifus(waifus_dict, waifu, value) store_dict(waifus_dict, waifu, value)
else: else:
break break
@ -212,7 +261,7 @@ class Anime(Cog):
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, waifus_dict, self.bot, bot) menu = HelpMenu(i, waifus_dict, "waifu", self.bot, bot)
await menu.start(ctx) await menu.start(ctx)
@waifu.command(name="daily") @waifu.command(name="daily")

Loading…
Cancel
Save