commit
bec6de044d
1 changed files with 38 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
|
||||
from discord import Embed
|
||||
from discord import Embed, Member
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import BadArgument
|
||||
|
||||
|
@ -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):
|
||||
|
@ -30,7 +31,7 @@ class PCP(commands.Cog):
|
|||
if not role:
|
||||
raise BadArgument()
|
||||
|
||||
roles = list(filter(lambda r: group_re.fullmatch(r.name.upper()), ctx.author.roles))
|
||||
roles = list(filter(lambda r: group_re.fullmatch(r.name.upper()) or r.name == "nouveau venu", ctx.author.roles))
|
||||
if role.name in map(lambda r: r.name, roles):
|
||||
raise BadArgument()
|
||||
elif roles:
|
||||
|
@ -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 <group>", 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):
|
||||
|
@ -63,6 +81,22 @@ class PCP(commands.Cog):
|
|||
embed.add_field(name="pcp group subject", value="Manage subjects for group", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@pcp_group.group("fix_vocal", pass_context=True)
|
||||
async def pcp_group_fix_vocal(self, ctx: commands.Context):
|
||||
for cat in filter(lambda c: group_re.fullmatch(c.name.upper()), ctx.guild.categories):
|
||||
await ctx.send(f"{cat.name}...")
|
||||
teachers = []
|
||||
for t in cat.text_channels:
|
||||
for p in t.overwrites:
|
||||
if isinstance(p, Member):
|
||||
teachers.append(p)
|
||||
voc = next(filter(lambda c: c.name == "vocal-1", cat.voice_channels), None)
|
||||
for t in teachers:
|
||||
await voc.set_permissions(t, view_channel=True)
|
||||
await ctx.send(f"{cat.name} done")
|
||||
await ctx.message.add_reaction("\U0001f44d")
|
||||
|
||||
|
||||
@pcp_group.group("subject", pass_context=True)
|
||||
async def pcp_group_subject(self, ctx: commands.Context):
|
||||
if ctx.invoked_subcommand is None:
|
||||
|
|
Reference in a new issue