Fix style in pin.py
This commit is contained in:
parent
2ccc10174d
commit
23c7e83be5
1 changed files with 28 additions and 5 deletions
33
cogs/pin.py
33
cogs/pin.py
|
@ -17,7 +17,9 @@ class Pin(Cog):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
def is_pinboard(self, msg):
|
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):
|
async def get_pinboard(self, gh, channel):
|
||||||
# Find pinboard pin
|
# Find pinboard pin
|
||||||
|
@ -30,9 +32,23 @@ class Pin(Cog):
|
||||||
return (id, data["files"]["pinboard.md"]["content"])
|
return (id, data["files"]["pinboard.md"]["content"])
|
||||||
|
|
||||||
# Create pinboard pin if it does not exist
|
# 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})
|
data = await gh.post("/gists", data={
|
||||||
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"]))
|
"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()
|
await msg.pin()
|
||||||
|
|
||||||
return (data["id"], data["files"]["pinboard.md"]["content"])
|
return (data["id"], data["files"]["pinboard.md"]["content"])
|
||||||
|
|
||||||
async def add_pin_to_pinboard(self, channel, data):
|
async def add_pin_to_pinboard(self, channel, data):
|
||||||
|
@ -41,11 +57,18 @@ class Pin(Cog):
|
||||||
return
|
return
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
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)
|
(id, content) = await self.get_pinboard(gh, channel)
|
||||||
content += "- " + data + "\n"
|
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.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
|
Loading…
Reference in a new issue