|
|
@ -13,6 +13,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
import asyncio
|
|
|
|
import datetime
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
|
@ -53,56 +54,33 @@ def store_in_dict(_dict, api):
|
|
|
|
store_dict(_dict, item, value)
|
|
|
|
store_dict(_dict, item, value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_waifu_api(self, ctx, url):
|
|
|
|
def store_dict(dict_, key, value):
|
|
|
|
"""Retreiving information about daily/random waifu's"""
|
|
|
|
"""Method to store waifu's in the new dict"""
|
|
|
|
|
|
|
|
|
|
|
|
url = f"https://mywaifulist.moe/api/v1/meta/{url}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Retrieve random or daily waifu from API
|
|
|
|
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
|
|
|
|
async with session.get(url, headers=self.headers) as resp:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Store waifu's in dict when request is successful, else send an error
|
|
|
|
|
|
|
|
if resp.status == 200:
|
|
|
|
|
|
|
|
waifu_dict = await resp.json()
|
|
|
|
|
|
|
|
waifu = waifu_dict["data"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 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!**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await session.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return waifu
|
|
|
|
dict_[key["name"]][value] = key[value]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_airing_api(self, ctx, url):
|
|
|
|
async def get_from_api(self, ctx, url):
|
|
|
|
"""Retreiving information about the airing shows/waifus"""
|
|
|
|
"""Retrieving data from API"""
|
|
|
|
|
|
|
|
|
|
|
|
url = f"https://mywaifulist.moe/api/v1/{url}"
|
|
|
|
url = f"https://mywaifulist.moe/api/v1/{url}"
|
|
|
|
data = {'content-type': "application/json"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Searching API for the current airing shows
|
|
|
|
# Retrieve random or daily waifu from API
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
async with session.get(url, data=data, headers=self.headers) as resp:
|
|
|
|
async with session.get(url, headers=self.headers) as resp:
|
|
|
|
|
|
|
|
|
|
|
|
# Store waifu's in dict when request is successful, else send an error
|
|
|
|
# Store waifu's in dict when request is successful, else send an error
|
|
|
|
if resp.status == 200:
|
|
|
|
if resp.status == 200:
|
|
|
|
airing = await resp.json()
|
|
|
|
api_dict = await resp.json()
|
|
|
|
|
|
|
|
_dict = api_dict["data"]
|
|
|
|
|
|
|
|
|
|
|
|
# Send error if something went wrong internally/while grabbing data from API
|
|
|
|
# Send error if something went wrong internally/while grabbing data from API
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await self.bot.generate_embed(ctx, desc="**Something went wrong with MyWaifuList!**")
|
|
|
|
await self.bot.generate_embed(ctx, desc="**Something went wrong with MyWaifuList!**")
|
|
|
|
|
|
|
|
|
|
|
|
# Close session
|
|
|
|
|
|
|
|
await session.close()
|
|
|
|
await session.close()
|
|
|
|
|
|
|
|
|
|
|
|
return airing
|
|
|
|
return _dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def store_dict(dict_, key, value):
|
|
|
|
|
|
|
|
"""Method to store waifu's in the new dict"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dict_[key["name"]][value] = key[value]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def search(self, bot):
|
|
|
|
def search(self, bot):
|
|
|
@ -138,8 +116,8 @@ def search(self, bot):
|
|
|
|
return embeds
|
|
|
|
return embeds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def waifu_embedder(self, waifu, _type):
|
|
|
|
def waifu_embed(self, waifu, _type):
|
|
|
|
"""Method to generate embed of single waifu's"""
|
|
|
|
"""Generate embed of single waifu's"""
|
|
|
|
|
|
|
|
|
|
|
|
# Get all the data to be displayed in the embed
|
|
|
|
# Get all the data to be displayed in the embed
|
|
|
|
name = waifu["name"]
|
|
|
|
name = waifu["name"]
|
|
|
@ -165,6 +143,37 @@ def waifu_embedder(self, waifu, _type):
|
|
|
|
return embed
|
|
|
|
return embed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def user_embed(self, user):
|
|
|
|
|
|
|
|
"""Generate embed of user profile information"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get all the data to be displayed in the embed
|
|
|
|
|
|
|
|
name = user["name"]
|
|
|
|
|
|
|
|
avatar = user["avatar"] if user[
|
|
|
|
|
|
|
|
"avatar"] else "https://media.discordapp.net/attachments/741072426984538122/748586578074664980/DzEZ4UsXgAAcFjN.png?width=423&height=658"
|
|
|
|
|
|
|
|
joined = user["joined"]
|
|
|
|
|
|
|
|
id = user["id"]
|
|
|
|
|
|
|
|
waifus_created = user["waifus_created"]
|
|
|
|
|
|
|
|
waifus_liked = user["waifus_liked"]
|
|
|
|
|
|
|
|
waifus_trashed = user["waifus_trashed"]
|
|
|
|
|
|
|
|
main_love = user["true_love"]
|
|
|
|
|
|
|
|
profile_url = f"https://mywaifulist.moe/user/{id}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
date_time_obj = datetime.datetime.strptime(joined, '%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
|
|
joined_at = date_time_obj.strftime("%a, %b %d, %Y\n%I:%M:%S %p")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
desc = f"**Waifu's Created:** {waifus_created}" \
|
|
|
|
|
|
|
|
f"\n**Waifu's Liked:** {waifus_liked}" \
|
|
|
|
|
|
|
|
f"\n**Waifu's Trashed:** {waifus_trashed}"
|
|
|
|
|
|
|
|
embed = Embed(title=name, description=desc,
|
|
|
|
|
|
|
|
colour=self.bot.random_colour(),
|
|
|
|
|
|
|
|
url=profile_url)
|
|
|
|
|
|
|
|
embed.add_field(name="Joined Date", value=joined_at, inline=False)
|
|
|
|
|
|
|
|
embed.set_thumbnail(url=avatar)
|
|
|
|
|
|
|
|
embed.set_footer(text=f"Internal ID: {id} | Powered by MyWaifuList")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return embed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MWLMenu(menus.Menu):
|
|
|
|
class MWLMenu(menus.Menu):
|
|
|
|
"""Setup menus for MyWaifuList results"""
|
|
|
|
"""Setup menus for MyWaifuList results"""
|
|
|
|
|
|
|
|
|
|
|
@ -445,7 +454,7 @@ class Anime(Cog):
|
|
|
|
# Variables to set up the reaction menu
|
|
|
|
# Variables to set up the reaction menu
|
|
|
|
i = 0
|
|
|
|
i = 0
|
|
|
|
airing_trash = {}
|
|
|
|
airing_trash = {}
|
|
|
|
trash_waifus = await get_airing_api(self, ctx, "airing/trash")
|
|
|
|
trash_waifus = await get_from_api(self, ctx, "airing/trash")
|
|
|
|
store_in_dict(airing_trash, trash_waifus)
|
|
|
|
store_in_dict(airing_trash, trash_waifus)
|
|
|
|
|
|
|
|
|
|
|
|
# Get the instance of the bot
|
|
|
|
# Get the instance of the bot
|
|
|
@ -465,7 +474,7 @@ class Anime(Cog):
|
|
|
|
# Variables to setup the reaction menu
|
|
|
|
# Variables to setup the reaction menu
|
|
|
|
i = 0
|
|
|
|
i = 0
|
|
|
|
airing_popular = {}
|
|
|
|
airing_popular = {}
|
|
|
|
popular_waifus = await get_airing_api(self, ctx, "airing/popular")
|
|
|
|
popular_waifus = await get_from_api(self, ctx, "airing/popular")
|
|
|
|
store_in_dict(airing_popular, popular_waifus)
|
|
|
|
store_in_dict(airing_popular, popular_waifus)
|
|
|
|
|
|
|
|
|
|
|
|
# Get the instance of the bot
|
|
|
|
# Get the instance of the bot
|
|
|
@ -485,7 +494,7 @@ 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 = {}
|
|
|
|
best_waifus = await get_airing_api(self, ctx, "airing/best")
|
|
|
|
best_waifus = await get_from_api(self, ctx, "airing/best")
|
|
|
|
store_in_dict(airing_best, best_waifus)
|
|
|
|
store_in_dict(airing_best, best_waifus)
|
|
|
|
|
|
|
|
|
|
|
|
# Get the instance of the bot
|
|
|
|
# Get the instance of the bot
|
|
|
@ -505,7 +514,7 @@ 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 = {}
|
|
|
|
anime_dict = {}
|
|
|
|
animes = await get_airing_api(self, ctx, "airing")
|
|
|
|
animes = await get_from_api(self, ctx, "airing")
|
|
|
|
store_in_dict(anime_dict, animes)
|
|
|
|
store_in_dict(anime_dict, animes)
|
|
|
|
|
|
|
|
|
|
|
|
# Get the instance of the bot
|
|
|
|
# Get the instance of the bot
|
|
|
@ -582,22 +591,25 @@ class Anime(Cog):
|
|
|
|
async def daily_waifu(self, ctx):
|
|
|
|
async def daily_waifu(self, ctx):
|
|
|
|
"""Returns the Daily Waifu from MyWaifuList"""
|
|
|
|
"""Returns the Daily Waifu from MyWaifuList"""
|
|
|
|
|
|
|
|
|
|
|
|
waifu = await get_waifu_api(self, ctx, "daily")
|
|
|
|
waifu = await get_from_api(self, ctx, "meta/daily")
|
|
|
|
await ctx.send(embed=waifu_embedder(self, waifu, "daily"))
|
|
|
|
await ctx.send(embed=waifu_embed(self, waifu, "daily"))
|
|
|
|
|
|
|
|
|
|
|
|
@waifu.command(name="random", aliases=["rnd"])
|
|
|
|
@waifu.command(name="random", aliases=["rnd"])
|
|
|
|
@bot_has_permissions(embed_links=True)
|
|
|
|
@bot_has_permissions(embed_links=True)
|
|
|
|
async def random_waifu(self, ctx):
|
|
|
|
async def random_waifu(self, ctx):
|
|
|
|
"""Returning a Random Waifu from MyWaifuList"""
|
|
|
|
"""Returning a Random Waifu from MyWaifuList"""
|
|
|
|
|
|
|
|
|
|
|
|
waifu = await get_waifu_api(self, ctx, "random")
|
|
|
|
waifu = await get_from_api(self, ctx, "meta/random")
|
|
|
|
await ctx.send(embed=waifu_embedder(self, waifu, "random"))
|
|
|
|
await ctx.send(embed=waifu_embed(self, waifu, "random"))
|
|
|
|
|
|
|
|
|
|
|
|
@group(name="profile", aliases=["user"], invoke_without_command=True, case_insensitive=True)
|
|
|
|
@group(name="profile", aliases=["user"], invoke_without_command=True, case_insensitive=True)
|
|
|
|
@bot_has_permissions(embed_links=True)
|
|
|
|
@bot_has_permissions(embed_links=True)
|
|
|
|
async def mwl_user_profile(self, ctx):
|
|
|
|
async def mwl_user_profile(self, ctx, term: int):
|
|
|
|
"""Returning the MWL User Profile requested"""
|
|
|
|
"""Returning the MWL User Profile requested"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user = await get_from_api(self, ctx, f"user/{term}")
|
|
|
|
|
|
|
|
await ctx.send(embed=user_embed(self, user))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setup(bot):
|
|
|
|
def setup(bot):
|
|
|
|
bot.add_cog(Anime(bot))
|
|
|
|
bot.add_cog(Anime(bot))
|
|
|
|