1
0
Fork 0

Add unpin command

This commit is contained in:
Ethanell 2020-11-05 00:41:22 +01:00
parent d9776cfa2f
commit cb0d41270a

View file

@ -67,12 +67,24 @@ class PCP(commands.Cog):
embed.add_field(name="pcp <group>", value="Join your group", inline=False) embed.add_field(name="pcp <group>", value="Join your group", inline=False)
if await self.pcp_group.can_run(ctx): if await self.pcp_group.can_run(ctx):
embed.add_field(name="pcp group", value="Manage PCP group", inline=False) embed.add_field(name="pcp group", value="Manage PCP group", inline=False)
if await self.pcp_pin.can_run(ctx):
embed.add_field(name="pcp pin <url>", value="Pin a message with the url", inline=False)
if await self.pcp_unpin.can_run(ctx):
embed.add_field(name="pcp unpin <url>", value="Unpin a message with the url", inline=False)
if not embed.fields: if not embed.fields:
raise MissingPermissions(None) raise MissingPermissions(None)
await ctx.send(embed=embed) await ctx.send(embed=embed)
@pcp.group("pin", pass_context=True) @pcp.group("pin", pass_context=True)
async def pcp_pin(self, ctx: commands.Context, url: str): async def pcp_pin(self, ctx: commands.Context, url: str):
await self.pin(ctx, url, True)
@pcp.group("unpin", pass_context=True)
async def pcp_unpin(self, ctx: commands.Context, url: str):
await self.pin(ctx, url, False)
@staticmethod
async def pin(ctx: commands.Context, url: str, action: bool):
r = msg_url_re.fullmatch(url) r = msg_url_re.fullmatch(url)
if not r: if not r:
raise BadArgument() raise BadArgument()
@ -86,9 +98,14 @@ class PCP(commands.Cog):
if not m: if not m:
raise BadArgument() raise BadArgument()
await m.pin() if action:
await m.pin()
msg = "pinned a message"
else:
await m.unpin()
msg = "unpinned a message"
await ctx.send(f"{ctx.author.mention} pinned a message") await ctx.send(f"{ctx.author.mention} {msg}")
@pcp.group("group", pass_context=True) @pcp.group("group", pass_context=True)
@commands.has_permissions(administrator=True) @commands.has_permissions(administrator=True)