Merge pull request #34 from flifloo/pcp
Fix some command arguments and update help
This commit is contained in:
commit
e5b07a9f20
1 changed files with 21 additions and 16 deletions
|
@ -11,12 +11,13 @@ extension_name = "PCP"
|
||||||
logger = logger.getChild(extension_name)
|
logger = logger.getChild(extension_name)
|
||||||
group_re = re.compile(r"(G[0-9]S[0-9]|ASPE|LP DEVOPS|LP ESSIR|LP SID)")
|
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]+)")
|
msg_url_re = re.compile(r"https://.*discord.*\.com/channels/[0-9]+/([0-9+]+)/([0-9]+)")
|
||||||
|
role_mention_re = re.compile(r"<@&[0-9]+>")
|
||||||
|
user_mention_re = re.compile(r"<@![0-9]+>")
|
||||||
|
|
||||||
|
|
||||||
class PCP(commands.Cog):
|
class PCP(commands.Cog):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.polls = {}
|
|
||||||
|
|
||||||
def description(self):
|
def description(self):
|
||||||
return "PCP Univ Lyon 1"
|
return "PCP Univ Lyon 1"
|
||||||
|
@ -31,7 +32,8 @@ class PCP(commands.Cog):
|
||||||
if not role:
|
if not role:
|
||||||
raise BadArgument()
|
raise BadArgument()
|
||||||
|
|
||||||
roles = list(filter(lambda r: group_re.fullmatch(r.name.upper()) or r.name == "nouveau venu", 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):
|
if role.name in map(lambda r: r.name, roles):
|
||||||
raise BadArgument()
|
raise BadArgument()
|
||||||
elif roles:
|
elif roles:
|
||||||
|
@ -78,6 +80,8 @@ class PCP(commands.Cog):
|
||||||
@pcp_group.group("help", pass_context=True)
|
@pcp_group.group("help", pass_context=True)
|
||||||
async def pcp_group_help(self, ctx: commands.Context):
|
async def pcp_group_help(self, ctx: commands.Context):
|
||||||
embed = Embed(title="PCP group help")
|
embed = Embed(title="PCP group help")
|
||||||
|
embed.add_field(name="pcp group fix_vocal",
|
||||||
|
value="Check all text channel permissions to reapply vocal permissions", inline=False)
|
||||||
embed.add_field(name="pcp group subject", value="Manage subjects for group", inline=False)
|
embed.add_field(name="pcp group subject", value="Manage subjects for group", inline=False)
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
@ -96,7 +100,6 @@ class PCP(commands.Cog):
|
||||||
await ctx.send(f"{cat.name} done")
|
await ctx.send(f"{cat.name} done")
|
||||||
await ctx.message.add_reaction("\U0001f44d")
|
await ctx.message.add_reaction("\U0001f44d")
|
||||||
|
|
||||||
|
|
||||||
@pcp_group.group("subject", pass_context=True)
|
@pcp_group.group("subject", pass_context=True)
|
||||||
async def pcp_group_subject(self, ctx: commands.Context):
|
async def pcp_group_subject(self, ctx: commands.Context):
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
||||||
|
@ -107,21 +110,24 @@ class PCP(commands.Cog):
|
||||||
embed = Embed(title="PCP group subject help")
|
embed = Embed(title="PCP group subject help")
|
||||||
embed.add_field(name="pcp group subject add <name> <@group> [@teacher]", value="Add a subject to a group",
|
embed.add_field(name="pcp group subject add <name> <@group> [@teacher]", value="Add a subject to a group",
|
||||||
inline=False)
|
inline=False)
|
||||||
|
embed.add_field(name="pcp group subject bulk <@group> [subject1] [subject2] ...", value="Bulk subject add",
|
||||||
|
inline=False)
|
||||||
embed.add_field(name="pcp group subject remove <name> <@group>", value="Remove a subject to a group",
|
embed.add_field(name="pcp group subject remove <name> <@group>", value="Remove a subject to a group",
|
||||||
inline=False)
|
inline=False)
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@pcp_group_subject.group("add", pass_context=True)
|
@pcp_group_subject.group("add", pass_context=True)
|
||||||
async def pcp_group_subject_add(self, ctx: commands.Context, name: str):
|
async def pcp_group_subject_add(self, ctx: commands.Context, name: str, group: str, teacher: str = None):
|
||||||
if len(ctx.message.role_mentions) != 1:
|
if not role_mention_re.fullmatch(group):
|
||||||
raise BadArgument()
|
raise BadArgument()
|
||||||
if len(ctx.message.mentions) > 1:
|
if teacher and not user_mention_re.fullmatch(teacher):
|
||||||
raise BadArgument()
|
raise BadArgument()
|
||||||
elif ctx.message.mentions and\
|
elif teacher and\
|
||||||
not next(filter(lambda r: r.name == "professeurs", ctx.message.mentions[0].roles), None):
|
not next(filter(lambda r: r.name == "professeurs", ctx.message.mentions[0].roles), None):
|
||||||
raise BadArgument()
|
raise BadArgument()
|
||||||
|
|
||||||
cat = next(filter(lambda c: c.name.upper() == ctx.message.role_mentions[0].name.upper(), ctx.guild.categories), None)
|
cat = next(filter(lambda c: c.name.upper() == ctx.message.role_mentions[0].name.upper(),
|
||||||
|
ctx.guild.categories), None)
|
||||||
if not cat:
|
if not cat:
|
||||||
raise BadArgument()
|
raise BadArgument()
|
||||||
|
|
||||||
|
@ -139,20 +145,23 @@ class PCP(commands.Cog):
|
||||||
|
|
||||||
@pcp_group_subject.group("bulk", pass_context=True)
|
@pcp_group_subject.group("bulk", pass_context=True)
|
||||||
async def pcp_group_subject_bulk(self, ctx: commands.Context, mention, *names):
|
async def pcp_group_subject_bulk(self, ctx: commands.Context, mention, *names):
|
||||||
|
if not role_mention_re.fullmatch(mention):
|
||||||
|
raise BadArgument()
|
||||||
for n in names:
|
for n in names:
|
||||||
await ctx.invoke(self.pcp_group_subject_add, n)
|
await ctx.invoke(self.pcp_group_subject_add, n)
|
||||||
|
|
||||||
@pcp_group_subject.group("remove", pass_context=True)
|
@pcp_group_subject.group("remove", pass_context=True)
|
||||||
async def pcp_group_subject_remove(self, ctx: commands.Context, name: str):
|
async def pcp_group_subject_remove(self, ctx: commands.Context, name: str, group: str):
|
||||||
if len(ctx.message.role_mentions) != 1:
|
if not role_mention_re.fullmatch(group):
|
||||||
raise BadArgument()
|
raise BadArgument()
|
||||||
|
|
||||||
cat = next(filter(lambda c: c.name.upper() == ctx.message.role_mentions[0].name.upper(), ctx.guild.categories), None)
|
cat = next(filter(lambda c: c.name.upper() == ctx.message.role_mentions[0].name.upper(),
|
||||||
|
ctx.guild.categories), None)
|
||||||
if not cat:
|
if not cat:
|
||||||
raise BadArgument()
|
raise BadArgument()
|
||||||
|
|
||||||
chan = next(filter(lambda c: c.name.upper() == name.upper(), cat.text_channels), None)
|
chan = next(filter(lambda c: c.name.upper() == name.upper(), cat.text_channels), None)
|
||||||
if not cat:
|
if not chan:
|
||||||
raise BadArgument()
|
raise BadArgument()
|
||||||
|
|
||||||
await chan.delete()
|
await chan.delete()
|
||||||
|
@ -171,10 +180,6 @@ class PCP(commands.Cog):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await ctx.send(f"{e.__class__.__name__}: {e}")
|
await ctx.send(f"{e.__class__.__name__}: {e}")
|
||||||
|
|
||||||
@pcp.group("test", pass_context=True)
|
|
||||||
async def test(self, ctx: commands.Context):
|
|
||||||
await ctx.message.add_reaction("\U0001f44d")
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
logger.info(f"Loading...")
|
logger.info(f"Loading...")
|
||||||
|
|
Reference in a new issue