From cb0d41270a08c1a7874943ea45a9082fbd4bc041 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 00:41:22 +0100 Subject: [PATCH] Add unpin command --- extensions/pcp.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/extensions/pcp.py b/extensions/pcp.py index 6607103..00721a1 100644 --- a/extensions/pcp.py +++ b/extensions/pcp.py @@ -67,12 +67,24 @@ class PCP(commands.Cog): embed.add_field(name="pcp ", value="Join your group", inline=False) if await self.pcp_group.can_run(ctx): 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 ", value="Pin a message with the url", inline=False) + if await self.pcp_unpin.can_run(ctx): + embed.add_field(name="pcp unpin ", value="Unpin a message with the url", inline=False) if not embed.fields: raise MissingPermissions(None) await ctx.send(embed=embed) @pcp.group("pin", pass_context=True) 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) if not r: raise BadArgument() @@ -86,9 +98,14 @@ class PCP(commands.Cog): if not m: 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) @commands.has_permissions(administrator=True)