♻️ roles are now an enum

This commit is contained in:
ddorn 2020-04-27 12:35:02 +02:00
parent 11aa877f2a
commit 7f3c81cd81
3 changed files with 20 additions and 21 deletions

View File

@ -202,7 +202,7 @@ class Phase:
self.tirage.teams = teams self.tirage.teams = teams
def captain_mention(self, ctx): def captain_mention(self, ctx):
return get(ctx.guild.roles, name=CAPTAIN_ROLE).mention return get(ctx.guild.roles, name=Role.CAPTAIN).mention
async def dice(self, ctx: Context, author, dice): async def dice(self, ctx: Context, author, dice):
raise UnwantedCommand() raise UnwantedCommand()
@ -485,9 +485,9 @@ class PassageOrderPhase(OrderPhase):
) )
await asyncio.sleep(0.5) await asyncio.sleep(0.5)
captain = get(ctx.guild.roles, name=CAPTAIN_ROLE)
await ctx.send( await ctx.send(
f"Les {captain.mention}s, vous pouvez lancer à nouveau un dé 100 (`!dice 100`)" f"Les {self.captain_mention(ctx)}s, vous pouvez lancer "
f"à nouveau un dé 100 (`!dice 100`)"
) )
@ -500,7 +500,6 @@ class TirageOrderPhase(OrderPhase):
super().__init__(tirage, round, "des tirages", "tirage_order", False) super().__init__(tirage, round, "des tirages", "tirage_order", False)
async def start(self, ctx): async def start(self, ctx):
captain = get(ctx.guild.roles, name=CAPTAIN_ROLE)
await asyncio.sleep( await asyncio.sleep(
0.5 0.5
@ -512,7 +511,7 @@ class TirageOrderPhase(OrderPhase):
) )
await asyncio.sleep(0.5) await asyncio.sleep(0.5)
await ctx.send( await ctx.send(
f"Les {captain.mention}s, vous pouvez désormais lancer un dé 100 " f"Les {self.captain_mention(ctx)}s, vous pouvez désormais lancer un dé 100 "
"comme ceci `!dice 100`. " "comme ceci `!dice 100`. "
"L'ordre des tirages suivants sera l'ordre croissant des lancers. " "L'ordre des tirages suivants sera l'ordre croissant des lancers. "
) )
@ -606,7 +605,7 @@ class TirageCog(Cog, name="Tirages"):
@draw_group.command( @draw_group.command(
name="start", usage="équipe1 équipe2 équipe3 (équipe4)", name="start", usage="équipe1 équipe2 équipe3 (équipe4)",
) )
@commands.has_role(ORGA_ROLE) @commands.has_role(Role.ORGA)
async def start(self, ctx: Context, *teams): async def start(self, ctx: Context, *teams):
""" """
Commence un tirage avec 3 ou 4 équipes. Commence un tirage avec 3 ou 4 équipes.
@ -640,8 +639,8 @@ class TirageCog(Cog, name="Tirages"):
r = lambda role_name: get(ctx.guild.roles, name=role_name) r = lambda role_name: get(ctx.guild.roles, name=role_name)
overwrites = { overwrites = {
ctx.guild.default_role: read, ctx.guild.default_role: read,
r(CAPTAIN_ROLE): send, r(Role.CAPTAIN): send,
r(BENEVOLE_ROLE): send, r(Role.BENEVOLE): send,
} }
await channel.edit(overwrites=overwrites) await channel.edit(overwrites=overwrites)
@ -661,7 +660,7 @@ class TirageCog(Cog, name="Tirages"):
@draw_group.command( @draw_group.command(
name="abort", help="Annule le tirage en cours.", name="abort", help="Annule le tirage en cours.",
) )
@commands.has_role(ORGA_ROLE) @commands.has_role(Role.ORGA)
async def abort_draw_cmd(self, ctx): async def abort_draw_cmd(self, ctx):
""" """
Annule le tirage en cours. Annule le tirage en cours.
@ -676,7 +675,7 @@ class TirageCog(Cog, name="Tirages"):
await ctx.send("Le tirage est annulé.") await ctx.send("Le tirage est annulé.")
@draw_group.command(name="skip", aliases=["s"]) @draw_group.command(name="skip", aliases=["s"])
@commands.has_role(DEV_ROLE) @commands.has_role(Role.DEV)
async def draw_skip(self, ctx, *teams): async def draw_skip(self, ctx, *teams):
"""Skip certaines phases du tirage.""" """Skip certaines phases du tirage."""
channel = ctx.channel.id channel = ctx.channel.id

View File

@ -3,11 +3,7 @@ from pathlib import Path
__all__ = [ __all__ = [
"TOKEN", "TOKEN",
"ORGA_ROLE", "Role",
"CNO_ROLE",
"DEV_ROLE",
"BENEVOLE_ROLE",
"CAPTAIN_ROLE",
"PROBLEMS", "PROBLEMS",
"MAX_REFUSE", "MAX_REFUSE",
"ROUND_NAMES", "ROUND_NAMES",
@ -26,11 +22,15 @@ if TOKEN is None:
quit(1) quit(1)
GUILD = "690934836696973404" GUILD = "690934836696973404"
ORGA_ROLE = "Orga"
CNO_ROLE = "CNO"
BENEVOLE_ROLE = "Bénévole" class Role:
CAPTAIN_ROLE = "Capitaine" CNO = "CNO"
DEV_ROLE = "dev" DEV = "dev"
ORGA = "Orga"
BENEVOLE = "Bénévole"
CAPTAIN = "Capitaine"
with open("problems") as f: with open("problems") as f:
PROBLEMS = f.read().splitlines() PROBLEMS = f.read().splitlines()

View File

@ -42,7 +42,7 @@ async def choose(ctx: Context, *args):
@bot.command(name="interrupt") @bot.command(name="interrupt")
@commands.has_role(DEV_ROLE) @commands.has_role(Role.DEV)
async def interrupt_cmd(ctx): async def interrupt_cmd(ctx):
""" """
:warning: Ouvre une console un @dev m'a lancé. :warning: :warning: Ouvre une console un @dev m'a lancé. :warning: