Merge pull request #8 from sgoudham/alpha

User Profile Command For MWL
pull/9/head
Hamothy 4 years ago committed by GitHub
commit 0380d7791d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,6 +23,8 @@ from discord import Embed
from discord.ext import menus from discord.ext import menus
from discord.ext.commands import Cog, group, bot_has_permissions, command from discord.ext.commands import Cog, group, bot_has_permissions, command
from bot.libs.paginator import SimpleMenu
my_waifu_list_auth = config('MYWAIFULIST_AUTH') my_waifu_list_auth = config('MYWAIFULIST_AUTH')
@ -48,10 +50,13 @@ def store_in_dict(_dict, api):
"""Store the waifu data in dicts""" """Store the waifu data in dicts"""
# Store all the shows with the name as the key # Store all the shows with the name as the key
for item in api: try:
_dict[item["name"]] = {} for item in api:
for value in item: _dict[item["name"]] = {}
store_dict(_dict, item, value) for value in item:
store_dict(_dict, item, value)
except Exception as e:
print(e)
def store_dict(dict_, key, value): def store_dict(dict_, key, value):
@ -145,9 +150,89 @@ def waifu_embed(self, waifu, _type):
return embed return embed
def user_embed(self, user): async def detailed_waifu_embed(self, waifu, author, ctx):
"""Generate embed of single waifu's (detailed)"""
not_found = "https://media.discordapp.net/attachments/741072426984538122/748586578074664980/DzEZ4UsXgAAcFjN.png?width=423&height=658"
# Get all the data to be displayed in the embed
name = waifu["name"]
waifu_id = waifu["id"]
og_name = waifu["original_name"]
romaji_name = waifu["romaji_name"]
picture = waifu["display_picture"]
url = waifu["url"]
age = waifu["age"]
b_day = waifu["birthday_day"]
b_month = waifu["birthday_month"]
b_year = waifu["birthday_year"]
popularity_rank = waifu["popularity_rank"]
like_rank = waifu["like_rank"]
trash_rank = waifu["trash_rank"]
likes = waifu["likes"]
trash = waifu["trash"]
height = waifu["height"]
weight = waifu["weight"]
waist = waifu["waist"]
bust = waifu["bust"]
hip = waifu["hip"]
# Only setting up description if waifu og_name has a value
desc = f"**Original Name:** {og_name}\n" if og_name else f"**Original Name:** {self.bot.cross}\n"
desc += f"**Romaji Name:** {romaji_name}\n" if romaji_name else f"**Romaji Name:** {self.bot.cross}\n"
desc += f"\n**Age:** {age}\n" if age else f"**Age:** {self.bot.cross}\n"
desc += f"**Birthday-Day:** {b_day}\n" if b_day else f"**Birthday-Day:** {self.bot.cross}\n"
desc += f"**Birthday-Month:** {b_month}\n" if b_month else f"**Birthday-Month:** {self.bot.cross}\n"
desc += f"**Birthday-Year:** {b_year}\n" if b_year else f"**Birthday-Year:** {self.bot.cross}\n"
height = f"**Height:** {height}cm" if height else f"**Height:** {self.bot.cross}"
weight = f"**Weight:** {weight}kg" if weight else f"**Weight:** {self.bot.cross}"
waist = f"**Waist:** {waist}cm" if waist else f"**Waist:** {self.bot.cross}"
bust = f"**Bust:** {bust}cm" if bust else f"**Bust:** {self.bot.cross}"
hip = f"**Hip:** {hip}cm" if hip else f"**Hip:** {self.bot.cross}"
fields = [("Measurements",
f"{height}"
f"\n{weight}"
f"\n{waist}"
f"\n{bust}"
f"\n{hip}", True),
("Ranks",
f"**Popularity Rank:** {popularity_rank}"
f"\n**Like Rank:** {like_rank}"
f"\n**Trash Rank:** {trash_rank}", True)]
# Only using image if it can be displayed, else display 404 image
picture_url = picture if picture.endswith((".jpeg", ".png", ".jpg")) else not_found
detailed = Embed(title=f"True Love | {name}", description=desc,
colour=self.bot.random_colour(),
url=url)
detailed.set_author(name=f"Internal True Love ID: {waifu_id}")
detailed.set_image(url=picture_url)
detailed.set_footer(text=f"❤️ {likes} 🗑️ {trash} | Powered by MyWaifuList")
# Add fields to the embed
for name, value, inline in fields:
detailed.add_field(name=name, value=value, inline=inline)
# Get the permissions of the channel
perms = ctx.guild.me.permissions_in(ctx.message.channel)
menu = SimpleMenu(0, "MyWaifuList User Information", perms, [author, detailed], self)
await menu.start(ctx)
async def user_embed(self, user, ctx):
"""Generate embed of user profile information""" """Generate embed of user profile information"""
love = False
# Get all the data to be displayed in the embed # Get all the data to be displayed in the embed
name = user["name"] name = user["name"]
avatar = user["avatar"] if user[ avatar = user["avatar"] if user[
@ -166,14 +251,23 @@ def user_embed(self, user):
desc = f"**Waifu's Created:** {waifus_created}" \ desc = f"**Waifu's Created:** {waifus_created}" \
f"\n**Waifu's Liked:** {waifus_liked}" \ f"\n**Waifu's Liked:** {waifus_liked}" \
f"\n**Waifu's Trashed:** {waifus_trashed}" f"\n**Waifu's Trashed:** {waifus_trashed}"
embed = Embed(title=name, description=desc, author = Embed(title=name, description=desc,
colour=self.bot.random_colour(), colour=self.bot.random_colour(),
url=profile_url) url=profile_url)
embed.add_field(name="Joined Date", value=joined_at, inline=False) author.add_field(name="Joined Date", value=joined_at, inline=False)
embed.set_thumbnail(url=avatar) author.set_thumbnail(url=avatar)
embed.set_footer(text=f"Internal ID: {id} | Powered by MyWaifuList") author.set_footer(text=f"Internal User ID: {id} | Powered by MyWaifuList")
if main_love["slug"]:
love = True
slug = main_love["slug"]
# Get true love details from the API
true_love = await get_from_api(self, ctx, f"waifu/{slug}")
await detailed_waifu_embed(self, true_love, author, ctx)
return author, love
return embed
def true_love_embed(): def true_love_embed():
"""Generate embed for profile with true love information""" """Generate embed for profile with true love information"""
@ -397,7 +491,7 @@ class MWLMenu(menus.Menu):
('\N{BLACK RIGHT-POINTING TRIANGLE}', "Takes You To The Next Page"), ('\N{BLACK RIGHT-POINTING TRIANGLE}', "Takes You To The Next Page"),
('\N{BLACK RIGHT-POINTING DOUBLE TRIANGLE WITH VERTICAL BAR}', "Takes You To The Last Page"), ('\N{BLACK RIGHT-POINTING DOUBLE TRIANGLE WITH VERTICAL BAR}', "Takes You To The Last Page"),
('\N{INPUT SYMBOL FOR NUMBERS}', "Enter Page Number To Go To"), ('\N{INPUT SYMBOL FOR NUMBERS}', "Enter Page Number To Go To"),
('\N{INFORMATION SOURCE}', "Show's This Message"), ('\N{INFORMATION SOURCE}', "Shows This Message"),
('\N{BLACK SQUARE FOR STOP}', "Closes The Pagination Session") ('\N{BLACK SQUARE FOR STOP}', "Closes The Pagination Session")
] ]
@ -613,7 +707,9 @@ class Anime(Cog):
"""Returning the MWL User Profile requested""" """Returning the MWL User Profile requested"""
user = await get_from_api(self, ctx, f"user/{term}") user = await get_from_api(self, ctx, f"user/{term}")
await ctx.send(embed=user_embed(self, user)) embed, love = await user_embed(self, user, ctx)
if not love:
await ctx.send(embed=embed)
def setup(bot): def setup(bot):

@ -16,7 +16,7 @@
import datetime import datetime
from datetime import timedelta from datetime import timedelta
from typing import Optional from typing import Optional, Union
import discord import discord
from discord import Member, Embed, DMChannel, NotFound from discord import Member, Embed, DMChannel, NotFound
@ -35,9 +35,7 @@ async def send_to_modlogs(self, ctx, target, reason, action):
""" """
# Get the channel of the modlog within the guild # Get the channel of the modlog within the guild
modlog = self.bot.get_modlog_for_guild(ctx.guild.id) if modlog := self.bot.get_modlog_for_guild(ctx.guild.id):
if modlog:
channel = ctx.guild.get_channel(modlog) channel = ctx.guild.get_channel(modlog)
@ -344,7 +342,7 @@ class Moderation(Cog):
with ctx.typing(): with ctx.typing():
await ban_members(self, ctx, members, reason) await ban_members(self, ctx, members, reason)
@command(name="forceban", aliases=["powerban", "ultraban"], usage="`<member>...` `[reason]`") @command(name="force", aliases=["powerban", "ultraban"], usage="`<member>...` `[reason]`")
@guild_only() @guild_only()
@has_guild_permissions(ban_members=True) @has_guild_permissions(ban_members=True)
@bot_has_guild_permissions(ban_members=True) @bot_has_guild_permissions(ban_members=True)
@ -367,27 +365,7 @@ class Moderation(Cog):
# Send confirmation to the channel that the user is in # Send confirmation to the channel that the user is in
await self.bot.generate_embed(ctx, desc=f"✅ **{target}** Was Power Banned! ✅") await self.bot.generate_embed(ctx, desc=f"✅ **{target}** Was Power Banned! ✅")
# Get the channel of the modlog within the guild await send_to_modlogs(self, ctx, target, reason, action="Power Banned")
modlog = self.bot.get_modlog_for_guild(ctx.guild.id)
if modlog:
channel = ctx.guild.get_channel(modlog)
embed = Embed(title=f"User Power Banned",
colour=self.bot.admin_colour,
timestamp=datetime.datetime.utcnow())
embed.set_thumbnail(url=target.avatar_url)
fields = [("User ID", target, False),
("Actioned by", ctx.author.mention, False),
("Reason", reason, False)]
for name, value, inline in fields:
embed.add_field(name=name, value=value, inline=inline)
await channel.send(embed=embed)
@command(name="unban", usage="`<member>...` `[reason]`") @command(name="unban", usage="`<member>...` `[reason]`")
@guild_only() @guild_only()

Loading…
Cancel
Save