Added commentary for instagram command

pull/8/head
sgoudham 4 years ago
parent 14a51710ed
commit 58a5756f4d

@ -346,18 +346,20 @@ class Fun(Cog):
async def insta_info(self, ctx, *, user_name):
"""Retrieve a persons Instagram profile information"""
with ctx.typing():
# Request profile information from API
url = f"https://apis.duncte123.me/insta/{user_name}"
async with aiohttp.ClientSession() as session:
async with await session.get(url=url) as response:
# When succesful, read data from json
if response.status == 200:
insta = await response.json()
data = insta["user"]
images = insta["images"]
private = data["is_private"]
verified = data["is_verified"]
if not private:
image_url = images[0]["url"]
image_caption = images[0]["caption"]
full_name = data["full_name"]
username = data["username"]
@ -368,6 +370,12 @@ class Fun(Cog):
uploads = data["uploads"]["count"]
biography = data["biography"]
# When profile isn't private, grab the information of their last post
if not private:
image_url = images[0]["url"]
image_caption = images[0]["caption"]
# Send error if no instagram profile was found with given username
elif response.status == 422:
await self.bot.generate_embed(ctx, desc="**Instagram Username Not Found!**")
return
@ -376,6 +384,7 @@ class Fun(Cog):
verif = self.bot.tick if verified else self.bot.cross
priv = self.bot.tick if private else self.bot.cross
# Set the page url to the last post or the profile based on privacy settings
page_url = images[0]["page_url"] if not private else f"https://www.instagram.com/{username}/"
desc = f"**Full Name:** {full_name}" \
@ -391,6 +400,7 @@ class Fun(Cog):
embed.set_thumbnail(url=pfp)
embed.set_footer(text=f"Requested By {ctx.author}", icon_url=ctx.author.avatar_url)
# When profile is not private, display the last post with the caption
if not private:
embed.add_field(name="My Latest Post",
value=f"**Caption:** {image_caption}",

Loading…
Cancel
Save