Waifu search is it's own command

pull/8/head
sgoudham 4 years ago
parent 76956f3e3f
commit ed031d689c

@ -14,8 +14,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from typing import Optional
import aiohttp import aiohttp
from decouple import config from decouple import config
from discord import Embed from discord import Embed
@ -166,7 +164,7 @@ class Anime(Cog):
@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, *, waifu2: Optional[str] = None): async def waifu(self, ctx, *, name: str):
""" """
Shows a Waifu (UNDER CONSTRUCTION) Shows a Waifu (UNDER CONSTRUCTION)
Waifu's are grabbed from mywaifulist.com Waifu's are grabbed from mywaifulist.com
@ -175,48 +173,47 @@ class Anime(Cog):
# Local Variable i to allow the index of the pages[] to be modified # Local Variable i to allow the index of the pages[] to be modified
i = 0 i = 0
# When a waifu has been specified, retrieve waifu(s) matching the user input waifus_dict = {}
if waifu2: url = "https://mywaifulist.moe/api/v1/search/"
data = {"term": name,
waifus_dict = {} 'content-type': "application/json"}
url = "https://mywaifulist.moe/api/v1/search/"
data = {"term": waifu2, # Searching API for waifu(s)
'content-type': "application/json"} async with aiohttp.ClientSession() as session:
async with session.post(url, data=data, headers=self.headers) as resp:
# Searching API for waifu(s) # Store waifu's in dict when request is successful, else send an error
async with aiohttp.ClientSession() as session: if resp.status == 200:
async with session.post(url, data=data, headers=self.headers) as resp: waifu_dict = await resp.json()
# Store waifu's in dict when request is successful, else send an error
if resp.status == 200: # Send error if something went wrong internally/while grabbing data from API
waifu_dict = await resp.json() else:
await self.bot.generate_embed(ctx, desc="**Something went wrong!**")
# Send error if something went wrong internally/while grabbing data from API
else: # As long waifu's were returned from the GET request
await self.bot.generate_embed(ctx, desc="**Something went wrong!**") # Store waifus in a dict
if len(waifu_dict["data"]) > 0:
# As long waifu's were returned from the GET request for waifu in waifu_dict["data"]:
# Store waifus in a dict
if len(waifu_dict["data"]) > 0: # Only store "Waifu's" and "Husbando's"
for waifu in waifu_dict["data"]: if waifu["type"] in ["Waifu", "Husbando"]:
waifus_dict[waifu["name"]] = {}
# Only store "Waifu's" and "Husbando's" for value in waifu:
if waifu["type"] in ["Waifu", "Husbando"]: store_waifus(waifus_dict, waifu, value)
waifus_dict[waifu["name"]] = {}
for value in waifu: else:
store_waifus(waifus_dict, waifu, value) break
else:
break # When no waifu has been retrieved, send error message to the user
else:
# When no waifu has been retrieved, send error message to the user
else: await self.bot.generate_embed(ctx, desc="**Waifu Not Found!**")
await self.bot.generate_embed(ctx, desc="**Waifu Not Found!**")
# 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, waifus_dict, self.bot, bot)
menu = HelpMenu(i, waifus_dict, self.bot, bot) await menu.start(ctx)
await menu.start(ctx)
@waifu.command(name="daily") @waifu.command(name="daily")
async def daily_waifu(self, ctx): async def daily_waifu(self, ctx):

Loading…
Cancel
Save