From 0fea1b597c98e5fdde355283bad5a11c46acbbd3 Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Thu, 1 Oct 2020 02:28:20 +0530 Subject: GithubInfo command --- bot/exts/evergreen/githubinfo.py | 88 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 bot/exts/evergreen/githubinfo.py (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py new file mode 100644 index 00000000..fd1ba47f --- /dev/null +++ b/bot/exts/evergreen/githubinfo.py @@ -0,0 +1,88 @@ +import logging +import aiohttp +from datetime import datetime + +import discord +from discord.ext import commands +from discord.ext.commands.cooldowns import BucketType + +log = logging.getLogger(__name__) + + +class GithubInfo(commands.Cog): + + def __init__(self, bot: commands.Bot): + self.bot = bot + + async def fetch_data(self, url: str) -> dict: + """Retrieve data as a dictionary""" + + async with aiohttp.ClientSession() as cs: + async with cs.get(url) as r: + return await r.json() + + @commands.command(name='github', aliases=['gh']) + @commands.cooldown(1, 5, BucketType.user) + async def get_github_info(self, ctx: commands.Context, username: str = 'python-discord') -> None: + """Fetches a user's GitHub information + + User defaults to python-discord + + Usage: .gh [username] + """ + + # fetch user data + user_data = await self.fetch_data(f"https://api.github.com/users/{username}") + + # user_data will not have a message key if the user exists + if user_data.get('message') is not None: + return await ctx.send(embed=discord.Embed(title=f"The profile `{username}` was not found", colour=0xff0022)) + + # fetching organization data and forming the organization string + org_data = await self.fetch_data(user_data['organizations_url']) + + orgs = [f"[{org['login']}](https://github.com/{org['login']})" for org in org_data] + orgs_to_add = ' | '.join(orgs) + + # fetching starred repos data + starred_data = await self.fetch_data(user_data['starred_url']) + + # forming blog link + if user_data['blog'].startswith("http"): # blog link is clickable + blog = f"[Direct link]({user_data['blog']})" + elif user_data['blog']: # blog exists but the link is not clickable + blog = f"[Direct link](https://{user_data['blog']})" + else: # blog does not exist + blog = "No blog link available" + + # building embed + embed = discord.Embed( + title=f"`{user_data['login']}`'s GitHub profile info", + description=f"```{user_data['bio']}```\n" if user_data['bio'] is not None else "", + colour=0xf5faf6, + url=user_data['html_url'], + timestamp=datetime.strptime(user_data['created_at'], "%Y-%m-%dT%H:%M:%SZ") + ) + embed.set_thumbnail(url=user_data['avatar_url']) + embed.set_footer(text="Account created at") + + embed.add_field(name="Followers", value=f"[{user_data['followers']}]{user_data['html_url']}?tab=followers)") + embed.add_field(name="\u200b", value="\u200b") # zero width space + embed.add_field(name="Following", value=f"[{user_data['following']}]{user_data['html_url']}?tab=following)") + + embed.add_field(name="Public repos", + value=f"[{user_data['public_repos']}]{user_data['html_url']}?tab=repositories)") + embed.add_field(name="\u200b", value="\u200b") + embed.add_field(name="Starred repos", value=f"[{len(starred_data)}]{user_data['html_url']}?tab=stars)") + + embed.add_field(name=f"Organization{'s' if len(orgs)!=1 else ''}", + value=orgs_to_add if orgs else "No organizations") + embed.add_field(name="\u200b", value="\u200b") + embed.add_field(name="Blog", value=blog) + + await ctx.send(embed=embed) + + +def setup(bot: commands.Bot) -> None: + """Load the cog""" + bot.add_cog(GithubInfo(bot)) -- cgit v1.2.3 From cd20d5499ee74bccd5280663f374fbfefaeccc17 Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Thu, 1 Oct 2020 09:55:17 +0530 Subject: fixed checks failing by running Installing dependencies from Pipfile.lock (2801e4)… To activate this project's virtualenv, run pipenv shell. Alternatively, run a command inside the virtualenv with pipenv run. All dependencies are now up-to-date! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/exts/evergreen/githubinfo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index fd1ba47f..e2541a23 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -84,5 +84,5 @@ class GithubInfo(commands.Cog): def setup(bot: commands.Bot) -> None: - """Load the cog""" + """Adding the cog to the bot""" bot.add_cog(GithubInfo(bot)) -- cgit v1.2.3 From 7d593edd30d1d14cb367c5896333fa343fe3e6ea Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Thu, 1 Oct 2020 10:08:12 +0530 Subject: fixed issues showing up in Check for merge conflicts................................................Passed Check Toml...............................................................Passed Check Yaml...............................................................Passed Fix End of Files.........................................................Passed Mixed line ending........................................................Passed Trim Trailing Whitespace.................................................Passed check blanket noqa.......................................................Passed Flake8...................................................................Passed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/exts/evergreen/githubinfo.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index e2541a23..46f6d167 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -1,7 +1,7 @@ import logging -import aiohttp from datetime import datetime +import aiohttp import discord from discord.ext import commands from discord.ext.commands.cooldowns import BucketType @@ -10,13 +10,13 @@ log = logging.getLogger(__name__) class GithubInfo(commands.Cog): + """Fetches GitHub.""" def __init__(self, bot: commands.Bot): self.bot = bot async def fetch_data(self, url: str) -> dict: - """Retrieve data as a dictionary""" - + """Retrieve data as a dictionary.""" async with aiohttp.ClientSession() as cs: async with cs.get(url) as r: return await r.json() @@ -24,13 +24,13 @@ class GithubInfo(commands.Cog): @commands.command(name='github', aliases=['gh']) @commands.cooldown(1, 5, BucketType.user) async def get_github_info(self, ctx: commands.Context, username: str = 'python-discord') -> None: - """Fetches a user's GitHub information + """ + Fetches a user's GitHub information. - User defaults to python-discord + User defaults to python-discord. Usage: .gh [username] """ - # fetch user data user_data = await self.fetch_data(f"https://api.github.com/users/{username}") @@ -84,5 +84,5 @@ class GithubInfo(commands.Cog): def setup(bot: commands.Bot) -> None: - """Adding the cog to the bot""" + """Adding the cog to the bot.""" bot.add_cog(GithubInfo(bot)) -- cgit v1.2.3 From 2600a1c541abb8f2470fca2e14c66b628688d0fa Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Fri, 2 Oct 2020 12:37:36 +0530 Subject: implemented requested changes --- bot/exts/evergreen/githubinfo.py | 110 +++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 51 deletions(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index 46f6d167..4935e1de 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -1,5 +1,6 @@ import logging from datetime import datetime +from typing import Optional import aiohttp import discord @@ -10,12 +11,13 @@ log = logging.getLogger(__name__) class GithubInfo(commands.Cog): - """Fetches GitHub.""" + """Fetches info from GitHub.""" def __init__(self, bot: commands.Bot): self.bot = bot - async def fetch_data(self, url: str) -> dict: + @staticmethod + async def fetch_data(url: str) -> dict: """Retrieve data as a dictionary.""" async with aiohttp.ClientSession() as cs: async with cs.get(url) as r: @@ -23,7 +25,7 @@ class GithubInfo(commands.Cog): @commands.command(name='github', aliases=['gh']) @commands.cooldown(1, 5, BucketType.user) - async def get_github_info(self, ctx: commands.Context, username: str = 'python-discord') -> None: + async def get_github_info(self, ctx: commands.Context, username: Optional[str]) -> None: """ Fetches a user's GitHub information. @@ -31,54 +33,60 @@ class GithubInfo(commands.Cog): Usage: .gh [username] """ - # fetch user data - user_data = await self.fetch_data(f"https://api.github.com/users/{username}") - - # user_data will not have a message key if the user exists - if user_data.get('message') is not None: - return await ctx.send(embed=discord.Embed(title=f"The profile `{username}` was not found", colour=0xff0022)) - - # fetching organization data and forming the organization string - org_data = await self.fetch_data(user_data['organizations_url']) - - orgs = [f"[{org['login']}](https://github.com/{org['login']})" for org in org_data] - orgs_to_add = ' | '.join(orgs) - - # fetching starred repos data - starred_data = await self.fetch_data(user_data['starred_url']) - - # forming blog link - if user_data['blog'].startswith("http"): # blog link is clickable - blog = f"[Direct link]({user_data['blog']})" - elif user_data['blog']: # blog exists but the link is not clickable - blog = f"[Direct link](https://{user_data['blog']})" - else: # blog does not exist - blog = "No blog link available" - - # building embed - embed = discord.Embed( - title=f"`{user_data['login']}`'s GitHub profile info", - description=f"```{user_data['bio']}```\n" if user_data['bio'] is not None else "", - colour=0xf5faf6, - url=user_data['html_url'], - timestamp=datetime.strptime(user_data['created_at'], "%Y-%m-%dT%H:%M:%SZ") - ) - embed.set_thumbnail(url=user_data['avatar_url']) - embed.set_footer(text="Account created at") - - embed.add_field(name="Followers", value=f"[{user_data['followers']}]{user_data['html_url']}?tab=followers)") - embed.add_field(name="\u200b", value="\u200b") # zero width space - embed.add_field(name="Following", value=f"[{user_data['following']}]{user_data['html_url']}?tab=following)") - - embed.add_field(name="Public repos", - value=f"[{user_data['public_repos']}]{user_data['html_url']}?tab=repositories)") - embed.add_field(name="\u200b", value="\u200b") - embed.add_field(name="Starred repos", value=f"[{len(starred_data)}]{user_data['html_url']}?tab=stars)") - - embed.add_field(name=f"Organization{'s' if len(orgs)!=1 else ''}", - value=orgs_to_add if orgs else "No organizations") - embed.add_field(name="\u200b", value="\u200b") - embed.add_field(name="Blog", value=blog) + + if username is None: + await ctx.invoke(self.bot.get_command('help'), 'github') + return + + async with ctx.typing(): + + user_data = await self.fetch_data(f"https://api.github.com/users/{username}") + + # user_data will not have a message key if the user exists + if user_data.get('message') is not None: + await ctx.send(embed=discord.Embed(title=f"The profile for `{username}` was not found.", + colour=0xff0022)) + return + + org_data = await self.fetch_data(user_data['organizations_url']) + orgs = [f"[{org['login']}](https://github.com/{org['login']})" for org in org_data] + orgs_to_add = ' | '.join(orgs) + + starred_data = await self.fetch_data(user_data['starred_url']) + + # Forming blog link + if user_data['blog'].startswith("http"): # Blog link is clickable + blog = f"[Direct link]({user_data['blog']})" + elif user_data['blog']: # Blog exists but the link is not clickable + blog = f"[Direct link](https://{user_data['blog']})" + else: + blog = "No blog link available" + + embed = discord.Embed( + title=f"`{user_data['login']}`'s GitHub profile info", + description=f"```{user_data['bio']}```\n" if user_data['bio'] is not None else "", + colour=0xf5faf6, + url=user_data['html_url'], + timestamp=datetime.strptime(user_data['created_at'], "%Y-%m-%dT%H:%M:%SZ") + ) + embed.set_thumbnail(url=user_data['avatar_url']) + embed.set_footer(text="Account created at") + + embed.add_field(name="Followers", value=f"""[{user_data['followers']}] + ({user_data['html_url']}?tab=followers)""") + embed.add_field(name="\u200b", value="\u200b") + embed.add_field(name="Following", value=f"""[{user_data['following']}] + ({user_data['html_url']}?tab=following)""") + + embed.add_field(name="Public repos", + value=f"[{user_data['public_repos']}]({user_data['html_url']}?tab=repositories)") + embed.add_field(name="\u200b", value="\u200b") + embed.add_field(name="Starred repos", value=f"[{len(starred_data)}]({user_data['html_url']}?tab=stars)") + + embed.add_field(name=f"Organization{'s' if len(orgs)!=1 else ''}", + value=orgs_to_add if orgs else "No organizations") + embed.add_field(name="\u200b", value="\u200b") + embed.add_field(name="Blog", value=blog) await ctx.send(embed=embed) -- cgit v1.2.3 From fa1364622c0768186eb5919dd5661c9c64c565a7 Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Fri, 2 Oct 2020 12:42:42 +0530 Subject: linting smh --- bot/exts/evergreen/githubinfo.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index 4935e1de..b7ebcb3e 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -29,11 +29,10 @@ class GithubInfo(commands.Cog): """ Fetches a user's GitHub information. - User defaults to python-discord. + Username is optional and sends the help command if not specified. Usage: .gh [username] """ - if username is None: await ctx.invoke(self.bot.get_command('help'), 'github') return -- cgit v1.2.3 From f7e26fb4d3b8c6869eb4dd8dc8b9ef31ceb8352a Mon Sep 17 00:00:00 2001 From: Lakshya Shastri <62901541+LakshyaShastri@users.noreply.github.com> Date: Sat, 3 Oct 2020 03:46:10 +0530 Subject: final changes --- bot/exts/evergreen/githubinfo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index b7ebcb3e..2a540bac 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -41,7 +41,7 @@ class GithubInfo(commands.Cog): user_data = await self.fetch_data(f"https://api.github.com/users/{username}") - # user_data will not have a message key if the user exists + # User_data will not have a message key if the user exists if user_data.get('message') is not None: await ctx.send(embed=discord.Embed(title=f"The profile for `{username}` was not found.", colour=0xff0022)) @@ -54,9 +54,9 @@ class GithubInfo(commands.Cog): starred_data = await self.fetch_data(user_data['starred_url']) # Forming blog link - if user_data['blog'].startswith("http"): # Blog link is clickable + if user_data['blog'].startswith("http"): # Blog link is complete blog = f"[Direct link]({user_data['blog']})" - elif user_data['blog']: # Blog exists but the link is not clickable + elif user_data['blog']: # Blog exists but the link is not complete blog = f"[Direct link](https://{user_data['blog']})" else: blog = "No blog link available" -- cgit v1.2.3 From 0cc321f5694c0366297f1d46ba160d65853732a9 Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Sat, 3 Oct 2020 13:38:45 +0530 Subject: made code more consistent --- bot/exts/evergreen/githubinfo.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index 2a540bac..f52454ba 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -1,4 +1,5 @@ import logging +import random from datetime import datetime from typing import Optional @@ -7,6 +8,8 @@ import discord from discord.ext import commands from discord.ext.commands.cooldowns import BucketType +from bot.constants import NEGATIVE_REPLIES + log = logging.getLogger(__name__) @@ -38,13 +41,12 @@ class GithubInfo(commands.Cog): return async with ctx.typing(): - user_data = await self.fetch_data(f"https://api.github.com/users/{username}") # User_data will not have a message key if the user exists if user_data.get('message') is not None: - await ctx.send(embed=discord.Embed(title=f"The profile for `{username}` was not found.", - colour=0xff0022)) + await ctx.send(embed=discord.Embed(title=random.choice(NEGATIVE_REPLIES), + colour=discord.Colour.red())) return org_data = await self.fetch_data(user_data['organizations_url']) @@ -64,7 +66,7 @@ class GithubInfo(commands.Cog): embed = discord.Embed( title=f"`{user_data['login']}`'s GitHub profile info", description=f"```{user_data['bio']}```\n" if user_data['bio'] is not None else "", - colour=0xf5faf6, + colour=0x7289da, url=user_data['html_url'], timestamp=datetime.strptime(user_data['created_at'], "%Y-%m-%dT%H:%M:%SZ") ) -- cgit v1.2.3 From 6c9162deecebb21f3925276a474d2e295877a665 Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Fri, 9 Oct 2020 23:35:40 +0530 Subject: blog link shows the link itself --- bot/exts/evergreen/githubinfo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index f52454ba..b66512b3 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -57,9 +57,9 @@ class GithubInfo(commands.Cog): # Forming blog link if user_data['blog'].startswith("http"): # Blog link is complete - blog = f"[Direct link]({user_data['blog']})" + blog = user_data['blog'] elif user_data['blog']: # Blog exists but the link is not complete - blog = f"[Direct link](https://{user_data['blog']})" + blog = f"https://{user_data['blog']}" else: blog = "No blog link available" -- cgit v1.2.3 From a7c0531b20f6f9bd8bbc9c4436a6cb4e52336e0a Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Fri, 9 Oct 2020 23:50:25 +0530 Subject: organisation support --- bot/exts/evergreen/githubinfo.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index b66512b3..8183dd0c 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -73,20 +73,24 @@ class GithubInfo(commands.Cog): embed.set_thumbnail(url=user_data['avatar_url']) embed.set_footer(text="Account created at") - embed.add_field(name="Followers", value=f"""[{user_data['followers']}] - ({user_data['html_url']}?tab=followers)""") - embed.add_field(name="\u200b", value="\u200b") - embed.add_field(name="Following", value=f"""[{user_data['following']}] + if user_data['type'] == "User": + + embed.add_field(name="Followers", value=f"""[{user_data['followers']}] + ({user_data['html_url']}?tab=followers)""") + embed.add_field(name="\u200b", value="\u200b") + embed.add_field(name="Following", value=f"""[{user_data['following']}] ({user_data['html_url']}?tab=following)""") embed.add_field(name="Public repos", value=f"[{user_data['public_repos']}]({user_data['html_url']}?tab=repositories)") embed.add_field(name="\u200b", value="\u200b") - embed.add_field(name="Starred repos", value=f"[{len(starred_data)}]({user_data['html_url']}?tab=stars)") - embed.add_field(name=f"Organization{'s' if len(orgs)!=1 else ''}", - value=orgs_to_add if orgs else "No organizations") - embed.add_field(name="\u200b", value="\u200b") + if user_data['type'] == "User": + embed.add_field(name="Starred repos", value=f"[{len(starred_data)}]({user_data['html_url']}?tab=stars)") + + embed.add_field(name=f"Organization{'s' if len(orgs)!=1 else ''}", + value=orgs_to_add if orgs else "No organizations") + embed.add_field(name="\u200b", value="\u200b") embed.add_field(name="Blog", value=blog) await ctx.send(embed=embed) -- cgit v1.2.3 From 7c6328a6dafa370cab7bcadba454953e50d82741 Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Sat, 10 Oct 2020 12:00:59 +0530 Subject: cmd resets if username not given; blog renamed to website; replaced starred repo with gists --- bot/exts/evergreen/githubinfo.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index 8183dd0c..b0e7c9f0 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -3,7 +3,6 @@ import random from datetime import datetime from typing import Optional -import aiohttp import discord from discord.ext import commands from discord.ext.commands.cooldowns import BucketType @@ -20,24 +19,22 @@ class GithubInfo(commands.Cog): self.bot = bot @staticmethod - async def fetch_data(url: str) -> dict: + async def fetch_data(self, url: str) -> dict: """Retrieve data as a dictionary.""" - async with aiohttp.ClientSession() as cs: - async with cs.get(url) as r: - return await r.json() + async with self.bot.http_session.get(url) as r: + return await r.json() @commands.command(name='github', aliases=['gh']) - @commands.cooldown(1, 5, BucketType.user) + @commands.cooldown(1, 60, BucketType.user) async def get_github_info(self, ctx: commands.Context, username: Optional[str]) -> None: """ Fetches a user's GitHub information. Username is optional and sends the help command if not specified. - - Usage: .gh [username] """ if username is None: await ctx.invoke(self.bot.get_command('help'), 'github') + ctx.command.reset_cooldown(ctx) return async with ctx.typing(): @@ -53,7 +50,7 @@ class GithubInfo(commands.Cog): orgs = [f"[{org['login']}](https://github.com/{org['login']})" for org in org_data] orgs_to_add = ' | '.join(orgs) - starred_data = await self.fetch_data(user_data['starred_url']) + gists_data = await self.fetch_data(f"https://api.github.com/users/{username}/gists") # Forming blog link if user_data['blog'].startswith("http"): # Blog link is complete @@ -61,7 +58,7 @@ class GithubInfo(commands.Cog): elif user_data['blog']: # Blog exists but the link is not complete blog = f"https://{user_data['blog']}" else: - blog = "No blog link available" + blog = "No website link available" embed = discord.Embed( title=f"`{user_data['login']}`'s GitHub profile info", @@ -86,12 +83,12 @@ class GithubInfo(commands.Cog): embed.add_field(name="\u200b", value="\u200b") if user_data['type'] == "User": - embed.add_field(name="Starred repos", value=f"[{len(starred_data)}]({user_data['html_url']}?tab=stars)") + embed.add_field(name="Gists", value=f"[{len(gists_data)}](https://gist.github.com/{username})") embed.add_field(name=f"Organization{'s' if len(orgs)!=1 else ''}", value=orgs_to_add if orgs else "No organizations") embed.add_field(name="\u200b", value="\u200b") - embed.add_field(name="Blog", value=blog) + embed.add_field(name="Website", value=blog) await ctx.send(embed=embed) -- cgit v1.2.3 From f460a67d339df53163bb1fdc6a8d250a7d498c04 Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Sat, 10 Oct 2020 23:44:38 +0530 Subject: followers md fix --- bot/exts/evergreen/githubinfo.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index b0e7c9f0..c514d200 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -18,7 +18,6 @@ class GithubInfo(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot - @staticmethod async def fetch_data(self, url: str) -> dict: """Retrieve data as a dictionary.""" async with self.bot.http_session.get(url) as r: @@ -43,6 +42,7 @@ class GithubInfo(commands.Cog): # User_data will not have a message key if the user exists if user_data.get('message') is not None: await ctx.send(embed=discord.Embed(title=random.choice(NEGATIVE_REPLIES), + description=f"The profile for `{username}` was not found.", colour=discord.Colour.red())) return @@ -72,11 +72,11 @@ class GithubInfo(commands.Cog): if user_data['type'] == "User": - embed.add_field(name="Followers", value=f"""[{user_data['followers']}] - ({user_data['html_url']}?tab=followers)""") + embed.add_field(name="Followers", + value=f"[{user_data['followers']}]({user_data['html_url']}?tab=followers)") embed.add_field(name="\u200b", value="\u200b") - embed.add_field(name="Following", value=f"""[{user_data['following']}] - ({user_data['html_url']}?tab=following)""") + embed.add_field(name="Following", + value=f"[{user_data['following']}]({user_data['html_url']}?tab=following)") embed.add_field(name="Public repos", value=f"[{user_data['public_repos']}]({user_data['html_url']}?tab=repositories)") -- cgit v1.2.3 From d2e2143a2c1345f93a494314b0a9cc954d1ca957 Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Sun, 11 Oct 2020 00:29:13 +0530 Subject: reduced num of api calls by 1 --- bot/exts/evergreen/githubinfo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index c514d200..19ec382b 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -50,7 +50,7 @@ class GithubInfo(commands.Cog): orgs = [f"[{org['login']}](https://github.com/{org['login']})" for org in org_data] orgs_to_add = ' | '.join(orgs) - gists_data = await self.fetch_data(f"https://api.github.com/users/{username}/gists") + gists = user_data['public_gists'] # Forming blog link if user_data['blog'].startswith("http"): # Blog link is complete @@ -83,7 +83,7 @@ class GithubInfo(commands.Cog): embed.add_field(name="\u200b", value="\u200b") if user_data['type'] == "User": - embed.add_field(name="Gists", value=f"[{len(gists_data)}](https://gist.github.com/{username})") + embed.add_field(name="Gists", value=f"[{len(gists)}](https://gist.github.com/{username})") embed.add_field(name=f"Organization{'s' if len(orgs)!=1 else ''}", value=orgs_to_add if orgs else "No organizations") -- cgit v1.2.3 From d8b51b804b4d309dafc7ba6aaea7be62c64681be Mon Sep 17 00:00:00 2001 From: Lakshya Shastri Date: Sun, 11 Oct 2020 00:46:47 +0530 Subject: gists count fix --- bot/exts/evergreen/githubinfo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/githubinfo.py') diff --git a/bot/exts/evergreen/githubinfo.py b/bot/exts/evergreen/githubinfo.py index 19ec382b..2e38e3ab 100644 --- a/bot/exts/evergreen/githubinfo.py +++ b/bot/exts/evergreen/githubinfo.py @@ -83,7 +83,7 @@ class GithubInfo(commands.Cog): embed.add_field(name="\u200b", value="\u200b") if user_data['type'] == "User": - embed.add_field(name="Gists", value=f"[{len(gists)}](https://gist.github.com/{username})") + embed.add_field(name="Gists", value=f"[{gists}](https://gist.github.com/{username})") embed.add_field(name=f"Organization{'s' if len(orgs)!=1 else ''}", value=orgs_to_add if orgs else "No organizations") -- cgit v1.2.3