aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar vivax3794 <[email protected]>2019-10-05 06:30:48 +0200
committerGravatar vivax3794 <[email protected]>2019-10-05 06:30:48 +0200
commita7c7fb7aacc477eb498c3872adf71d10cb798f67 (patch)
treeeeca328a420b5fb6de373376f804bce0ae4ef6b6
parentadded embed. (diff)
added beginner
-rw-r--r--bot/seasons/halloween/hacktober-issue-finder.py50
1 files changed, 36 insertions, 14 deletions
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