From 8c82fd5c03b62f2d35cf6b0e2945e332a5b02bc3 Mon Sep 17 00:00:00 2001 From: vivax3794 <51753506+vivax3794@users.noreply.github.com> Date: Tue, 1 Oct 2019 01:16:01 +0200 Subject: added hacktober-issue-finder cog. --- bot/seasons/halloween/hacktober-issue-finder.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 bot/seasons/halloween/hacktober-issue-finder.py (limited to 'bot') diff --git a/bot/seasons/halloween/hacktober-issue-finder.py b/bot/seasons/halloween/hacktober-issue-finder.py new file mode 100644 index 00000000..ce0993d3 --- /dev/null +++ b/bot/seasons/halloween/hacktober-issue-finder.py @@ -0,0 +1,18 @@ +import logging + +from discord.ext import commands + +log = logging.getLogger(__name__) + + +class SpookyEightBall(commands.Cog): + """Find a random hacktober python issue on GitHub.""" + + def __init__(self, bot: commands.Bot): + self.bot = bot + + +def setup(bot: commands.Bot) -> None: + """Hacktober issue finder Cog Load.""" + bot.add_cog(SpookyEightBall(bot)) + log.info("hacktober-issue-finder cog loaded") -- cgit v1.2.3 From ae4eb13f93c9b7e5465fe9b3a91f093f1c6d1bac Mon Sep 17 00:00:00 2001 From: vivax3794 <51753506+vivax3794@users.noreply.github.com> Date: Tue, 1 Oct 2019 02:45:48 +0200 Subject: get issue data --- bot/seasons/halloween/hacktober-issue-finder.py | 39 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktober-issue-finder.py b/bot/seasons/halloween/hacktober-issue-finder.py index ce0993d3..17eec95a 100644 --- a/bot/seasons/halloween/hacktober-issue-finder.py +++ b/bot/seasons/halloween/hacktober-issue-finder.py @@ -1,18 +1,53 @@ +import datetime import logging +from typing import Dict, List +import aiohttp from discord.ext import commands log = logging.getLogger(__name__) +URL = "https://api.github.com/search/issues" +HEADERS = {"Accept": "application / vnd.github.v3 + json"} +SEARCH = "label:hacktoberfest+language:python+state:open" -class SpookyEightBall(commands.Cog): + +class HacktoberIssues(commands.Cog): """Find a random hacktober python issue on GitHub.""" def __init__(self, bot: commands.Bot): self.bot = bot + self.cache = None + self.cache_timer = datetime.datetime(1, 1, 1) + + @commands.command() + async def hacktoberissues(self, ctx: commands.Context) -> None: + """Get a random python hacktober issue from Github.""" + with ctx.typing(): + data = await self.get_issues(ctx) + print("need to use data somehow to commit...", data) + + async def get_issues(self, ctx: commands.Context) -> List[Dict]: + """Get a list of the python issues with the label 'hacktoberfest' from the Github api.""" + if (ctx.message.created_at - self.cache_timer).seconds <= 60: + return self.cache + + async with aiohttp.ClientSession() as session: + # text = TEXT # + "+label:hacktober" + params = { + "q": SEARCH + } + async with session.get(URL, headers=HEADERS, params=params) as response: + if response.status != 200: + await ctx.send(f"ERROR: expected 200 status (got {response.status}) from the GitHub api.") + await ctx.send(await response.text()) + data = (await response.json())["items"] + self.cache = data + self.cache_timer = ctx.message.created_at + return data def setup(bot: commands.Bot) -> None: """Hacktober issue finder Cog Load.""" - bot.add_cog(SpookyEightBall(bot)) + bot.add_cog(HacktoberIssues(bot)) log.info("hacktober-issue-finder cog loaded") -- cgit v1.2.3 From dce5b70e15b089ea661c12db120223f50f83ad74 Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Tue, 1 Oct 2019 15:02:21 -0400 Subject: Add drag queen names The names are stored in a text file, since they're basically just a list, and json seems like overkill for this case. In any case switching over to json later would be easy. The names could be separated into first and last names in order to generate more combinations, but that would break the wordplay that many of the names have. The names were taken from https://www.fantasynamegenerators.com/drag-queen-names.php as permitted by the footnote on the page. --- bot/resources/pride/drag_queen_names.txt | 248 +++++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 bot/resources/pride/drag_queen_names.txt (limited to 'bot') diff --git a/bot/resources/pride/drag_queen_names.txt b/bot/resources/pride/drag_queen_names.txt new file mode 100644 index 00000000..1701b760 --- /dev/null +++ b/bot/resources/pride/drag_queen_names.txt @@ -0,0 +1,248 @@ +Adelle Lectible +Adelle Light +Adelle Lirious +Alison Wonder +Amie Thyst +Amie Zonite +Angela Develle +Anna Conda +Anne Amaley +Annie Nigma +Aria Hymn +Aria Viderci +Aroa Mattic +Aster Starr +Aura Aurora +Aura Ley +Aurora Dorea +Barba Rouse +Bea Constrictor +Bella Lush +Belle Icoza +Belle Ligerrente +Betty Brilliance +Bo Deysious +Carol Chorale +Cecil Clouds +Cecil Sunshine +Celeste Booday +Chichi Swank +Claire Geeman +Claire Rickal +Claire Voyance +Cleo Patrix +Connie Fidence +Corra Rageous +Daye Light +Deedee Cation +Deedee Sign +Dianne Gerous +Didi Divine +Diemme Monds +Dorothy Doughty +Dutches Dauntless +Ella Gance +Ella Gants +Ella Menterry +Ella Stique +Elle Lectrick +Elle Lure +Emma Geddon +Emma Phasis +Emma Rald +Emme Plosion +Emme Pulse +Emme Vention +Enna Fincible +Enne Phinite +Enne Treppide +Etha Nitty +Etha Reyal +Euphoria Bliss +Eva Nessent +Eve Forric +Eve Ningowne +Eve Ville +Faith Lesse +Faschia Nation +Faye Boulous +Faye Lacious +Faye Minine +Faye Nixx +Felicity Spice +Freya Domme +Gal Gallant +Gal Galore +Gal Lante +Gemma Safir +Gena Rocity +Genna Russ +Gigi Lamour +Gigi Rand +Glemma Rouss +Grace Iyus +Haye Light +Hazel Nutt +Hella Billy +Hella Centrique +Hella Cious +Hella Riouss +Hella Whole +Hellen Back +Herra Zee +Ina Creddeble +Ina Fernalle +Jo Nee +Jo Phial +Joye Ryde +Jue Cee +Jue Wells +Juju Bee +Kaia Cayenne +Kaye Bye +Kitsch Kitsch Bang Bang +Lady Lace +Lavish Lazuli +Lea Ness +Leye Berty +Lisse Truss +Liv Lee +Lola Lavish +Lolo Yaltie +Lucy Fur +Lucy Luck +Lulu LaBye +Lulu Xuri +Lunaye Clipse +Lyra Kall +Maggie Magma +Mara Bells +Marry Golds +Marry Nayde +Marry Sipan +Marve Vellus +Mary Ganal +Mary Malade +May Jestic +May Lancholly +May Licious +May Lodi +May Morable +May Stirius +May Varlous +Melody Gale +Melody Toune +Miss Adora +Miss Alure +Miss Chieff +Miss Fortune +Miss Mash +Miss Mood +Miss Nomer +Miss Sanguine +Miss Sublime +Mistress Galore +Monique Mystique +Morgan Fatana +Nashay Kitt +Nicole Lorful +Noë Stalgia +Ora Kelle +Ora Nate +Patty Siyens +Penny Laized +Penny Ramma +Penny Rammic +Penny Talloons +Percey Ferance +Perry Fomance +Phara Waye +Phata Morgana +Pho Latyle +Pho Lume +Phoebe Rant +Phoenix Bright +Pippa Pepper +Pippa Pizazz +Polly Tickle +Poppy Corn +Poppy Cox +Poppy Domm +Poppy Larr +Poppy Lerry +Poppy Sickles +Portia Bella +Portia Nette +Pria Steegious +Pria Steen +Prissa Teen +Raye Bitt +Raye Diante +Raye Nessance +Raye Storm +Remi Nissent +Rey Mantique +Rey Markeble +Rey Moorse +Rey Torric +Rococo Jazz +Roma Ence +Rose Budd +Ruby Redd +Ruby Ree +Ruth Lezz +Sall Laikeen +Sall Lay +Sally Ness +Sam Armie +Sam Ooth +Sara Castique +Sara Donique +Sara Penth +Sarah Pentine +Sarah Reen +Sasha Sass +Satty Phection +Sella Fish +Sella Stice +Selly Foxx +Senna Guinne +Senna Seer +Shia Mirring +Sia Dellic +Sia Dowe +Siam Pathy +Silver Foxx +Siri Price +Sofie Moore +Sofie Stication +Su Blime +Sue Burben +Sue Missif +Sue Pernova +Sue Preem +Super Nova +Suse Pense +Suzu Blime +Temma Tation +Tempest Wilde +Terra Gique +Thea Terre +Tina Cious +Tina Scious +Tira Mendus +Tira Quoise +Trinity Quart +Trixie Foxx +Tye Gress +Tye Phun +Vall Canno +Vall Iant +Vall Orous +Vanity Fairchild +Vicki Tory +Vivi Venus +Vivian Foxx +Vye Vacius +Zahara Dessert + -- cgit v1.2.3 From a1c9078e69ddaec24c632bd1bd85826d6abe2d65 Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Tue, 1 Oct 2019 15:44:40 -0400 Subject: Add drag queen name generator Could be improved by writing a message that says: "@command_invoker's drag queen name is " --- bot/seasons/pride/drag_queen_name.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 bot/seasons/pride/drag_queen_name.py (limited to 'bot') diff --git a/bot/seasons/pride/drag_queen_name.py b/bot/seasons/pride/drag_queen_name.py new file mode 100644 index 00000000..f34da00e --- /dev/null +++ b/bot/seasons/pride/drag_queen_name.py @@ -0,0 +1,32 @@ +import logging +import random +from pathlib import Path + +from discord.ext import commands + +log = logging.getLogger(__name__) + + +class DragNames(commands.Cog): + """Gives a random drag queen name""" + + def __init__(self, bot: commands.Bot): + self.bot = bot + self.names = self.load_names() + + @staticmethod + def load_names() -> list: + """Loads a list of drag queen names.""" + with open(Path("bot/resources/pride/drag_queen_names.txt"), "r", encoding="utf-8") as f: + return f.readlines() + + @commands.command(name="dragname", aliases=["dragqueenname", "queenme"]) + async def dragname(self, ctx: commands.Context) -> None: + """Sends a message with a drag queen name.""" + await ctx.send(random.choice(self.names)) + + +def setup(bot: commands.Bot) -> None: + """Cog loader for drag queen name generator.""" + bot.add_cog(DragNames(bot)) + log.info("Drag queen name generator cog loaded!") -- cgit v1.2.3 From 63e98827e44d3049922c14fd32ca104548c44b60 Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Tue, 1 Oct 2019 21:25:50 -0400 Subject: Fix linter issue --- bot/seasons/pride/drag_queen_name.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/pride/drag_queen_name.py b/bot/seasons/pride/drag_queen_name.py index f34da00e..8f0219f3 100644 --- a/bot/seasons/pride/drag_queen_name.py +++ b/bot/seasons/pride/drag_queen_name.py @@ -8,7 +8,7 @@ log = logging.getLogger(__name__) class DragNames(commands.Cog): - """Gives a random drag queen name""" + """Gives a random drag queen name!""" def __init__(self, bot: commands.Bot): self.bot = bot -- cgit v1.2.3 From 3177f6ae35c4f60134a02248a07c3f590298e85e Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Wed, 2 Oct 2019 20:59:25 +0100 Subject: New more succinct output. --- bot/seasons/evergreen/issues.py | 85 ++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 40 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 438ab475..a0969e50 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -3,55 +3,60 @@ import logging import discord from discord.ext import commands -from bot.constants import Colours -from bot.decorators import override_in_channel - log = logging.getLogger(__name__) +icons = {"issue": "https://i.imgur.com/HFV0nv9.png", + "issue-closed": "https://i.imgur.com/uZSX7as.png", + "pull-request": "https://i.imgur.com/zHhnALX.png", + "pull-request-closed": "https://i.imgur.com/JYmTn5P.png", + "merge": "https://i.imgur.com/xzQZxXe.png"} -class Issues(commands.Cog): - """Cog that allows users to retrieve issues from GitHub.""" +respValue = {404: "Issue/pull request not located! Please enter a valid number!", + 403: "rate limit has been hit! Please try again later!"} - def __init__(self, bot: commands.Bot): - self.bot = bot - - @commands.command(aliases=("issues",)) - @override_in_channel() - async def issue( - self, ctx: commands.Context, number: int, repository: str = "seasonalbot", user: str = "python-discord" - ) -> None: - """Command to retrieve issues from a GitHub repository.""" - api_url = f"https://api.github.com/repos/{user}/{repository}/issues/{number}" - failed_status = { - 404: f"Issue #{number} doesn't exist in the repository {user}/{repository}.", - 403: f"Rate limit exceeded. Please wait a while before trying again!" - } - - async with self.bot.http_session.get(api_url) as r: - json_data = await r.json() - response_code = r.status - if response_code in failed_status: - return await ctx.send(failed_status[response_code]) - - repo_url = f"https://github.com/{user}/{repository}" - issue_embed = discord.Embed(colour=Colours.bright_green) - issue_embed.add_field(name="Repository", value=f"[{user}/{repository}]({repo_url})", inline=False) - issue_embed.add_field(name="Issue Number", value=f"#{number}", inline=False) - issue_embed.add_field(name="Status", value=json_data["state"].title()) - issue_embed.add_field(name="Link", value=json_data["html_url"], inline=False) +class Issues(commands.Cog): + """Cog that allows users to retrieve issues from GitHub""" - description = json_data["body"] - if len(description) > 1024: - placeholder = " [...]" - description = f"{description[:1024 - len(placeholder)]}{placeholder}" + def __init__(self, bot): + self.bot = bot - issue_embed.add_field(name="Description", value=description, inline=False) + @commands.command(aliases=("pr",)) + async def issues(self, ctx, number: int, repository: str = "seasonalbot", user: str = "python-discord"): + """Command to get issues/pull request from GitHub""" + url = f"https://api.github.com/repos/{user}/{repository}/issues/{str(number)}" + mergeURL = f"https://api.github.com/repos/{user}/{repository}/pulls/{str(number)}/merge" - await ctx.send(embed=issue_embed) + async with self.bot.http_session.get(url) as r: + json_data = await r.json() + if r.status in respValue: + return await ctx.send(f"[{str(r.status)}] {respValue.get(r.status)}") + + if "issues" in json_data.get("html_url"): + if json_data.get("state") == "open": + iconURL = icons.get("issue") + else: + iconURL = icons.get("issue_closed") + else: + async with self.bot.http_session.get(mergeURL) as m: + if json_data.get("state") == "open": + iconURL = icons.get("pull-request") + elif m.status == 204: + iconURL = icons.get("merge") + else: + iconURL = icons.get("pull-request-closed") + + resp = discord.Embed(colour=0x6CC644) + resp.set_author( + name=f"[{repository}] #{number} {json_data.get('title')}", + url=json_data.get("html_url"), + icon_url=iconURL) + await ctx.send(embed=resp) + + +def setup(bot): + """Cog Retrieves Issues From Github""" -def setup(bot: commands.Bot) -> None: - """Github Issues Cog Load.""" bot.add_cog(Issues(bot)) log.info("Issues cog loaded") -- cgit v1.2.3 From c06ec338c1e6d955c4244ed60d08bbeccb90c359 Mon Sep 17 00:00:00 2001 From: vivax3794 <51753506+vivax3794@users.noreply.github.com> Date: Wed, 2 Oct 2019 22:05:23 +0200 Subject: added embed. --- bot/seasons/halloween/hacktober-issue-finder.py | 39 ++++++++++++++++++------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktober-issue-finder.py b/bot/seasons/halloween/hacktober-issue-finder.py index 17eec95a..54f205cf 100644 --- a/bot/seasons/halloween/hacktober-issue-finder.py +++ b/bot/seasons/halloween/hacktober-issue-finder.py @@ -1,15 +1,16 @@ import datetime import logging +import random from typing import Dict, List import aiohttp +import discord from discord.ext import commands log = logging.getLogger(__name__) -URL = "https://api.github.com/search/issues" +URL = "https://api.github.com/search/issues?q=label:hacktoberfest+language:python+state:open&per_page=100" HEADERS = {"Accept": "application / vnd.github.v3 + json"} -SEARCH = "label:hacktoberfest+language:python+state:open" class HacktoberIssues(commands.Cog): @@ -24,8 +25,10 @@ class HacktoberIssues(commands.Cog): async def hacktoberissues(self, ctx: commands.Context) -> None: """Get a random python hacktober issue from Github.""" with ctx.typing(): - data = await self.get_issues(ctx) - print("need to use data somehow to commit...", data) + issues = await self.get_issues(ctx) + issue = random.choice(issues) + embed = self.format_embed(issue) + await ctx.send(embed=embed) async def get_issues(self, ctx: commands.Context) -> List[Dict]: """Get a list of the python issues with the label 'hacktoberfest' from the Github api.""" @@ -34,17 +37,31 @@ class HacktoberIssues(commands.Cog): async with aiohttp.ClientSession() as session: # text = TEXT # + "+label:hacktober" - params = { - "q": SEARCH - } - async with session.get(URL, headers=HEADERS, params=params) as response: + + async with session.get(URL, headers=HEADERS) as response: if response.status != 200: await ctx.send(f"ERROR: expected 200 status (got {response.status}) from the GitHub api.") await ctx.send(await response.text()) - data = (await response.json())["items"] - self.cache = data + data = await response.json() + issues = data["items"] + self.cache = issues self.cache_timer = ctx.message.created_at - return data + return issues + + @staticmethod + def format_embed(issue: Dict) -> discord.Embed: + """Format the issue data into a embed.""" + title = issue["title"] + issue_url = issue["url"].replace("api.", "").replace("/repos/", "/") + body = issue["body"] + labels = [label["name"] for label in issue["labels"]] + + embed = discord.Embed(title=title) + embed.description = body + embed.add_field(name="labels", value="\n".join(labels)) + embed.url = issue_url + + return embed def setup(bot: commands.Bot) -> None: -- cgit v1.2.3 From ecc2e3b1bbcda1c841b9cb2d0e96809cefe66261 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Wed, 2 Oct 2019 21:10:15 +0100 Subject: Linting --- bot/seasons/evergreen/issues.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index a0969e50..5f46e1e6 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -22,7 +22,7 @@ class Issues(commands.Cog): self.bot = bot @commands.command(aliases=("pr",)) - async def issues(self, ctx, number: int, repository: str = "seasonalbot", user: str = "python-discord"): + async def issues(self, ctx, number: int, repository: str = "seasonalbot", user: str = "python-discord") -> None: """Command to get issues/pull request from GitHub""" url = f"https://api.github.com/repos/{user}/{repository}/issues/{str(number)}" mergeURL = f"https://api.github.com/repos/{user}/{repository}/pulls/{str(number)}/merge" @@ -55,8 +55,7 @@ class Issues(commands.Cog): await ctx.send(embed=resp) -def setup(bot): +def setup(bot) -> None: """Cog Retrieves Issues From Github""" - bot.add_cog(Issues(bot)) log.info("Issues cog loaded") -- cgit v1.2.3 From 9376aeafd94c5c26d0f80ad995fe0487e027d97e Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Wed, 2 Oct 2019 21:15:34 +0100 Subject: Final Linting --- bot/seasons/evergreen/issues.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 5f46e1e6..ddcdb265 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -18,12 +18,13 @@ respValue = {404: "Issue/pull request not located! Please enter a valid number!" class Issues(commands.Cog): """Cog that allows users to retrieve issues from GitHub""" - def __init__(self, bot): + def __init__(self, bot: commands.Bot): self.bot = bot @commands.command(aliases=("pr",)) - async def issues(self, ctx, number: int, repository: str = "seasonalbot", user: str = "python-discord") -> None: - """Command to get issues/pull request from GitHub""" + async def issues(self, ctx: commands.Context, number: int, repository: str = "seasonalbot", + user: str = "python-discord") -> None: + """Command to get issues/pull request from GitHub.""" url = f"https://api.github.com/repos/{user}/{repository}/issues/{str(number)}" mergeURL = f"https://api.github.com/repos/{user}/{repository}/pulls/{str(number)}/merge" @@ -56,6 +57,6 @@ class Issues(commands.Cog): def setup(bot) -> None: - """Cog Retrieves Issues From Github""" - bot.add_cog(Issues(bot)) + """Cog Retrieves Issues From Github.""" + bot.add_cog(Issues(bot: commands.Bot)) log.info("Issues cog loaded") -- cgit v1.2.3 From 618b9d512b6772dcd6e106972623f840a9833f29 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Wed, 2 Oct 2019 21:17:58 +0100 Subject: Syntax Error Fix --- bot/seasons/evergreen/issues.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index ddcdb265..07f1a508 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -56,7 +56,7 @@ class Issues(commands.Cog): await ctx.send(embed=resp) -def setup(bot) -> None: +def setup(bot: commands.Bot) -> None: """Cog Retrieves Issues From Github.""" - bot.add_cog(Issues(bot: commands.Bot)) + bot.add_cog(Issues(bot)) log.info("Issues cog loaded") -- cgit v1.2.3 From cda6fe789f411cf18e4d468dcbfbf0b2b1f1bbca Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Wed, 2 Oct 2019 21:27:01 +0100 Subject: Final Final Linting Error D415 --- bot/seasons/evergreen/issues.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 07f1a508..a6fe7b57 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -16,7 +16,7 @@ respValue = {404: "Issue/pull request not located! Please enter a valid number!" class Issues(commands.Cog): - """Cog that allows users to retrieve issues from GitHub""" + """Cog that allows users to retrieve issues from GitHub.""" def __init__(self, bot: commands.Bot): self.bot = bot -- cgit v1.2.3 From 9fab6ec2d5762d6d25f232efd419e62622270eff Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Wed, 2 Oct 2019 22:59:24 -0400 Subject: Change drag queen name list to JSON --- bot/resources/pride/drag_queen_names.json | 249 ++++++++++++++++++++++++++++++ bot/resources/pride/drag_queen_names.txt | 248 ----------------------------- bot/seasons/pride/drag_queen_name.py | 5 +- 3 files changed, 252 insertions(+), 250 deletions(-) create mode 100644 bot/resources/pride/drag_queen_names.json delete mode 100644 bot/resources/pride/drag_queen_names.txt (limited to 'bot') diff --git a/bot/resources/pride/drag_queen_names.json b/bot/resources/pride/drag_queen_names.json new file mode 100644 index 00000000..f63cdec3 --- /dev/null +++ b/bot/resources/pride/drag_queen_names.json @@ -0,0 +1,249 @@ +[ + "Adelle Lectible", + "Adelle Light", + "Adelle Lirious", + "Alison Wonder", + "Amie Thyst", + "Amie Zonite", + "Angela Develle", + "Anna Conda", + "Anne Amaley", + "Annie Nigma", + "Aria Hymn", + "Aria Viderci", + "Aroa Mattic", + "Aster Starr", + "Aura Aurora", + "Aura Ley", + "Aurora Dorea", + "Barba Rouse", + "Bea Constrictor", + "Bella Lush", + "Belle Icoza", + "Belle Ligerrente", + "Betty Brilliance", + "Bo Deysious", + "Carol Chorale", + "Cecil Clouds", + "Cecil Sunshine", + "Celeste Booday", + "Chichi Swank", + "Claire Geeman", + "Claire Rickal", + "Claire Voyance", + "Cleo Patrix", + "Connie Fidence", + "Corra Rageous", + "Daye Light", + "Deedee Cation", + "Deedee Sign", + "Dianne Gerous", + "Didi Divine", + "Diemme Monds", + "Dorothy Doughty", + "Dutches Dauntless", + "Ella Gance", + "Ella Gants", + "Ella Menterry", + "Ella Stique", + "Elle Lectrick", + "Elle Lure", + "Emma Geddon", + "Emma Phasis", + "Emma Rald", + "Emme Plosion", + "Emme Pulse", + "Emme Vention", + "Enna Fincible", + "Enne Phinite", + "Enne Treppide", + "Etha Nitty", + "Etha Reyal", + "Euphoria Bliss", + "Eva Nessent", + "Eve Forric", + "Eve Ningowne", + "Eve Ville", + "Faith Lesse", + "Faschia Nation", + "Faye Boulous", + "Faye Lacious", + "Faye Minine", + "Faye Nixx", + "Felicity Spice", + "Freya Domme", + "Gal Gallant", + "Gal Galore", + "Gal Lante", + "Gemma Safir", + "Gena Rocity", + "Genna Russ", + "Gigi Lamour", + "Gigi Rand", + "Glemma Rouss", + "Grace Iyus", + "Haye Light", + "Hazel Nutt", + "Hella Billy", + "Hella Centrique", + "Hella Cious", + "Hella Riouss", + "Hella Whole", + "Hellen Back", + "Herra Zee", + "Ina Creddeble", + "Ina Fernalle", + "Jo Nee", + "Jo Phial", + "Joye Ryde", + "Jue Cee", + "Jue Wells", + "Juju Bee", + "Kaia Cayenne", + "Kaye Bye", + "Kitsch Kitsch Bang Bang", + "Lady Lace", + "Lavish Lazuli", + "Lea Ness", + "Leye Berty", + "Lisse Truss", + "Liv Lee", + "Lola Lavish", + "Lolo Yaltie", + "Lucy Fur", + "Lucy Luck", + "Lulu LaBye", + "Lulu Xuri", + "Lunaye Clipse", + "Lyra Kall", + "Maggie Magma", + "Mara Bells", + "Marry Golds", + "Marry Nayde", + "Marry Sipan", + "Marve Vellus", + "Mary Ganal", + "Mary Malade", + "May Jestic", + "May Lancholly", + "May Licious", + "May Lodi", + "May Morable", + "May Stirius", + "May Varlous", + "Melody Gale", + "Melody Toune", + "Miss Adora", + "Miss Alure", + "Miss Chieff", + "Miss Fortune", + "Miss Mash", + "Miss Mood", + "Miss Nomer", + "Miss Sanguine", + "Miss Sublime", + "Mistress Galore", + "Monique Mystique", + "Morgan Fatana", + "Nashay Kitt", + "Nicole Lorful", + "Noë Stalgia", + "Ora Kelle", + "Ora Nate", + "Patty Siyens", + "Penny Laized", + "Penny Ramma", + "Penny Rammic", + "Penny Talloons", + "Percey Ferance", + "Perry Fomance", + "Phara Waye", + "Phata Morgana", + "Pho Latyle", + "Pho Lume", + "Phoebe Rant", + "Phoenix Bright", + "Pippa Pepper", + "Pippa Pizazz", + "Polly Tickle", + "Poppy Corn", + "Poppy Cox", + "Poppy Domm", + "Poppy Larr", + "Poppy Lerry", + "Poppy Sickles", + "Portia Bella", + "Portia Nette", + "Pria Steegious", + "Pria Steen", + "Prissa Teen", + "Raye Bitt", + "Raye Diante", + "Raye Nessance", + "Raye Storm", + "Remi Nissent", + "Rey Mantique", + "Rey Markeble", + "Rey Moorse", + "Rey Torric", + "Rococo Jazz", + "Roma Ence", + "Rose Budd", + "Ruby Redd", + "Ruby Ree", + "Ruth Lezz", + "Sall Laikeen", + "Sall Lay", + "Sally Ness", + "Sam Armie", + "Sam Ooth", + "Sara Castique", + "Sara Donique", + "Sara Penth", + "Sarah Pentine", + "Sarah Reen", + "Sasha Sass", + "Satty Phection", + "Sella Fish", + "Sella Stice", + "Selly Foxx", + "Senna Guinne", + "Senna Seer", + "Shia Mirring", + "Sia Dellic", + "Sia Dowe", + "Siam Pathy", + "Silver Foxx", + "Siri Price", + "Sofie Moore", + "Sofie Stication", + "Su Blime", + "Sue Burben", + "Sue Missif", + "Sue Pernova", + "Sue Preem", + "Super Nova", + "Suse Pense", + "Suzu Blime", + "Temma Tation", + "Tempest Wilde", + "Terra Gique", + "Thea Terre", + "Tina Cious", + "Tina Scious", + "Tira Mendus", + "Tira Quoise", + "Trinity Quart", + "Trixie Foxx", + "Tye Gress", + "Tye Phun", + "Vall Canno", + "Vall Iant", + "Vall Orous", + "Vanity Fairchild", + "Vicki Tory", + "Vivi Venus", + "Vivian Foxx", + "Vye Vacius", + "Zahara Dessert" +] \ No newline at end of file diff --git a/bot/resources/pride/drag_queen_names.txt b/bot/resources/pride/drag_queen_names.txt deleted file mode 100644 index 1701b760..00000000 --- a/bot/resources/pride/drag_queen_names.txt +++ /dev/null @@ -1,248 +0,0 @@ -Adelle Lectible -Adelle Light -Adelle Lirious -Alison Wonder -Amie Thyst -Amie Zonite -Angela Develle -Anna Conda -Anne Amaley -Annie Nigma -Aria Hymn -Aria Viderci -Aroa Mattic -Aster Starr -Aura Aurora -Aura Ley -Aurora Dorea -Barba Rouse -Bea Constrictor -Bella Lush -Belle Icoza -Belle Ligerrente -Betty Brilliance -Bo Deysious -Carol Chorale -Cecil Clouds -Cecil Sunshine -Celeste Booday -Chichi Swank -Claire Geeman -Claire Rickal -Claire Voyance -Cleo Patrix -Connie Fidence -Corra Rageous -Daye Light -Deedee Cation -Deedee Sign -Dianne Gerous -Didi Divine -Diemme Monds -Dorothy Doughty -Dutches Dauntless -Ella Gance -Ella Gants -Ella Menterry -Ella Stique -Elle Lectrick -Elle Lure -Emma Geddon -Emma Phasis -Emma Rald -Emme Plosion -Emme Pulse -Emme Vention -Enna Fincible -Enne Phinite -Enne Treppide -Etha Nitty -Etha Reyal -Euphoria Bliss -Eva Nessent -Eve Forric -Eve Ningowne -Eve Ville -Faith Lesse -Faschia Nation -Faye Boulous -Faye Lacious -Faye Minine -Faye Nixx -Felicity Spice -Freya Domme -Gal Gallant -Gal Galore -Gal Lante -Gemma Safir -Gena Rocity -Genna Russ -Gigi Lamour -Gigi Rand -Glemma Rouss -Grace Iyus -Haye Light -Hazel Nutt -Hella Billy -Hella Centrique -Hella Cious -Hella Riouss -Hella Whole -Hellen Back -Herra Zee -Ina Creddeble -Ina Fernalle -Jo Nee -Jo Phial -Joye Ryde -Jue Cee -Jue Wells -Juju Bee -Kaia Cayenne -Kaye Bye -Kitsch Kitsch Bang Bang -Lady Lace -Lavish Lazuli -Lea Ness -Leye Berty -Lisse Truss -Liv Lee -Lola Lavish -Lolo Yaltie -Lucy Fur -Lucy Luck -Lulu LaBye -Lulu Xuri -Lunaye Clipse -Lyra Kall -Maggie Magma -Mara Bells -Marry Golds -Marry Nayde -Marry Sipan -Marve Vellus -Mary Ganal -Mary Malade -May Jestic -May Lancholly -May Licious -May Lodi -May Morable -May Stirius -May Varlous -Melody Gale -Melody Toune -Miss Adora -Miss Alure -Miss Chieff -Miss Fortune -Miss Mash -Miss Mood -Miss Nomer -Miss Sanguine -Miss Sublime -Mistress Galore -Monique Mystique -Morgan Fatana -Nashay Kitt -Nicole Lorful -Noë Stalgia -Ora Kelle -Ora Nate -Patty Siyens -Penny Laized -Penny Ramma -Penny Rammic -Penny Talloons -Percey Ferance -Perry Fomance -Phara Waye -Phata Morgana -Pho Latyle -Pho Lume -Phoebe Rant -Phoenix Bright -Pippa Pepper -Pippa Pizazz -Polly Tickle -Poppy Corn -Poppy Cox -Poppy Domm -Poppy Larr -Poppy Lerry -Poppy Sickles -Portia Bella -Portia Nette -Pria Steegious -Pria Steen -Prissa Teen -Raye Bitt -Raye Diante -Raye Nessance -Raye Storm -Remi Nissent -Rey Mantique -Rey Markeble -Rey Moorse -Rey Torric -Rococo Jazz -Roma Ence -Rose Budd -Ruby Redd -Ruby Ree -Ruth Lezz -Sall Laikeen -Sall Lay -Sally Ness -Sam Armie -Sam Ooth -Sara Castique -Sara Donique -Sara Penth -Sarah Pentine -Sarah Reen -Sasha Sass -Satty Phection -Sella Fish -Sella Stice -Selly Foxx -Senna Guinne -Senna Seer -Shia Mirring -Sia Dellic -Sia Dowe -Siam Pathy -Silver Foxx -Siri Price -Sofie Moore -Sofie Stication -Su Blime -Sue Burben -Sue Missif -Sue Pernova -Sue Preem -Super Nova -Suse Pense -Suzu Blime -Temma Tation -Tempest Wilde -Terra Gique -Thea Terre -Tina Cious -Tina Scious -Tira Mendus -Tira Quoise -Trinity Quart -Trixie Foxx -Tye Gress -Tye Phun -Vall Canno -Vall Iant -Vall Orous -Vanity Fairchild -Vicki Tory -Vivi Venus -Vivian Foxx -Vye Vacius -Zahara Dessert - diff --git a/bot/seasons/pride/drag_queen_name.py b/bot/seasons/pride/drag_queen_name.py index 8f0219f3..43813fbd 100644 --- a/bot/seasons/pride/drag_queen_name.py +++ b/bot/seasons/pride/drag_queen_name.py @@ -1,3 +1,4 @@ +import json import logging import random from pathlib import Path @@ -17,8 +18,8 @@ class DragNames(commands.Cog): @staticmethod def load_names() -> list: """Loads a list of drag queen names.""" - with open(Path("bot/resources/pride/drag_queen_names.txt"), "r", encoding="utf-8") as f: - return f.readlines() + with open(Path("bot/resources/pride/drag_queen_names.json"), "r", encoding="utf-8") as f: + return json.load(f) @commands.command(name="dragname", aliases=["dragqueenname", "queenme"]) async def dragname(self, ctx: commands.Context) -> None: -- cgit v1.2.3 From 15ad5e5e689f5769ff8419466c96207cd5efec0d Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Thu, 3 Oct 2019 00:18:57 -0400 Subject: Add pride facts for 2020 --- bot/resources/pride/facts.json | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 bot/resources/pride/facts.json (limited to 'bot') diff --git a/bot/resources/pride/facts.json b/bot/resources/pride/facts.json new file mode 100644 index 00000000..0b7a4358 --- /dev/null +++ b/bot/resources/pride/facts.json @@ -0,0 +1,34 @@ +{ + "2020": [ + "No research has conclusively proven what causes homosexuality, heterosexuality, or bisexuality.", + "Records of same-sex relationships have been found in nearly every culture throughout history with varying degrees of acceptance.", + "Various slurs targeting queer people have been reappropriated by them, notably \"dyke\", and \"queer\".", + "October 8th is lesbian pride day!", + "Historians note that in some cultures, some homosexual behavior was not viewed as effeminate but as evidence of a man's masculinity. Examples include the Celtic and Greek cultures.", + "Every year for the past few decades, a greater percentage of people have identified as being homosexual or bisexual.", + "A large proportion of people, both in and out of the LGBTQ+ communities, do not believe bisexuality exists. This is known as bisexual erasure.", + "Queer people commit suicide are much more common in politically conservative regions, and also more common than non-queer people in general.", + "Stormé DeLarverie, a lesbian drag king, had a \"scuffle\" with the police which many claim is what kicked off the Stonewall Riots.", + "Gilbert Baker, also known as the “Gay Betsy Ross,” designed the rainbow flag, or Pride Flag, in San Francisco in 1978.", + "The rainbow pride flag is well-known, but there are flags for most labeled gender/sexual minorities.", + "In 1968, Dr. John Money performed the first complete male-to-female sex-change operation in the United States at Johns Hopkins University.", + "At the age of 24, Leonardo Da Vinci was arrested for having sex with a man. He was eventually acquitted.", + "Alfred Kinsey, the creator of the Kinsey scale, is known as \"the father of the sexual revolution\". The Kinsey scale was created in order to demonstrate that sexuality does not fit into two strict categories: homosexual and heterosexual. Instead, Kinsey believed that sexuality is fluid and subject to change over time.", + "The Kinsey scale ranges from 0, which is exclusively heterosexual, to 6, which is exclusively homosexual.", + "November 20th is the Transgender Day of Remembrance, which is a day to memorialize those who have been murdered as a result of transphobia.", + "The pink triangle was the symbol that queer people were required to wear in Nazi concentration camps during WWII. The symbol has since been reclaimed as a positive symbol of self-identity.", + "The term \"AC/DC\" has been used to refer to bisexuals.", + "September 23rd is bisexual pride day!", + "Pride Day refers to celebrations that typically take place in June that commemorate the Stonewall Inn riots of June 28, 1969. These riots are considered the birth of the modern gay civil rights movement.", + "A \"beard\" is someone of the opposite sex who knowingly dates a closeted lesbian or gay man to provide that person with a heterosexual \"disguise\", usually for family or career purposes.", + "In Nigeria, where homosexuality is punishable by death by stoning, a post-grad student claimed he had proved being gay was wrong by using magnets. He hoped to win a Nobel Prize for his research. He has not received one.", + "In 1982, the Gay Related Immune Disorder (GRID) was renamed Acquired Immune Deficiency Syndrome (AIDS).", + "The word \"lesbian\" is derived from the Greek island Lesbos, home of Greek poet Sappho. Her poetry proclaimed her love for women, and their beauty.", + "Nearly all bonobos (a kind of chimpanzee) appear to be bisexual.", + "Homosexual behavior has been observed in 1,500 animal species and is most widespread among animals with a complex herd life.", + "Many queer people identify their sexual orientation independently from their romantic orientation. For instance, it is possible to be sexually attracted to both women and men, but only be romantically attracted to one of them.", + "In 2005, Swedish researchers found that when straight men smelled a female urine compound, their hypothalamus lit up in brain images. In gay men, it did not. Instead, homosexual men's hypothalamus lit up when they smelled the male-sweat compound, which was the same way straight women responded.", + "As of 2019-10-02, there are 17 states in the United States of America where queer people can be fired for being queer. In most other states, there is minimal protection offered, often only for public employees.", + "In 1985, an official Star Trek novel was published with scenes depicting Kirk and Spock as lovers. These parts were largely removed, which made the original into a collector's item." + ] +} \ No newline at end of file -- cgit v1.2.3 From 1ef715bd24a08abb6b2c9b9a23edb46ac9838787 Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Thu, 3 Oct 2019 03:08:36 -0400 Subject: Add pride facts cog --- bot/seasons/pride/pride_facts.py | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 bot/seasons/pride/pride_facts.py (limited to 'bot') diff --git a/bot/seasons/pride/pride_facts.py b/bot/seasons/pride/pride_facts.py new file mode 100644 index 00000000..90804d65 --- /dev/null +++ b/bot/seasons/pride/pride_facts.py @@ -0,0 +1,83 @@ +from datetime import datetime +import json +import logging +from typing import Union +import random +from pathlib import Path + +import dateutil.parser +from discord.ext import commands + +log = logging.getLogger(__name__) + + +class PrideFacts(commands.Cog): + """Provides a new fact every day during the Pride season!""" + + def __init__(self, bot: commands.Bot): + self.bot = bot + self.facts = self.load_facts() + + @staticmethod + def load_facts() -> dict: + """Loads a dictionary of years mapping to lists of facts.""" + with open(Path("bot/resources/pride/facts.json"), "r", encoding="utf-8") as f: + return json.load(f) + + async def random_fact(self, ctx: commands.Context): + """Provides a fact from any valid day.""" + now = datetime.utcnow() + previous_years_facts = (self.facts[x] for x in self.facts.keys() if int(x) < now.year) + current_year_facts = self.facts.get(str(now.year), [])[:now.day] + previous_facts = current_year_facts + [x for y in previous_years_facts for x in y] + try: + await ctx.send(random.choice(previous_facts)) + except IndexError: + await ctx.send("No facts available") + + async def select_fact(self, ctx: commands.Context, _date: Union[str, datetime]): + """Provides the fact for the specified day, if valid.""" + now = datetime.utcnow() + if isinstance(_date, str): + try: + date = dateutil.parser.parse(_date, dayfirst=True, fuzzy=True) + except (ValueError, OverflowError) as err: + await ctx.send(f"Error parsing date: {err}") + return + else: + date = _date + if date.year < now.year or (date.year == now.year and date.day <= now.day): + try: + await ctx.send(self.facts[str(date.year)][date.day - 1]) + except KeyError: + await ctx.send(f"The year {date.year} is not yet supported") + return + except IndexError: + await ctx.send(f"Day {date.day} of {date.year} is not yet support") + return + else: + await ctx.send("The fact for the selected day is not yet available.") + + @commands.command(name="pridefact", aliases=["pridefacts"]) + async def pridefact(self, ctx: commands.Context) -> None: + """ + Sends a message with a pride fact of the day. + + If "random" is given as an argument, a random previous fact will be provided. + + If a date is given as an argument, and the date is in the past, the fact from that day + will be provided. + """ + message_body = ctx.message.content[len(ctx.invoked_with) + 2:] + if message_body == "": + await self.select_fact(ctx, datetime.utcnow()) + elif message_body.lower().startswith("rand"): + await self.random_fact(ctx) + else: + await self.select_fact(ctx, message_body) + + +def setup(bot: commands.Bot) -> None: + """Cog loader for pride facts.""" + bot.add_cog(PrideFacts(bot)) + log.info("Pride facts cog loaded!") -- cgit v1.2.3 From 000110847972c6d74f57830737f599e0efe9bd3e Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Thu, 3 Oct 2019 03:28:22 -0400 Subject: Minor improvements for pride facts cog --- bot/resources/pride/facts.json | 6 +++--- bot/seasons/pride/pride_facts.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/resources/pride/facts.json b/bot/resources/pride/facts.json index 0b7a4358..f6597201 100644 --- a/bot/resources/pride/facts.json +++ b/bot/resources/pride/facts.json @@ -3,11 +3,11 @@ "No research has conclusively proven what causes homosexuality, heterosexuality, or bisexuality.", "Records of same-sex relationships have been found in nearly every culture throughout history with varying degrees of acceptance.", "Various slurs targeting queer people have been reappropriated by them, notably \"dyke\", and \"queer\".", - "October 8th is lesbian pride day!", - "Historians note that in some cultures, some homosexual behavior was not viewed as effeminate but as evidence of a man's masculinity. Examples include the Celtic and Greek cultures.", - "Every year for the past few decades, a greater percentage of people have identified as being homosexual or bisexual.", + "Historians note that in some cultures, some homosexual behavior was not viewed as effeminate, but as evidence of a man's masculinity. Examples include the Celtic and Greek cultures.", + "Over time, the proportion of people who identify as homosexual or bisexual appears to be increasing. It is not know if this is because they feel it is safer to come out, or if the actual numbers of homosexual/bisexual people are increasing.", "A large proportion of people, both in and out of the LGBTQ+ communities, do not believe bisexuality exists. This is known as bisexual erasure.", "Queer people commit suicide are much more common in politically conservative regions, and also more common than non-queer people in general.", + "October 8th is lesbian pride day!", "Stormé DeLarverie, a lesbian drag king, had a \"scuffle\" with the police which many claim is what kicked off the Stonewall Riots.", "Gilbert Baker, also known as the “Gay Betsy Ross,” designed the rainbow flag, or Pride Flag, in San Francisco in 1978.", "The rainbow pride flag is well-known, but there are flags for most labeled gender/sexual minorities.", diff --git a/bot/seasons/pride/pride_facts.py b/bot/seasons/pride/pride_facts.py index 90804d65..d691b7e7 100644 --- a/bot/seasons/pride/pride_facts.py +++ b/bot/seasons/pride/pride_facts.py @@ -40,7 +40,7 @@ class PrideFacts(commands.Cog): now = datetime.utcnow() if isinstance(_date, str): try: - date = dateutil.parser.parse(_date, dayfirst=True, fuzzy=True) + date = dateutil.parser.parse(_date, dayfirst=False, yearfirst=False, fuzzy=True) except (ValueError, OverflowError) as err: await ctx.send(f"Error parsing date: {err}") return -- cgit v1.2.3 From 76caa7577230a9a5617c9ea9ba28190b2082b571 Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Thu, 3 Oct 2019 03:46:29 -0400 Subject: Fix linter issues I don't understand why these linter issues don't come up when I run flake8 myself --- bot/seasons/pride/pride_facts.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/seasons/pride/pride_facts.py b/bot/seasons/pride/pride_facts.py index d691b7e7..3673fa95 100644 --- a/bot/seasons/pride/pride_facts.py +++ b/bot/seasons/pride/pride_facts.py @@ -1,8 +1,8 @@ -from datetime import datetime import json +from datetime import datetime import logging -from typing import Union import random +from typing import Union from pathlib import Path import dateutil.parser @@ -24,7 +24,7 @@ class PrideFacts(commands.Cog): with open(Path("bot/resources/pride/facts.json"), "r", encoding="utf-8") as f: return json.load(f) - async def random_fact(self, ctx: commands.Context): + async def random_fact(self, ctx: commands.Context) -> None: """Provides a fact from any valid day.""" now = datetime.utcnow() previous_years_facts = (self.facts[x] for x in self.facts.keys() if int(x) < now.year) @@ -35,7 +35,7 @@ class PrideFacts(commands.Cog): except IndexError: await ctx.send("No facts available") - async def select_fact(self, ctx: commands.Context, _date: Union[str, datetime]): + async def select_fact(self, ctx: commands.Context, _date: Union[str, datetime]) -> None: """Provides the fact for the specified day, if valid.""" now = datetime.utcnow() if isinstance(_date, str): -- cgit v1.2.3 From c03db25cfda6e5bf302c1fcd8ad682422ad144bf Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Thu, 3 Oct 2019 03:49:40 -0400 Subject: Fix linter issues --- bot/seasons/pride/pride_facts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/seasons/pride/pride_facts.py b/bot/seasons/pride/pride_facts.py index 3673fa95..95ca4d24 100644 --- a/bot/seasons/pride/pride_facts.py +++ b/bot/seasons/pride/pride_facts.py @@ -1,9 +1,9 @@ import json -from datetime import datetime import logging import random -from typing import Union +from datetime import datetime from pathlib import Path +from typing import Union import dateutil.parser from discord.ext import commands -- cgit v1.2.3 From 2e89209053713af46bfae832ce4d5f74188683e0 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Thu, 3 Oct 2019 17:58:47 +0100 Subject: Resloved requested changes --- bot/seasons/evergreen/issues.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index a6fe7b57..d41467e8 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -11,7 +11,7 @@ icons = {"issue": "https://i.imgur.com/HFV0nv9.png", "pull-request-closed": "https://i.imgur.com/JYmTn5P.png", "merge": "https://i.imgur.com/xzQZxXe.png"} -respValue = {404: "Issue/pull request not located! Please enter a valid number!", +RESP_VALUE = {404: "Issue/pull request not located! Please enter a valid number!", 403: "rate limit has been hit! Please try again later!"} @@ -22,7 +22,8 @@ class Issues(commands.Cog): self.bot = bot @commands.command(aliases=("pr",)) - async def issues(self, ctx: commands.Context, number: int, repository: str = "seasonalbot", + @override_in_channel() + async def issue(self, ctx: commands.Context, number: int, repository: str = "seasonalbot", user: str = "python-discord") -> None: """Command to get issues/pull request from GitHub.""" url = f"https://api.github.com/repos/{user}/{repository}/issues/{str(number)}" @@ -31,8 +32,8 @@ class Issues(commands.Cog): async with self.bot.http_session.get(url) as r: json_data = await r.json() - if r.status in respValue: - return await ctx.send(f"[{str(r.status)}] {respValue.get(r.status)}") + if r.status in RESP_VALUE: + return await ctx.send(f"[{str(r.status)}] {RESP_VALUE.get(r.status)}") if "issues" in json_data.get("html_url"): if json_data.get("state") == "open": @@ -43,8 +44,10 @@ class Issues(commands.Cog): async with self.bot.http_session.get(mergeURL) as m: if json_data.get("state") == "open": iconURL = icons.get("pull-request") + # when the status is 204 this means that the state of the PR is merged elif m.status == 204: iconURL = icons.get("merge") + # else by the process of elimination, the pull request has been closed else: iconURL = icons.get("pull-request-closed") -- cgit v1.2.3 From 3492e0871d08523755ecc62c3e1559617d5360d4 Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Thu, 3 Oct 2019 13:17:21 -0400 Subject: Add task to post daily pride fact Also, pride facts are posted as embeds now --- bot/seasons/pride/pride_facts.py | 49 +++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'bot') diff --git a/bot/seasons/pride/pride_facts.py b/bot/seasons/pride/pride_facts.py index 95ca4d24..d2ea0461 100644 --- a/bot/seasons/pride/pride_facts.py +++ b/bot/seasons/pride/pride_facts.py @@ -1,3 +1,4 @@ +import asyncio import json import logging import random @@ -6,10 +7,16 @@ from pathlib import Path from typing import Union import dateutil.parser +import discord from discord.ext import commands +from bot.constants import Channels +from bot.constants import Colours + log = logging.getLogger(__name__) +Sendable = Union[commands.Context, discord.TextChannel] + class PrideFacts(commands.Cog): """Provides a new fact every day during the Pride season!""" @@ -24,39 +31,46 @@ class PrideFacts(commands.Cog): with open(Path("bot/resources/pride/facts.json"), "r", encoding="utf-8") as f: return json.load(f) - async def random_fact(self, ctx: commands.Context) -> None: - """Provides a fact from any valid day.""" + async def send_pride_fact_daily(self) -> None: + """Background task to post the daily pride fact every day.""" + channel = self.bot.get_channel(Channels.seasonalbot_chat) + while True: + await self.send_select_fact(channel, datetime.utcnow()) + await asyncio.sleep(24 * 60 * 60) + + async def send_random_fact(self, ctx: commands.Context) -> None: + """Provides a fact from any previous day, or today.""" now = datetime.utcnow() previous_years_facts = (self.facts[x] for x in self.facts.keys() if int(x) < now.year) current_year_facts = self.facts.get(str(now.year), [])[:now.day] previous_facts = current_year_facts + [x for y in previous_years_facts for x in y] try: - await ctx.send(random.choice(previous_facts)) + await ctx.send(embed=self.make_embed(random.choice(previous_facts))) except IndexError: await ctx.send("No facts available") - async def select_fact(self, ctx: commands.Context, _date: Union[str, datetime]) -> None: - """Provides the fact for the specified day, if valid.""" + async def send_select_fact(self, target: Sendable, _date: Union[str, datetime]) -> None: + """Provides the fact for the specified day, if the day is today, or is in the past.""" now = datetime.utcnow() if isinstance(_date, str): try: date = dateutil.parser.parse(_date, dayfirst=False, yearfirst=False, fuzzy=True) except (ValueError, OverflowError) as err: - await ctx.send(f"Error parsing date: {err}") + await target.send(f"Error parsing date: {err}") return else: date = _date if date.year < now.year or (date.year == now.year and date.day <= now.day): try: - await ctx.send(self.facts[str(date.year)][date.day - 1]) + await target.send(embed=self.make_embed(self.facts[str(date.year)][date.day - 1])) except KeyError: - await ctx.send(f"The year {date.year} is not yet supported") + await target.send(f"The year {date.year} is not yet supported") return except IndexError: - await ctx.send(f"Day {date.day} of {date.year} is not yet support") + await target.send(f"Day {date.day} of {date.year} is not yet support") return else: - await ctx.send("The fact for the selected day is not yet available.") + await target.send("The fact for the selected day is not yet available.") @commands.command(name="pridefact", aliases=["pridefacts"]) async def pridefact(self, ctx: commands.Context) -> None: @@ -70,14 +84,23 @@ class PrideFacts(commands.Cog): """ message_body = ctx.message.content[len(ctx.invoked_with) + 2:] if message_body == "": - await self.select_fact(ctx, datetime.utcnow()) + await self.send_select_fact(ctx, datetime.utcnow()) elif message_body.lower().startswith("rand"): - await self.random_fact(ctx) + await self.send_random_fact(ctx) else: - await self.select_fact(ctx, message_body) + await self.send_select_fact(ctx, message_body) + + def make_embed(self, fact) -> discord.Embed: + """Makes a nice embed for the fact to be sent.""" + return discord.Embed( + colour=Colours.pink, + title="Pride Fact!", + description=fact + ) def setup(bot: commands.Bot) -> None: """Cog loader for pride facts.""" + bot.loop.create_task(PrideFacts(bot).send_pride_fact_daily()) bot.add_cog(PrideFacts(bot)) log.info("Pride facts cog loaded!") -- cgit v1.2.3 From fb15e331d794c204db74f506f91828699c4f5968 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Thu, 3 Oct 2019 18:22:33 +0100 Subject: Flake8 Fixing --- bot/seasons/evergreen/issues.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index d41467e8..708f5d15 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -3,6 +3,8 @@ import logging import discord from discord.ext import commands +from bot.decorators import override_in_channel + log = logging.getLogger(__name__) icons = {"issue": "https://i.imgur.com/HFV0nv9.png", @@ -12,7 +14,7 @@ icons = {"issue": "https://i.imgur.com/HFV0nv9.png", "merge": "https://i.imgur.com/xzQZxXe.png"} RESP_VALUE = {404: "Issue/pull request not located! Please enter a valid number!", - 403: "rate limit has been hit! Please try again later!"} + 403: "rate limit has been hit! Please try again later!"} class Issues(commands.Cog): @@ -24,7 +26,7 @@ class Issues(commands.Cog): @commands.command(aliases=("pr",)) @override_in_channel() async def issue(self, ctx: commands.Context, number: int, repository: str = "seasonalbot", - user: str = "python-discord") -> None: + user: str = "python-discord") -> None: """Command to get issues/pull request from GitHub.""" url = f"https://api.github.com/repos/{user}/{repository}/issues/{str(number)}" mergeURL = f"https://api.github.com/repos/{user}/{repository}/pulls/{str(number)}/merge" -- cgit v1.2.3 From bcfe86418da57a0c66fc077c1607171b29448aca Mon Sep 17 00:00:00 2001 From: Will Da Silva Date: Thu, 3 Oct 2019 13:34:11 -0400 Subject: Fix linter issue --- bot/seasons/pride/pride_facts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/pride/pride_facts.py b/bot/seasons/pride/pride_facts.py index d2ea0461..b705bfb4 100644 --- a/bot/seasons/pride/pride_facts.py +++ b/bot/seasons/pride/pride_facts.py @@ -90,7 +90,7 @@ class PrideFacts(commands.Cog): else: await self.send_select_fact(ctx, message_body) - def make_embed(self, fact) -> discord.Embed: + def make_embed(self, fact: str) -> discord.Embed: """Makes a nice embed for the fact to be sent.""" return discord.Embed( colour=Colours.pink, -- cgit v1.2.3 From c2df3759d697db782f9553b7fdef646291f427e9 Mon Sep 17 00:00:00 2001 From: Numerlor Date: Thu, 3 Oct 2019 20:11:59 +0200 Subject: limit issue command to global whitelist and seasonalbot_chat --- bot/seasons/evergreen/issues.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 438ab475..08d78e30 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -3,10 +3,11 @@ import logging import discord from discord.ext import commands -from bot.constants import Colours +from bot.constants import Channels, Colours, WHITELISTED_CHANNELS from bot.decorators import override_in_channel log = logging.getLogger(__name__) +ISSUE_WHITELIST = WHITELISTED_CHANNELS + (Channels.seasonalbot_chat,) class Issues(commands.Cog): @@ -16,7 +17,7 @@ class Issues(commands.Cog): self.bot = bot @commands.command(aliases=("issues",)) - @override_in_channel() + @override_in_channel(ISSUE_WHITELIST) async def issue( self, ctx: commands.Context, number: int, repository: str = "seasonalbot", user: str = "python-discord" ) -> None: -- cgit v1.2.3 From eaf49758e7a175aeeeeafdb66c3c1a5fc96a4b10 Mon Sep 17 00:00:00 2001 From: Numerlor Date: Thu, 3 Oct 2019 20:21:39 +0200 Subject: add the adventofcode channel to Channels constant --- bot/constants.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bot') diff --git a/bot/constants.py b/bot/constants.py index 0d4321c8..c1722158 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -22,6 +22,7 @@ class AdventOfCode: class Channels(NamedTuple): admins = 365960823622991872 + advent_of_code = 517745814039166986 announcements = int(environ.get("CHANNEL_ANNOUNCEMENTS", 354619224620138496)) big_brother_logs = 468507907357409333 bot = 267659945086812160 -- cgit v1.2.3 From 9d6ea0f020a448cb1498f0c4eeb560858c510a69 Mon Sep 17 00:00:00 2001 From: Numerlor Date: Thu, 3 Oct 2019 20:27:09 +0200 Subject: limit Advent Of Code commands to global whitelist and the AoC channel --- bot/seasons/christmas/adventofcode.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 513c1020..a88e5ac3 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -13,7 +13,7 @@ from bs4 import BeautifulSoup from discord.ext import commands from pytz import timezone -from bot.constants import AdventOfCode as AocConfig, Channels, Colours, Emojis, Tokens +from bot.constants import AdventOfCode as AocConfig, Channels, Colours, Emojis, Tokens, WHITELISTED_CHANNELS from bot.decorators import override_in_channel log = logging.getLogger(__name__) @@ -24,6 +24,8 @@ AOC_SESSION_COOKIE = {"session": Tokens.aoc_session_cookie} EST = timezone("EST") COUNTDOWN_STEP = 60 * 5 +AOC_WHITELIST = WHITELISTED_CHANNELS + (Channels.advent_of_code,) + def is_in_advent() -> bool: """Utility function to check if we are between December 1st and December 25th.""" @@ -126,7 +128,7 @@ class AdventOfCode(commands.Cog): self.status_task = asyncio.ensure_future(self.bot.loop.create_task(status_coro)) @commands.group(name="adventofcode", aliases=("aoc",), invoke_without_command=True) - @override_in_channel() + @override_in_channel(AOC_WHITELIST) async def adventofcode_group(self, ctx: commands.Context) -> None: """All of the Advent of Code commands.""" await ctx.send_help(ctx.command) -- cgit v1.2.3 From bc866f5e5bdfe49318601a12c5bac8134d5c06be Mon Sep 17 00:00:00 2001 From: Numerlor Date: Fri, 4 Oct 2019 21:06:32 +0200 Subject: override global whitelist on all hacktober subcommands --- bot/seasons/halloween/hacktoberstats.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktoberstats.py b/bot/seasons/halloween/hacktoberstats.py index 9ad44e3f..ab8d865c 100644 --- a/bot/seasons/halloween/hacktoberstats.py +++ b/bot/seasons/halloween/hacktoberstats.py @@ -58,6 +58,7 @@ class HacktoberStats(commands.Cog): await self.get_stats(ctx, github_username) @hacktoberstats_group.command(name="link") + @override_in_channel(HACKTOBER_WHITELIST) async def link_user(self, ctx: commands.Context, github_username: str = None) -> None: """ Link the invoking user's Github github_username to their Discord ID. @@ -91,6 +92,7 @@ class HacktoberStats(commands.Cog): await ctx.send(f"{author_mention}, a GitHub username is required to link your account") @hacktoberstats_group.command(name="unlink") + @override_in_channel(HACKTOBER_WHITELIST) async def unlink_user(self, ctx: commands.Context) -> None: """Remove the invoking user's account link from the log.""" author_id, author_mention = HacktoberStats._author_mention_from_context(ctx) -- cgit v1.2.3 From a7c7fb7aacc477eb498c3872adf71d10cb798f67 Mon Sep 17 00:00:00 2001 From: vivax3794 <51753506+vivax3794@users.noreply.github.com> Date: Sat, 5 Oct 2019 06:30:48 +0200 Subject: added beginner --- bot/seasons/halloween/hacktober-issue-finder.py | 50 ++++++++++++++++++------- 1 file changed, 36 insertions(+), 14 deletions(-) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktober-issue-finder.py b/bot/seasons/halloween/hacktober-issue-finder.py index 54f205cf..3c4780a9 100644 --- a/bot/seasons/halloween/hacktober-issue-finder.py +++ b/bot/seasons/halloween/hacktober-issue-finder.py @@ -1,7 +1,7 @@ import datetime import logging import random -from typing import Dict, List +from typing import Dict, List, Optional import aiohttp import discord @@ -9,7 +9,7 @@ from discord.ext import commands log = logging.getLogger(__name__) -URL = "https://api.github.com/search/issues?q=label:hacktoberfest+language:python+state:open&per_page=100" +URL = "https://api.github.com/search/issues?per_page=100&q=is:issue+label:hacktoberfest+language:python+state:open" HEADERS = {"Accept": "application / vnd.github.v3 + json"} @@ -18,34 +18,55 @@ class HacktoberIssues(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot - self.cache = None - self.cache_timer = datetime.datetime(1, 1, 1) + self.cache_normal = None + self.cache_timer_normal = datetime.datetime(1, 1, 1) + self.cache_beginner = None + self.cache_timer_beginner = datetime.datetime(1, 1, 1) @commands.command() - async def hacktoberissues(self, ctx: commands.Context) -> None: + async def hacktoberissues(self, ctx: commands.Context, option: str = "") -> None: """Get a random python hacktober issue from Github.""" with ctx.typing(): - issues = await self.get_issues(ctx) + issues = await self.get_issues(ctx, option) + if issues is None: + return issue = random.choice(issues) embed = self.format_embed(issue) - await ctx.send(embed=embed) + await ctx.send(embed=embed) - async def get_issues(self, ctx: commands.Context) -> List[Dict]: + async def get_issues(self, ctx: commands.Context, option: str) -> Optional[List[Dict]]: """Get a list of the python issues with the label 'hacktoberfest' from the Github api.""" - if (ctx.message.created_at - self.cache_timer).seconds <= 60: - return self.cache + if option == "beginner": + if (ctx.message.created_at - self.cache_timer_beginner).seconds <= 60: + return self.cache_beginner + elif (ctx.message.created_at - self.cache_timer_normal).seconds <= 60: + return self.cache_normal async with aiohttp.ClientSession() as session: - # text = TEXT # + "+label:hacktober" + if option == "beginner": + url = URL + '+label:"good first issue"' + else: + url = URL - async with session.get(URL, headers=HEADERS) as response: + async with session.get(url, headers=HEADERS) as response: if response.status != 200: await ctx.send(f"ERROR: expected 200 status (got {response.status}) from the GitHub api.") await ctx.send(await response.text()) + return None data = await response.json() issues = data["items"] - self.cache = issues - self.cache_timer = ctx.message.created_at + + if len(issues) == 0: + await ctx.send(f"ERROR: no issues returned from GitHub api. with url: {response.url}") + return None + + if option == "beginner": + self.cache_beginner = issues + self.cache_timer_beginner = ctx.message.created_at + else: + self.cache_normal = issues + self.cache_timer_normal = ctx.message.created_at + return issues @staticmethod @@ -60,6 +81,7 @@ class HacktoberIssues(commands.Cog): embed.description = body embed.add_field(name="labels", value="\n".join(labels)) embed.url = issue_url + embed.set_footer(text=issue_url) return embed -- cgit v1.2.3 From cb90d1269dbad0a29fe0a03a7219428ff5a38f51 Mon Sep 17 00:00:00 2001 From: vivax3794 <51753506+vivax3794@users.noreply.github.com> Date: Sat, 5 Oct 2019 07:29:53 +0200 Subject: bug fixes --- bot/seasons/halloween/hacktober-issue-finder.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktober-issue-finder.py b/bot/seasons/halloween/hacktober-issue-finder.py index 3c4780a9..a9cff610 100644 --- a/bot/seasons/halloween/hacktober-issue-finder.py +++ b/bot/seasons/halloween/hacktober-issue-finder.py @@ -1,7 +1,7 @@ import datetime import logging import random -from typing import Dict, List, Optional +from typing import Dict, Optional import aiohttp import discord @@ -27,14 +27,14 @@ class HacktoberIssues(commands.Cog): async def hacktoberissues(self, ctx: commands.Context, option: str = "") -> None: """Get a random python hacktober issue from Github.""" with ctx.typing(): - issues = await self.get_issues(ctx, option) + issues = (await self.get_issues(ctx, option))["items"] if issues is None: return issue = random.choice(issues) embed = self.format_embed(issue) await ctx.send(embed=embed) - async def get_issues(self, ctx: commands.Context, option: str) -> Optional[List[Dict]]: + async def get_issues(self, ctx: commands.Context, option: str) -> Optional[Dict]: """Get a list of the python issues with the label 'hacktoberfest' from the Github api.""" if option == "beginner": if (ctx.message.created_at - self.cache_timer_beginner).seconds <= 60: @@ -45,8 +45,14 @@ class HacktoberIssues(commands.Cog): async with aiohttp.ClientSession() as session: if option == "beginner": url = URL + '+label:"good first issue"' + if self.cache_beginner is not None: + page = random.randint(1, min(1000, self.cache_beginner["total_count"]) // 100) + url += f"&page={page}" else: url = URL + if self.cache_normal is not None: + page = random.randint(1, min(1000, self.cache_normal["total_count"])) + url += f"&page={page}" async with session.get(url, headers=HEADERS) as response: if response.status != 200: @@ -54,20 +60,19 @@ class HacktoberIssues(commands.Cog): await ctx.send(await response.text()) return None data = await response.json() - issues = data["items"] - if len(issues) == 0: + if len(data["items"]) == 0: await ctx.send(f"ERROR: no issues returned from GitHub api. with url: {response.url}") return None if option == "beginner": - self.cache_beginner = issues + self.cache_beginner = data self.cache_timer_beginner = ctx.message.created_at else: - self.cache_normal = issues + self.cache_normal = data self.cache_timer_normal = ctx.message.created_at - return issues + return data @staticmethod def format_embed(issue: Dict) -> discord.Embed: -- cgit v1.2.3 From 9f176ee92273251177894335444efe7a6f103e3a Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Sun, 6 Oct 2019 18:15:47 +0100 Subject: Updated the explination of API calls --- bot/seasons/evergreen/issues.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 708f5d15..6c84ae2d 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -36,12 +36,19 @@ class Issues(commands.Cog): if r.status in RESP_VALUE: return await ctx.send(f"[{str(r.status)}] {RESP_VALUE.get(r.status)}") - + + # the original call is made to the issues API endpoint + # if a issue or PR exists then there will be something returned + # if the word 'issues' is present within the response then we can simply pull the data we need from the + # return data received from the API if "issues" in json_data.get("html_url"): if json_data.get("state") == "open": iconURL = icons.get("issue") else: iconURL = icons.get("issue_closed") + # if the word 'issues' is not contained within the returned data and there is no error code then we know that + # the requested data is a pr, hence to get the specifics on it we have to call the PR API endpoint allowing us + # to get the specific information in relation to the PR that is not provided via the issues endpoint else: async with self.bot.http_session.get(mergeURL) as m: if json_data.get("state") == "open": -- cgit v1.2.3 From bf265601ffd95d1f42b63c086b51b3ec519da344 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Sun, 6 Oct 2019 18:21:26 +0100 Subject: Lint error --- bot/seasons/evergreen/issues.py | 1 - 1 file changed, 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 6c84ae2d..6438c363 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -36,7 +36,6 @@ class Issues(commands.Cog): if r.status in RESP_VALUE: return await ctx.send(f"[{str(r.status)}] {RESP_VALUE.get(r.status)}") - # the original call is made to the issues API endpoint # if a issue or PR exists then there will be something returned # if the word 'issues' is present within the response then we can simply pull the data we need from the -- cgit v1.2.3 From 1f30799e0d6f27fe1f62a047a4b46a6fba8e9694 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Sun, 6 Oct 2019 18:32:10 +0100 Subject: Updated location of emojis --- bot/seasons/evergreen/issues.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 6438c363..fdf95d7e 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -7,11 +7,11 @@ from bot.decorators import override_in_channel log = logging.getLogger(__name__) -icons = {"issue": "https://i.imgur.com/HFV0nv9.png", - "issue-closed": "https://i.imgur.com/uZSX7as.png", - "pull-request": "https://i.imgur.com/zHhnALX.png", - "pull-request-closed": "https://i.imgur.com/JYmTn5P.png", - "merge": "https://i.imgur.com/xzQZxXe.png"} +icons = {"issue": "<:IssueOpen:629695470327037963>", + "issue-closed": "<:IssueClosed:629695470570307614>", + "pull-request": "<:PROpen:629695470175780875>", + "pull-request-closed": "<:PRClosed:629695470519713818>", + "merge": "<:PRMerged:629695470570176522>"} RESP_VALUE = {404: "Issue/pull request not located! Please enter a valid number!", 403: "rate limit has been hit! Please try again later!"} @@ -61,9 +61,8 @@ class Issues(commands.Cog): resp = discord.Embed(colour=0x6CC644) resp.set_author( - name=f"[{repository}] #{number} {json_data.get('title')}", - url=json_data.get("html_url"), - icon_url=iconURL) + name=f"{iconURL} | [{repository}] #{number} {json_data.get('title')}", + url=json_data.get("html_url")) await ctx.send(embed=resp) -- cgit v1.2.3 From 3e7f5904aed66ab753e5d186cfcd5f63adc58ede Mon Sep 17 00:00:00 2001 From: vivax3794 <51753506+vivax3794@users.noreply.github.com> Date: Mon, 7 Oct 2019 15:03:29 +0200 Subject: Added logging to "get_issues". --- bot/seasons/halloween/hacktober-issue-finder.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktober-issue-finder.py b/bot/seasons/halloween/hacktober-issue-finder.py index a9cff610..57273ee7 100644 --- a/bot/seasons/halloween/hacktober-issue-finder.py +++ b/bot/seasons/halloween/hacktober-issue-finder.py @@ -27,10 +27,10 @@ class HacktoberIssues(commands.Cog): async def hacktoberissues(self, ctx: commands.Context, option: str = "") -> None: """Get a random python hacktober issue from Github.""" with ctx.typing(): - issues = (await self.get_issues(ctx, option))["items"] + issues = await self.get_issues(ctx, option) if issues is None: return - issue = random.choice(issues) + issue = random.choice(issues["items"]) embed = self.format_embed(issue) await ctx.send(embed=embed) @@ -38,8 +38,10 @@ class HacktoberIssues(commands.Cog): """Get a list of the python issues with the label 'hacktoberfest' from the Github api.""" if option == "beginner": if (ctx.message.created_at - self.cache_timer_beginner).seconds <= 60: + log.debug("using cache") return self.cache_beginner elif (ctx.message.created_at - self.cache_timer_normal).seconds <= 60: + log.debug("using cache") return self.cache_normal async with aiohttp.ClientSession() as session: @@ -54,14 +56,17 @@ class HacktoberIssues(commands.Cog): page = random.randint(1, min(1000, self.cache_normal["total_count"])) url += f"&page={page}" + log.debug(f"making api request to url: {url}") async with session.get(url, headers=HEADERS) as response: if response.status != 200: + log.error(f"expected 200 status (got {response.status}) from the GitHub api.") await ctx.send(f"ERROR: expected 200 status (got {response.status}) from the GitHub api.") await ctx.send(await response.text()) return None data = await response.json() if len(data["items"]) == 0: + log.error(f"no issues returned from GitHub api. with url: {response.url}") await ctx.send(f"ERROR: no issues returned from GitHub api. with url: {response.url}") return None -- cgit v1.2.3 From fd01d17a5c29f626c5dc37bfcf5df0a1bd6a17d1 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Mon, 7 Oct 2019 16:42:57 +0100 Subject: Made use of constants file instead of hard coding --- bot/seasons/evergreen/issues.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index fdf95d7e..c764cd57 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -3,15 +3,16 @@ import logging import discord from discord.ext import commands +from bot.constants import Emojis from bot.decorators import override_in_channel log = logging.getLogger(__name__) -icons = {"issue": "<:IssueOpen:629695470327037963>", - "issue-closed": "<:IssueClosed:629695470570307614>", - "pull-request": "<:PROpen:629695470175780875>", - "pull-request-closed": "<:PRClosed:629695470519713818>", - "merge": "<:PRMerged:629695470570176522>"} +icons = {"issue": Emojis.issue, + "issue-closed": Emojis.issue_closed, + "pull-request": Emojis.pull_request, + "pull-request-closed": Emojis.pull_request_closed, + "merge": Emojis.merge} RESP_VALUE = {404: "Issue/pull request not located! Please enter a valid number!", 403: "rate limit has been hit! Please try again later!"} -- cgit v1.2.3 From 960ed42684c2d5a49464c4bc68c52ad5d94edc28 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Mon, 7 Oct 2019 16:43:21 +0100 Subject: Added GitHub emojis to constants file --- bot/constants.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'bot') diff --git a/bot/constants.py b/bot/constants.py index 0d4321c8..124c48ae 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -86,6 +86,12 @@ class Emojis: terning5 = "<:terning5:431249716328792064>" terning6 = "<:terning6:431249726705369098>" + issue = "<:IssueOpen:629695470327037963>", + issue_closed = "<:IssueClosed:629695470570307614>", + pull_request = "<:PROpen:629695470175780875>", + pull_request_closed = "<:PRClosed:629695470519713818>", + merge = "<:PRMerged:629695470570176522>" + class Lovefest: role_id = int(environ.get("LOVEFEST_ROLE_ID", 542431903886606399)) -- cgit v1.2.3 From 11c4ceac19e2f82becc9d206f164a5b2914f2169 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Mon, 7 Oct 2019 16:46:13 +0100 Subject: Made use of constants for colours --- bot/seasons/evergreen/issues.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index c764cd57..5f1dcfb6 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -3,6 +3,7 @@ import logging import discord from discord.ext import commands +from bot.constants import Colours from bot.constants import Emojis from bot.decorators import override_in_channel @@ -60,7 +61,7 @@ class Issues(commands.Cog): else: iconURL = icons.get("pull-request-closed") - resp = discord.Embed(colour=0x6CC644) + resp = discord.Embed(colour=Colours.bright_green) resp.set_author( name=f"{iconURL} | [{repository}] #{number} {json_data.get('title')}", url=json_data.get("html_url")) -- cgit v1.2.3 From fc6dc955cf41c3f0b18927b22d8d46fd18a847d6 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Mon, 7 Oct 2019 22:52:33 +0100 Subject: Trailing Commas Removed --- bot/constants.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/constants.py b/bot/constants.py index 124c48ae..e0195961 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -86,10 +86,10 @@ class Emojis: terning5 = "<:terning5:431249716328792064>" terning6 = "<:terning6:431249726705369098>" - issue = "<:IssueOpen:629695470327037963>", - issue_closed = "<:IssueClosed:629695470570307614>", - pull_request = "<:PROpen:629695470175780875>", - pull_request_closed = "<:PRClosed:629695470519713818>", + issue = "<:IssueOpen:629695470327037963>" + issue_closed = "<:IssueClosed:629695470570307614>" + pull_request = "<:PROpen:629695470175780875>" + pull_request_closed = "<:PRClosed:629695470519713818>" merge = "<:PRMerged:629695470570176522>" -- cgit v1.2.3 From 6f3a6241d1e5931cdbc3fb1d35a19d3885431ca9 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Mon, 7 Oct 2019 22:57:10 +0100 Subject: Constants match pep8 formatting --- bot/seasons/evergreen/issues.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 5f1dcfb6..0a9e1e09 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -9,11 +9,11 @@ from bot.decorators import override_in_channel log = logging.getLogger(__name__) -icons = {"issue": Emojis.issue, - "issue-closed": Emojis.issue_closed, - "pull-request": Emojis.pull_request, - "pull-request-closed": Emojis.pull_request_closed, - "merge": Emojis.merge} +icons = {"ISSUE": Emojis.issue, + "ISSUE_CLOSED": Emojis.issue_closed, + "PULL_REQUEST": Emojis.pull_request, + "PULL_REQUEST_CLOSED": Emojis.pull_request_closed, + "MERGE": Emojis.merge} RESP_VALUE = {404: "Issue/pull request not located! Please enter a valid number!", 403: "rate limit has been hit! Please try again later!"} @@ -44,22 +44,22 @@ class Issues(commands.Cog): # return data received from the API if "issues" in json_data.get("html_url"): if json_data.get("state") == "open": - iconURL = icons.get("issue") + iconURL = icons.get("ISSUE") else: - iconURL = icons.get("issue_closed") + iconURL = icons.get("ISSUE_CLOSED") # if the word 'issues' is not contained within the returned data and there is no error code then we know that # the requested data is a pr, hence to get the specifics on it we have to call the PR API endpoint allowing us # to get the specific information in relation to the PR that is not provided via the issues endpoint else: async with self.bot.http_session.get(mergeURL) as m: if json_data.get("state") == "open": - iconURL = icons.get("pull-request") + iconURL = icons.get("PULL_REQUEST") # when the status is 204 this means that the state of the PR is merged elif m.status == 204: - iconURL = icons.get("merge") + iconURL = icons.get("MERGE") # else by the process of elimination, the pull request has been closed else: - iconURL = icons.get("pull-request-closed") + iconURL = icons.get("PULL_REQUEST_CLOSED") resp = discord.Embed(colour=Colours.bright_green) resp.set_author( -- cgit v1.2.3 From db87246ebd8958479d8a29fb6cd21fec0af1cde7 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Mon, 7 Oct 2019 22:58:54 +0100 Subject: Condensed imports --- bot/seasons/evergreen/issues.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 0a9e1e09..e836ead9 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -3,8 +3,7 @@ import logging import discord from discord.ext import commands -from bot.constants import Colours -from bot.constants import Emojis +from bot.constants import Colours, Emojis from bot.decorators import override_in_channel log = logging.getLogger(__name__) -- cgit v1.2.3 From f6e9d15ec2ad648ea8c992f9574740ec9137becf Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Wed, 9 Oct 2019 18:22:27 +0100 Subject: Fixed emoji error in embed --- bot/seasons/evergreen/issues.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index e836ead9..9713cfbd 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -8,7 +8,7 @@ from bot.decorators import override_in_channel log = logging.getLogger(__name__) -icons = {"ISSUE": Emojis.issue, +ICONS = {"ISSUE": Emojis.issue, "ISSUE_CLOSED": Emojis.issue_closed, "PULL_REQUEST": Emojis.pull_request, "PULL_REQUEST_CLOSED": Emojis.pull_request_closed, @@ -43,27 +43,30 @@ class Issues(commands.Cog): # return data received from the API if "issues" in json_data.get("html_url"): if json_data.get("state") == "open": - iconURL = icons.get("ISSUE") + iconURL = ICONS.get("ISSUE") else: - iconURL = icons.get("ISSUE_CLOSED") + iconURL = ICONS.get("ISSUE_CLOSED") # if the word 'issues' is not contained within the returned data and there is no error code then we know that # the requested data is a pr, hence to get the specifics on it we have to call the PR API endpoint allowing us # to get the specific information in relation to the PR that is not provided via the issues endpoint else: async with self.bot.http_session.get(mergeURL) as m: if json_data.get("state") == "open": - iconURL = icons.get("PULL_REQUEST") + iconURL = ICONS.get("PULL_REQUEST") # when the status is 204 this means that the state of the PR is merged elif m.status == 204: - iconURL = icons.get("MERGE") + iconURL = ICONS.get("MERGE") # else by the process of elimination, the pull request has been closed else: - iconURL = icons.get("PULL_REQUEST_CLOSED") + iconURL = ICONS.get("PULL_REQUEST_CLOSED") - resp = discord.Embed(colour=Colours.bright_green) - resp.set_author( - name=f"{iconURL} | [{repository}] #{number} {json_data.get('title')}", - url=json_data.get("html_url")) + issue_url = json_data.get("html_url") + description_text = f"[{repository}] #{number} {json_data.get('title')}" + resp = discord.Embed( + colour=Colours.bright_green, + description=f"{iconURL} [{description_text}]({issue_url})" + ) + resp.set_author(name="GitHub", url=issue_url) await ctx.send(embed=resp) -- cgit v1.2.3 From d38f7c384487c5ee3da9fca1cff8df5dfb84ec21 Mon Sep 17 00:00:00 2001 From: vivax3794 <51753506+vivax3794@users.noreply.github.com> Date: Sat, 12 Oct 2019 02:18:32 +0200 Subject: Added Beginner to docstring. --- bot/seasons/halloween/hacktober-issue-finder.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktober-issue-finder.py b/bot/seasons/halloween/hacktober-issue-finder.py index 57273ee7..5978eb95 100644 --- a/bot/seasons/halloween/hacktober-issue-finder.py +++ b/bot/seasons/halloween/hacktober-issue-finder.py @@ -25,7 +25,12 @@ class HacktoberIssues(commands.Cog): @commands.command() async def hacktoberissues(self, ctx: commands.Context, option: str = "") -> None: - """Get a random python hacktober issue from Github.""" + """ + Get a random python hacktober issue from Github. + + If the command is run with beginner (`!hacktoberissues beginner`): + It will also narrow it down to the "first good issue label". + """ with ctx.typing(): issues = await self.get_issues(ctx, option) if issues is None: -- cgit v1.2.3 From 2ed67377928c55ab766e08c17e392eae5667f0e9 Mon Sep 17 00:00:00 2001 From: vivax3794 <51753506+vivax3794@users.noreply.github.com> Date: Sat, 12 Oct 2019 02:19:14 +0200 Subject: fixed " misplace meant. --- bot/seasons/halloween/hacktober-issue-finder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktober-issue-finder.py b/bot/seasons/halloween/hacktober-issue-finder.py index 5978eb95..8b8ea41d 100644 --- a/bot/seasons/halloween/hacktober-issue-finder.py +++ b/bot/seasons/halloween/hacktober-issue-finder.py @@ -29,7 +29,7 @@ class HacktoberIssues(commands.Cog): Get a random python hacktober issue from Github. If the command is run with beginner (`!hacktoberissues beginner`): - It will also narrow it down to the "first good issue label". + It will also narrow it down to the "first good issue" label. """ with ctx.typing(): issues = await self.get_issues(ctx, option) -- cgit v1.2.3 From fd1a2a68139f83a2313e18ec42cba1b4f9220e7c Mon Sep 17 00:00:00 2001 From: vivax3794 <51753506+vivax3794@users.noreply.github.com> Date: Sat, 12 Oct 2019 02:22:45 +0200 Subject: had the wrong prefix in docstring xD --- bot/seasons/halloween/hacktober-issue-finder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktober-issue-finder.py b/bot/seasons/halloween/hacktober-issue-finder.py index 8b8ea41d..2f1d6ac7 100644 --- a/bot/seasons/halloween/hacktober-issue-finder.py +++ b/bot/seasons/halloween/hacktober-issue-finder.py @@ -28,7 +28,7 @@ class HacktoberIssues(commands.Cog): """ Get a random python hacktober issue from Github. - If the command is run with beginner (`!hacktoberissues beginner`): + If the command is run with beginner (`.hacktoberissues beginner`): It will also narrow it down to the "first good issue" label. """ with ctx.typing(): -- cgit v1.2.3 From 0e7501251175e49fd5300d37b2178a0a914d89ba Mon Sep 17 00:00:00 2001 From: vivax3794 <51753506+vivax3794@users.noreply.github.com> Date: Sat, 12 Oct 2019 05:09:58 +0200 Subject: Fixed forgetting to divide by 100. --- bot/seasons/halloween/hacktober-issue-finder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/halloween/hacktober-issue-finder.py b/bot/seasons/halloween/hacktober-issue-finder.py index 2f1d6ac7..10732374 100644 --- a/bot/seasons/halloween/hacktober-issue-finder.py +++ b/bot/seasons/halloween/hacktober-issue-finder.py @@ -58,7 +58,7 @@ class HacktoberIssues(commands.Cog): else: url = URL if self.cache_normal is not None: - page = random.randint(1, min(1000, self.cache_normal["total_count"])) + page = random.randint(1, min(1000, self.cache_normal["total_count"]) // 100) url += f"&page={page}" log.debug(f"making api request to url: {url}") -- cgit v1.2.3 From 3afb3ce056d225464333b8f633ec3dac40024da8 Mon Sep 17 00:00:00 2001 From: Numerlor Date: Sat, 12 Oct 2019 22:24:00 +0200 Subject: allow all AoC commands in whitelisted channels --- bot/seasons/christmas/adventofcode.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'bot') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index a88e5ac3..007e4783 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -138,6 +138,7 @@ class AdventOfCode(commands.Cog): aliases=("sub", "notifications", "notify", "notifs"), brief="Notifications for new days" ) + @override_in_channel(AOC_WHITELIST) async def aoc_subscribe(self, ctx: commands.Context) -> None: """Assign the role for notifications about new days being ready.""" role = ctx.guild.get_role(AocConfig.role_id) @@ -152,6 +153,7 @@ class AdventOfCode(commands.Cog): f"If you don't want them any more, run `{unsubscribe_command}` instead.") @adventofcode_group.command(name="unsubscribe", aliases=("unsub",), brief="Notifications for new days") + @override_in_channel(AOC_WHITELIST) async def aoc_unsubscribe(self, ctx: commands.Context) -> None: """Remove the role for notifications about new days being ready.""" role = ctx.guild.get_role(AocConfig.role_id) @@ -163,6 +165,7 @@ class AdventOfCode(commands.Cog): await ctx.send("Hey, you don't even get any notifications about new Advent of Code tasks currently anyway.") @adventofcode_group.command(name="countdown", aliases=("count", "c"), brief="Return time left until next day") + @override_in_channel(AOC_WHITELIST) async def aoc_countdown(self, ctx: commands.Context) -> None: """Return time left until next day.""" if not is_in_advent(): @@ -180,11 +183,13 @@ class AdventOfCode(commands.Cog): await ctx.send(f"There are {hours} hours and {minutes} minutes left until day {tomorrow.day}.") @adventofcode_group.command(name="about", aliases=("ab", "info"), brief="Learn about Advent of Code") + @override_in_channel(AOC_WHITELIST) async def about_aoc(self, ctx: commands.Context) -> None: """Respond with an explanation of all things Advent of Code.""" await ctx.send("", embed=self.cached_about_aoc) @adventofcode_group.command(name="join", aliases=("j",), brief="Learn how to join PyDis' private AoC leaderboard") + @override_in_channel(AOC_WHITELIST) async def join_leaderboard(self, ctx: commands.Context) -> None: """DM the user the information for joining the PyDis AoC private leaderboard.""" author = ctx.message.author @@ -205,6 +210,7 @@ class AdventOfCode(commands.Cog): aliases=("board", "lb"), brief="Get a snapshot of the PyDis private AoC leaderboard", ) + @override_in_channel(AOC_WHITELIST) async def aoc_leaderboard(self, ctx: commands.Context, number_of_people_to_display: int = 10) -> None: """ Pull the top number_of_people_to_display members from the PyDis leaderboard and post an embed. @@ -246,6 +252,7 @@ class AdventOfCode(commands.Cog): aliases=("dailystats", "ds"), brief="Get daily statistics for the PyDis private leaderboard" ) + @override_in_channel(AOC_WHITELIST) async def private_leaderboard_daily_stats(self, ctx: commands.Context) -> None: """ Respond with a table of the daily completion statistics for the PyDis private leaderboard. @@ -289,6 +296,7 @@ class AdventOfCode(commands.Cog): aliases=("globalboard", "gb"), brief="Get a snapshot of the global AoC leaderboard", ) + @override_in_channel(AOC_WHITELIST) async def global_leaderboard(self, ctx: commands.Context, number_of_people_to_display: int = 10) -> None: """ Pull the top number_of_people_to_display members from the global AoC leaderboard and post an embed. -- cgit v1.2.3 From 055db29965e05cf175417ccb7b0bf737647d3db1 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Sun, 13 Oct 2019 17:54:50 +0100 Subject: Update bot/seasons/evergreen/issues.py Co-Authored-By: Kieran Siek --- bot/seasons/evergreen/issues.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 9713cfbd..8c449c49 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -39,7 +39,7 @@ class Issues(commands.Cog): return await ctx.send(f"[{str(r.status)}] {RESP_VALUE.get(r.status)}") # the original call is made to the issues API endpoint # if a issue or PR exists then there will be something returned - # if the word 'issues' is present within the response then we can simply pull the data we need from the + # if the word 'issues' is present within the response then we can simply pull the data we need from the # return data received from the API if "issues" in json_data.get("html_url"): if json_data.get("state") == "open": -- cgit v1.2.3 From 55d57ff80ca18c12bf5f3dca08aa59e9c57c92bc Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Mon, 14 Oct 2019 08:38:13 +0100 Subject: Caps fix --- bot/seasons/evergreen/issues.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 8c449c49..db94a3f4 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -15,7 +15,7 @@ ICONS = {"ISSUE": Emojis.issue, "MERGE": Emojis.merge} RESP_VALUE = {404: "Issue/pull request not located! Please enter a valid number!", - 403: "rate limit has been hit! Please try again later!"} + 403: "Rate limit has been hit! Please try again later!"} class Issues(commands.Cog): -- cgit v1.2.3 From 8da3d05486d8a47da48a3ae13c59e16c346c4d63 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Mon, 14 Oct 2019 08:39:58 +0100 Subject: Remove str() within f-string Co-Authored-By: Kieran Siek --- bot/seasons/evergreen/issues.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index db94a3f4..4c7966ff 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -29,7 +29,7 @@ class Issues(commands.Cog): async def issue(self, ctx: commands.Context, number: int, repository: str = "seasonalbot", user: str = "python-discord") -> None: """Command to get issues/pull request from GitHub.""" - url = f"https://api.github.com/repos/{user}/{repository}/issues/{str(number)}" + url = f"https://api.github.com/repos/{user}/{repository}/issues/{number}" mergeURL = f"https://api.github.com/repos/{user}/{repository}/pulls/{str(number)}/merge" async with self.bot.http_session.get(url) as r: -- cgit v1.2.3 From a3b10c15eae968ffdc5959eb7529ed0aaab17d1a Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Mon, 14 Oct 2019 08:40:29 +0100 Subject: Remove str() in f-string Co-Authored-By: Kieran Siek --- bot/seasons/evergreen/issues.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 4c7966ff..b32b8548 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -30,7 +30,7 @@ class Issues(commands.Cog): user: str = "python-discord") -> None: """Command to get issues/pull request from GitHub.""" url = f"https://api.github.com/repos/{user}/{repository}/issues/{number}" - mergeURL = f"https://api.github.com/repos/{user}/{repository}/pulls/{str(number)}/merge" + mergeURL = f"https://api.github.com/repos/{user}/{repository}/pulls/{number}/merge" async with self.bot.http_session.get(url) as r: json_data = await r.json() -- cgit v1.2.3 From 20d96fbae9e92a4ff8c75ef7cf5118998c6c74e0 Mon Sep 17 00:00:00 2001 From: RohanRadia Date: Mon, 14 Oct 2019 08:42:12 +0100 Subject: Made the icon_URL variable conform to PEP8 --- bot/seasons/evergreen/issues.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index b32b8548..22f7c6dc 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -43,28 +43,28 @@ class Issues(commands.Cog): # return data received from the API if "issues" in json_data.get("html_url"): if json_data.get("state") == "open": - iconURL = ICONS.get("ISSUE") + icon_URL = ICONS.get("ISSUE") else: - iconURL = ICONS.get("ISSUE_CLOSED") + icon_URL = ICONS.get("ISSUE_CLOSED") # if the word 'issues' is not contained within the returned data and there is no error code then we know that # the requested data is a pr, hence to get the specifics on it we have to call the PR API endpoint allowing us # to get the specific information in relation to the PR that is not provided via the issues endpoint else: async with self.bot.http_session.get(mergeURL) as m: if json_data.get("state") == "open": - iconURL = ICONS.get("PULL_REQUEST") + icon_URL = ICONS.get("PULL_REQUEST") # when the status is 204 this means that the state of the PR is merged elif m.status == 204: - iconURL = ICONS.get("MERGE") + icon_URL = ICONS.get("MERGE") # else by the process of elimination, the pull request has been closed else: - iconURL = ICONS.get("PULL_REQUEST_CLOSED") + icon_URL = ICONS.get("PULL_REQUEST_CLOSED") issue_url = json_data.get("html_url") description_text = f"[{repository}] #{number} {json_data.get('title')}" resp = discord.Embed( colour=Colours.bright_green, - description=f"{iconURL} [{description_text}]({issue_url})" + description=f"{icon_URL} [{description_text}]({issue_url})" ) resp.set_author(name="GitHub", url=issue_url) await ctx.send(embed=resp) -- cgit v1.2.3 From 9c1a0a4b172f092ca3c11b36dd10d5cb4fd5f2d7 Mon Sep 17 00:00:00 2001 From: "S. Co1" Date: Mon, 14 Oct 2019 13:42:21 -0400 Subject: Syntax cleanup, remove unnecessary emoji dict --- bot/seasons/evergreen/issues.py | 55 ++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index af33b2be..c7501a5d 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -3,21 +3,16 @@ import logging import discord from discord.ext import commands - from bot.constants import Channels, Colours, Emojis, WHITELISTED_CHANNELS from bot.decorators import override_in_channel log = logging.getLogger(__name__) ISSUE_WHITELIST = WHITELISTED_CHANNELS + (Channels.seasonalbot_chat,) -ICONS = {"ISSUE": Emojis.issue, - "ISSUE_CLOSED": Emojis.issue_closed, - "PULL_REQUEST": Emojis.pull_request, - "PULL_REQUEST_CLOSED": Emojis.pull_request_closed, - "MERGE": Emojis.merge} - -RESP_VALUE = {404: "Issue/pull request not located! Please enter a valid number!", - 403: "Rate limit has been hit! Please try again later!"} +BAD_RESPONSE = { + 404: "Issue/pull request not located! Please enter a valid number!", + 403: "Rate limit has been hit! Please try again later!" +} class Issues(commands.Cog): @@ -33,41 +28,45 @@ class Issues(commands.Cog): ) -> None: """Command to retrieve issues from a GitHub repository.""" url = f"https://api.github.com/repos/{user}/{repository}/issues/{number}" - mergeURL = f"https://api.github.com/repos/{user}/{repository}/pulls/{number}/merge" + merge_url = f"https://api.github.com/repos/{user}/{repository}/pulls/{number}/merge" + log.trace(f"Querying GH issues API: {url}") async with self.bot.http_session.get(url) as r: json_data = await r.json() - if r.status in RESP_VALUE: - return await ctx.send(f"[{str(r.status)}] {RESP_VALUE.get(r.status)}") - # the original call is made to the issues API endpoint - # if a issue or PR exists then there will be something returned - # if the word 'issues' is present within the response then we can simply pull the data we need from the - # return data received from the API + if r.status in BAD_RESPONSE: + log.warning(f"Received response {r.status} from: {url}") + return await ctx.send(f"[{str(r.status)}] {BAD_RESPONSE.get(r.status)}") + + # The initial API request is made to the issues API endpoint, which will return information + # if the issue or PR is present. However, the scope of information returned for PRs differs + # from issues: if the 'issues' key is present in the response then we can pull the data we + # need from the initial API call. if "issues" in json_data.get("html_url"): if json_data.get("state") == "open": - icon_URL = ICONS.get("ISSUE") + icon_url = Emojis.issue else: - icon_URL = ICONS.get("ISSUE_CLOSED") - # if the word 'issues' is not contained within the returned data and there is no error code then we know that - # the requested data is a pr, hence to get the specifics on it we have to call the PR API endpoint allowing us - # to get the specific information in relation to the PR that is not provided via the issues endpoint + icon_url = Emojis.issue_closed + + # If the 'issues' key is not contained in the API response and there is no error code, then + # we know that a PR has been requested and a call to the pulls API endpoint is necessary + # to get the desired information for the PR. else: - async with self.bot.http_session.get(mergeURL) as m: + log.trace(f"PR provided, querying GH pulls API for additional information: {merge_url}") + async with self.bot.http_session.get(merge_url) as m: if json_data.get("state") == "open": - icon_URL = ICONS.get("PULL_REQUEST") - # when the status is 204 this means that the state of the PR is merged + icon_url = Emojis.pull_request + # When the status is 204 this means that the state of the PR is merged elif m.status == 204: - icon_URL = ICONS.get("MERGE") - # else by the process of elimination, the pull request has been closed + icon_url = Emojis.merge else: - icon_URL = ICONS.get("PULL_REQUEST_CLOSED") + icon_url = Emojis.pull_request_closed issue_url = json_data.get("html_url") description_text = f"[{repository}] #{number} {json_data.get('title')}" resp = discord.Embed( colour=Colours.bright_green, - description=f"{icon_URL} [{description_text}]({issue_url})" + description=f"{icon_url} [{description_text}]({issue_url})" ) resp.set_author(name="GitHub", url=issue_url) await ctx.send(embed=resp) -- cgit v1.2.3 From dbc7cb75a6bb09ac7b03b401cadd0187bf66815d Mon Sep 17 00:00:00 2001 From: Sebastiaan Zeeff <33516116+SebastiaanZ@users.noreply.github.com> Date: Thu, 31 Oct 2019 12:53:32 +0100 Subject: Hotfix end date of Hacktober The command is mostly used to calculate the time left in the DO's Hacktoberfest event we are participating in. However, the current end datetime was specified as a day before the actual end of the event. This hotfix remedies that for the end-calculation only. This code should get a proper fix to rework the entire logic to use the correct start and end datetimes for DO's event. --- bot/seasons/halloween/timeleft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/halloween/timeleft.py b/bot/seasons/halloween/timeleft.py index 77767baa..8cb3f4f6 100644 --- a/bot/seasons/halloween/timeleft.py +++ b/bot/seasons/halloween/timeleft.py @@ -25,7 +25,7 @@ class TimeLeft(commands.Cog): year = now.year if now.month > 10: year += 1 - end = datetime(year, 10, 31, 11, 59, 59) + end = datetime(year, 11, 1, 11, 59, 59) start = datetime(year, 10, 1) return now, end, start -- cgit v1.2.3 From a914ba2d7926de49d732abac872e778d465afa1d Mon Sep 17 00:00:00 2001 From: kwzrd Date: Sat, 2 Nov 2019 14:19:03 +0100 Subject: Add two new icons to icon constant --- bot/seasons/evergreen/__init__.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'bot') diff --git a/bot/seasons/evergreen/__init__.py b/bot/seasons/evergreen/__init__.py index b95f3528..43a5cfdf 100644 --- a/bot/seasons/evergreen/__init__.py +++ b/bot/seasons/evergreen/__init__.py @@ -10,4 +10,6 @@ class Evergreen(SeasonBase): "/logos/logo_animated/spinner/spinner.gif", "/logos/logo_animated/tongues/tongues.gif", "/logos/logo_animated/winky/winky.gif", + "/logos/logo_animated/jumper/jumper.gif", + "/logos/logo_animated/apple/apple.gif", ) -- cgit v1.2.3 From 7ad0b0a1d6b1d4adbe8dfb9ef6afb9804262aca2 Mon Sep 17 00:00:00 2001 From: kwzrd Date: Sat, 2 Nov 2019 21:50:34 +0100 Subject: Change off-season logo size to 512 --- bot/seasons/evergreen/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/__init__.py b/bot/seasons/evergreen/__init__.py index 43a5cfdf..722ef952 100644 --- a/bot/seasons/evergreen/__init__.py +++ b/bot/seasons/evergreen/__init__.py @@ -6,10 +6,10 @@ class Evergreen(SeasonBase): bot_icon = "/logos/logo_seasonal/evergreen/logo_evergreen.png" icon = ( - "/logos/logo_animated/heartbeat/heartbeat.gif", - "/logos/logo_animated/spinner/spinner.gif", - "/logos/logo_animated/tongues/tongues.gif", - "/logos/logo_animated/winky/winky.gif", - "/logos/logo_animated/jumper/jumper.gif", - "/logos/logo_animated/apple/apple.gif", + "/logos/logo_animated/heartbeat/heartbeat_512.gif", + "/logos/logo_animated/spinner/spinner_512.gif", + "/logos/logo_animated/tongues/tongues_512.gif", + "/logos/logo_animated/winky/winky_512.gif", + "/logos/logo_animated/jumper/jumper_512.gif", + "/logos/logo_animated/apple/apple_512.gif", ) -- cgit v1.2.3 From e8e6afb13debb54226d373d0fcc31c0c974f7b85 Mon Sep 17 00:00:00 2001 From: Deniz Date: Mon, 25 Nov 2019 20:23:09 +0100 Subject: Add the new blinky server guild icon --- bot/seasons/evergreen/__init__.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bot') diff --git a/bot/seasons/evergreen/__init__.py b/bot/seasons/evergreen/__init__.py index 722ef952..c2746552 100644 --- a/bot/seasons/evergreen/__init__.py +++ b/bot/seasons/evergreen/__init__.py @@ -12,4 +12,5 @@ class Evergreen(SeasonBase): "/logos/logo_animated/winky/winky_512.gif", "/logos/logo_animated/jumper/jumper_512.gif", "/logos/logo_animated/apple/apple_512.gif", + "/logos/logo_animated/blinky/blinky_512.gif", ) -- cgit v1.2.3