🐛 fix roles on the server
This commit is contained in:
parent
717f094c16
commit
ad2fcf6828
|
@ -1,8 +1,11 @@
|
|||
import code
|
||||
from pprint import pprint
|
||||
|
||||
from discord.ext.commands import command, has_role, Bot
|
||||
import discord
|
||||
from discord import Colour, TextChannel, PermissionOverwrite
|
||||
from discord.ext.commands import command, has_role, Bot, has_any_role
|
||||
from discord.ext.commands import Cog
|
||||
from discord.utils import get
|
||||
|
||||
from src.constants import *
|
||||
|
||||
|
@ -47,6 +50,12 @@ class DevCog(Cog, name="Dev tools"):
|
|||
@command(name="reload", aliases=["r"])
|
||||
@has_role(Role.DEV)
|
||||
async def reload_cmd(self, ctx, name):
|
||||
"""
|
||||
(dev) Recharge une catégorie de commande.
|
||||
|
||||
A utiliser quand le code change. Arguments
|
||||
possibles: `teams`, `tirages`, `dev`.
|
||||
"""
|
||||
|
||||
MAP = {"d": "dev", "ts": "teams", "t": "tirages"}
|
||||
name = MAP.get(name, name)
|
||||
|
@ -62,6 +71,57 @@ class DevCog(Cog, name="Dev tools"):
|
|||
else:
|
||||
await ctx.send(f":tada: L'extension **{name}** a bien été rechargée.")
|
||||
|
||||
@command(name="setup-roles")
|
||||
async def setup_roles(self, ctx):
|
||||
"""
|
||||
(dev) Temporary command to setup the server.
|
||||
"""
|
||||
|
||||
return
|
||||
|
||||
guild: discord.Guild = ctx.guild
|
||||
nothing = PermissionOverwrite(read_messages=False)
|
||||
see = PermissionOverwrite(read_messages=True)
|
||||
|
||||
return
|
||||
|
||||
aide: TextChannel = get(guild.text_channels, name="aide")
|
||||
for t in TOURNOIS:
|
||||
orga = get(guild.roles, name=f"Orga {t}")
|
||||
jury = get(guild.roles, name=f"Jury {t}")
|
||||
await aide.set_permissions(orga, overwrite=see)
|
||||
await aide.set_permissions(jury, overwrite=see)
|
||||
|
||||
return
|
||||
|
||||
tournois = {
|
||||
tournoi: get(guild.categories, name=tournoi) for tournoi in TOURNOIS
|
||||
}
|
||||
|
||||
for ch in guild.text_channels:
|
||||
print(repr(ch.category))
|
||||
|
||||
for tournoi, cat in tournois.items():
|
||||
if tournoi == "Lyon":
|
||||
continue
|
||||
|
||||
jury_channel: TextChannel = get(
|
||||
guild.text_channels, category=cat, name="cro"
|
||||
)
|
||||
await jury_channel.delete()
|
||||
# jury = get(guild.roles, name=f"Jury {tournoi}")
|
||||
orga = get(guild.roles, name=f"Orga {tournoi}")
|
||||
ov = {
|
||||
guild.default_role: nothing,
|
||||
# jury: see,
|
||||
orga: see,
|
||||
}
|
||||
await guild.create_text_channel(
|
||||
f"cro-{tournoi}", category=cat, overwrites=ov
|
||||
)
|
||||
|
||||
await ctx.send(str(jury_channel))
|
||||
|
||||
|
||||
def setup(bot: Bot):
|
||||
bot.add_cog(DevCog(bot))
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
#!/bin/python
|
||||
|
||||
|
||||
#!/bin/python
|
||||
|
||||
import asyncio
|
||||
import random
|
||||
from collections import defaultdict, namedtuple
|
||||
|
@ -667,7 +664,7 @@ class TirageCog(Cog, name="Tirages"):
|
|||
@draw_group.command(
|
||||
name="start", usage="équipe1 équipe2 équipe3 (équipe4)",
|
||||
)
|
||||
@commands.has_role(Role.ORGA)
|
||||
@commands.has_any_role(*Role.ORGAS)
|
||||
async def start(self, ctx: Context, *teams: discord.Role):
|
||||
"""
|
||||
(orga) Commence un tirage avec 3 ou 4 équipes.
|
||||
|
@ -720,7 +717,7 @@ class TirageCog(Cog, name="Tirages"):
|
|||
await self.tirages[channel_id].phase.start(ctx)
|
||||
|
||||
@draw_group.command(name="abort")
|
||||
@commands.has_role(Role.ORGA)
|
||||
@commands.has_any_role(*Role.ORGAS)
|
||||
async def abort_draw_cmd(self, ctx):
|
||||
"""
|
||||
(orga) Annule le tirage en cours.
|
||||
|
|
|
@ -11,6 +11,7 @@ __all__ = [
|
|||
"TEAMS_FILE",
|
||||
"TEAMS_CHANNEL_CATEGORY",
|
||||
"DIEGO",
|
||||
"TOURNOIS",
|
||||
]
|
||||
|
||||
TOKEN = os.environ.get("TFJM_DISCORD_TOKEN")
|
||||
|
@ -27,11 +28,24 @@ if TOKEN is None:
|
|||
GUILD = "690934836696973404"
|
||||
DIEGO = "Diego" # Mon display name
|
||||
|
||||
TOURNOIS = [
|
||||
"Lille",
|
||||
"Lyon",
|
||||
"Paris-Saclay",
|
||||
"Avignon",
|
||||
"Paris-Est",
|
||||
"Tours",
|
||||
"Bordeaux",
|
||||
"Nancy",
|
||||
"Rennes",
|
||||
]
|
||||
|
||||
|
||||
class Role:
|
||||
CNO = "CNO"
|
||||
DEV = "dev"
|
||||
ORGA = "Orga"
|
||||
ORGAS = tuple(f"Orga {t}" for t in TOURNOIS)
|
||||
BENEVOLE = "Bénévole"
|
||||
CAPTAIN = "Capitaine"
|
||||
PARTICIPANT = "Participant"
|
||||
|
|
Loading…
Reference in New Issue