From 85b1cc78916c69204b28af87415d448fdae9ba35 Mon Sep 17 00:00:00 2001 From: flifloo Date: Sun, 1 Nov 2020 22:16:36 +0100 Subject: [PATCH] Add pin command --- extensions/pcp.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/extensions/pcp.py b/extensions/pcp.py index 3eec875..850153a 100644 --- a/extensions/pcp.py +++ b/extensions/pcp.py @@ -10,6 +10,7 @@ from administrator.logger import logger extension_name = "PCP" logger = logger.getChild(extension_name) group_re = re.compile(r"(G[0-9]S[0-9]|ASPE|LP DEVOPS|LP ESSIR|LP SID)") +msg_url_re = re.compile(r"https://.*discord.*\.com/channels/[0-9]+/([0-9+]+)/([0-9]+)") class PCP(commands.Cog): @@ -38,12 +39,10 @@ class PCP(commands.Cog): await ctx.author.add_roles(role) await ctx.message.add_reaction("\U0001f44d") - return elif ctx.invoked_subcommand is None: await ctx.invoke(self.pcp_help) @pcp.group("help", pass_context=True) - @commands.guild_only() async def pcp_help(self, ctx: commands.Context): embed = Embed(title="PCP help") embed.add_field(name="pcp ", value="Join your group", inline=False) @@ -51,6 +50,25 @@ class PCP(commands.Cog): embed.add_field(name="pcp group", value="Manage PCP group", inline=False) await ctx.send(embed=embed) + @pcp.group("pin", pass_context=True) + async def pcp_pin(self, ctx: commands.Context, url: str): + r = msg_url_re.fullmatch(url) + if not r: + raise BadArgument() + r = r.groups() + + c = ctx.guild.get_channel(int(r[0])) + if not c: + raise BadArgument() + + m = await c.fetch_message(int(r[1])) + if not m: + raise BadArgument() + + await m.pin() + + await ctx.send(f"{ctx.author.mention} pinned a message") + @pcp.group("group", pass_context=True) @commands.has_permissions(administrator=True) async def pcp_group(self, ctx: commands.Context):