|
2 | 2 |
|
3 | 3 | from typing import TYPE_CHECKING |
4 | 4 |
|
| 5 | +import discord |
5 | 6 | from discord import Interaction, Member, app_commands |
6 | 7 | from discord.app_commands import Choice, Transform, Transformer |
7 | 8 | from discord.ext import commands |
@@ -70,3 +71,52 @@ async def add_club_member( |
70 | 71 | return |
71 | 72 | await member.add_roles(interaction.guild.get_role(club.member_role_id)) |
72 | 73 | await interaction.followup.send("Rôle attribué :thumbs_up:") |
| 74 | + |
| 75 | + @app_commands.command(name="create") |
| 76 | + @app_commands.autocomplete(club=autocomplete_club) |
| 77 | + async def create_club(self, interaction: Interaction, club: int): |
| 78 | + await interaction.response.defer(thinking=True) |
| 79 | + serv = interaction.guild |
| 80 | + clu = await self.club_service.get_club(club) |
| 81 | + if clu is None: |
| 82 | + await interaction.followup.send("Erreur : Club introuvable.") |
| 83 | + return |
| 84 | + club_name = clu.name |
| 85 | + |
| 86 | + # region create the role for member, presidence and treasurer |
| 87 | + await serv.create_role( |
| 88 | + name=f"Président {club_name}", color=discord.Color.from_str("#FFFFFF") |
| 89 | + ) |
| 90 | + await serv.create_role( |
| 91 | + name=f"Trésorier {club_name}", color=discord.Color.from_str("#FFFFFF") |
| 92 | + ) |
| 93 | + await serv.create_role( |
| 94 | + name=f"Membre {club_name}", color=discord.Color.from_str("#FFFFFF") |
| 95 | + ) |
| 96 | + # endregion |
| 97 | + |
| 98 | + # region create the clubs category |
| 99 | + """keep in memory roles for the club""" |
| 100 | + president = discord.utils.get(serv.roles, name=f"Président {club_name}") |
| 101 | + membre = discord.utils.get(serv.roles, name=f"Membre {club_name}") |
| 102 | + tresorier = discord.utils.get(serv.roles, name=f"Trésorier {club_name}") |
| 103 | + |
| 104 | + overwrites = { |
| 105 | + serv.default_role: discord.PermissionOverwrite(read_messages=False), |
| 106 | + president: discord.PermissionOverwrite( |
| 107 | + read_messages=True, manage_channels=True |
| 108 | + ), |
| 109 | + membre: discord.PermissionOverwrite(read_messages=True), |
| 110 | + tresorier: discord.PermissionOverwrite(read_messages=True), |
| 111 | + } |
| 112 | + |
| 113 | + await serv.create_category(club_name, overwrites=overwrites) |
| 114 | + # enderegion |
| 115 | + |
| 116 | + # region create default channel |
| 117 | + categorie = discord.utils.get(serv.categories, name=club_name) |
| 118 | + await serv.create_text_channel(f"Général-{club_name}", category=categorie) |
| 119 | + await serv.create_voice_channel(f"Général-{club_name}", category=categorie) |
| 120 | + |
| 121 | + await interaction.followup.send(club_name) |
| 122 | + # endregion |
0 commit comments