Added commentary for instagram command

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

@ -346,56 +346,66 @@ class Fun(Cog):
async def insta_info(self, ctx, *, user_name): async def insta_info(self, ctx, *, user_name):
"""Retrieve a persons Instagram profile information""" """Retrieve a persons Instagram profile information"""
url = f"https://apis.duncte123.me/insta/{user_name}" with ctx.typing():
async with aiohttp.ClientSession() as session: # Request profile information from API
async with await session.get(url=url) as response: url = f"https://apis.duncte123.me/insta/{user_name}"
if response.status == 200: async with aiohttp.ClientSession() as session:
insta = await response.json() async with await session.get(url=url) as response:
data = insta["user"]
images = insta["images"] # When succesful, read data from json
private = data["is_private"] if response.status == 200:
verified = data["is_verified"] insta = await response.json()
if not private:
image_url = images[0]["url"] data = insta["user"]
image_caption = images[0]["caption"] images = insta["images"]
private = data["is_private"]
full_name = data["full_name"] verified = data["is_verified"]
username = data["username"]
pfp = data["profile_pic_url"] full_name = data["full_name"]
username = data["username"]
followers = data["followers"]["count"] pfp = data["profile_pic_url"]
following = data["following"]["count"]
uploads = data["uploads"]["count"] followers = data["followers"]["count"]
biography = data["biography"] following = data["following"]["count"]
uploads = data["uploads"]["count"]
elif response.status == 422: biography = data["biography"]
await self.bot.generate_embed(ctx, desc="**Instagram Username Not Found!**")
return # When profile isn't private, grab the information of their last post
if not private:
# Setting bools to ticks/cross emojis image_url = images[0]["url"]
verif = self.bot.tick if verified else self.bot.cross image_caption = images[0]["caption"]
priv = self.bot.tick if private else self.bot.cross
# Send error if no instagram profile was found with given username
page_url = images[0]["page_url"] if not private else f"https://www.instagram.com/{username}/" elif response.status == 422:
await self.bot.generate_embed(ctx, desc="**Instagram Username Not Found!**")
desc = f"**Full Name:** {full_name}" \ return
f"\n**Bio:** {biography}" \
f"\n\n**Verified?:** {verif} | **Private?:** {priv}" \ # Setting bools to ticks/cross emojis
f"\n**Following:** {following} | **Followers:** {followers}" \ verif = self.bot.tick if verified else self.bot.cross
f"\n**Upload Count:** {uploads}" priv = self.bot.tick if private else self.bot.cross
embed = discord.Embed(title=f"{username}'s Instagram",
description=desc, # Set the page url to the last post or the profile based on privacy settings
url=page_url, page_url = images[0]["page_url"] if not private else f"https://www.instagram.com/{username}/"
colour=self.bot.random_colour(),
timestamp=datetime.datetime.utcnow()) desc = f"**Full Name:** {full_name}" \
embed.set_thumbnail(url=pfp) f"\n**Bio:** {biography}" \
embed.set_footer(text=f"Requested By {ctx.author}", icon_url=ctx.author.avatar_url) f"\n\n**Verified?:** {verif} | **Private?:** {priv}" \
f"\n**Following:** {following} | **Followers:** {followers}" \
if not private: f"\n**Upload Count:** {uploads}"
embed.add_field(name="My Latest Post", embed = discord.Embed(title=f"{username}'s Instagram",
value=f"**Caption:** {image_caption}", description=desc,
inline=False) url=page_url,
embed.set_image(url=image_url) colour=self.bot.random_colour(),
timestamp=datetime.datetime.utcnow())
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}",
inline=False)
embed.set_image(url=image_url)
await ctx.send(embed=embed) await ctx.send(embed=embed)

Loading…
Cancel
Save