diff --git a/cogs/pin.py b/cogs/pin.py index dea3c13..a91e509 100644 --- a/cogs/pin.py +++ b/cogs/pin.py @@ -17,7 +17,9 @@ class Pin(Cog): self.bot = bot def is_pinboard(self, msg): - return msg.author == self.bot.user and len(msg.embeds) > 0 and msg.embeds[0].title == "Pinboard" + return msg.author == self.bot.user and \ + len(msg.embeds) > 0 and \ + msg.embeds[0].title == "Pinboard" async def get_pinboard(self, gh, channel): # Find pinboard pin @@ -30,9 +32,23 @@ class Pin(Cog): return (id, data["files"]["pinboard.md"]["content"]) # Create pinboard pin if it does not exist - data = await gh.post("/gists", data={"files": {"pinboard.md": {"content": "Old pins are available here:\n\n"}}, "description": f"Pinboard for SwitchRoot #{channel.name}", "public": True}) - msg = await channel.send(embed=Embed(title="Pinboard", description="Old pins are moved to the pinboard to make space for new ones. Check it out!", url=data["html_url"])) + data = await gh.post("/gists", data={ + "files": { + "pinboard.md": { + "content": "Old pins are available here:\n\n" + } + }, + "description": f"Pinboard for SwitchRoot #{channel.name}", + "public": True + }) + + msg = await channel.send(embed=Embed( + title="Pinboard", + description="Old pins are moved to the pinboard to make space for \ + new ones. Check it out!", + url=data["html_url"])) await msg.pin() + return (data["id"], data["files"]["pinboard.md"]["content"]) async def add_pin_to_pinboard(self, channel, data): @@ -41,11 +57,18 @@ class Pin(Cog): return async with aiohttp.ClientSession() as session: - gh = gidgethub.aiohttp.GitHubAPI(session, "RoboCop-NG", oauth_token=config.github_oauth_token) + gh = gidgethub.aiohttp.GitHubAPI(session, "RoboCop-NG", + oauth_token=config.github_oauth_token) (id, content) = await self.get_pinboard(gh, channel) content += "- " + data + "\n" - await gh.patch(f"/gists/{id}", data={"files": {"pinboard.md": {"content": content}}}) + await gh.patch(f"/gists/{id}", data={ + "files": { + "pinboard.md": { + "content": content + } + } + }) @commands.command() @commands.guild_only()