From d84586b1e9d98b298b2ccf91abdbd2b1a5ccfe51 Mon Sep 17 00:00:00 2001 From: ddorn Date: Tue, 28 Apr 2020 21:03:35 +0200 Subject: [PATCH] :sparkles: add teams voice channels --- src/cogs/misc.py | 30 +++++++++++++++++++++++++++++- src/cogs/teams.py | 35 +++++++++++++++++++++++++++++++++++ src/constants.py | 2 +- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/cogs/misc.py b/src/cogs/misc.py index be2ab98..9358c8c 100644 --- a/src/cogs/misc.py +++ b/src/cogs/misc.py @@ -1,11 +1,15 @@ import random +import discord from discord.ext.commands import Cog, command, Context, Bot from src.constants import * class MiscCog(Cog, name="Divers"): + def __init__(self, bot: Bot): + self.bot = bot + @command( name="choose", usage='choix1 choix2 "choix 3"...', @@ -24,12 +28,36 @@ class MiscCog(Cog, name="Divers"): @command(name="joke", aliases=["blague"], hidden=True) async def joke_cmd(self, ctx): + await ctx.message.delete() with open(JOKES_FILE) as f: jokes = f.read().split("\n\n\n") msg = random.choice(jokes) await ctx.send(msg) + @command( + name="help-test", hidden=True, + ) + async def help_test(self, ctx: Context, *args): + if not args: + await self.send_bot_help(ctx) + else: + pass + + embed = discord.Embed( + title="Help for `!draw`", + description="Groupe qui continent des commande pour les tirages", + color=0xFFA500, + ) + # embed.set_author(name="*oooo*") + embed.add_field(name="zoulou", value="okokok", inline=True) + embed.add_field(name="lklk", value="mnmn", inline=True) + embed.set_footer(text="thankss!") + await ctx.send(embed=embed) + + async def send_bot_help(self, ctx: Context): + embed = discord.Embed(title="Aide pour le bot du TFJM²",) + def setup(bot: Bot): - bot.add_cog(MiscCog()) + bot.add_cog(MiscCog(bot)) diff --git a/src/cogs/teams.py b/src/cogs/teams.py index e950f67..79973d3 100644 --- a/src/cogs/teams.py +++ b/src/cogs/teams.py @@ -197,6 +197,41 @@ class TeamsCog(Cog, name="Teams"): reason=f"{ctx.author.name} à demandé une channel pour son équipe.", ) + @team.command(name="voice", usage="Nom du salon") + @commands.has_role(Role.CAPTAIN) + async def team_channel(self, ctx, *channel_name): + """ + (cap) Crée une channel vocale privée pour l'équipe + + Crée un endroit de discussion privé seulement pour l'équipe + personne d'autre n'y aura accès. + + Exemple: + `!team voice un-nom-sympa` + """ + + if not channel_name: + await ctx.send( + "Tu dois mettre un nom d'équipe, par exemple " + "`!team channel un-super-nom`" + ) + return + + channel_name = " ".join(channel_name) + + guild: discord.Guild = ctx.guild + team_role = self.teams_for(ctx.author)[0][1] + team_channel_category = get(guild.categories, name=TEAMS_CHANNEL_CATEGORY) + await guild.create_voice_channel( + channel_name, + overwrites={ + guild.default_role: discord.PermissionOverwrite(read_messages=False), + team_role: discord.PermissionOverwrite(read_messages=True), + }, + category=team_channel_category, + reason=f"{ctx.author.name} à demandé une channel vocale pour son équipe.", + ) + def setup(bot: Bot): bot.add_cog(TeamsCog()) diff --git a/src/constants.py b/src/constants.py index 128c5aa..5643c39 100644 --- a/src/constants.py +++ b/src/constants.py @@ -63,4 +63,4 @@ JOKES_FILE = TOP_LEVEL_DIR / "data" / "jokes" with open(TOP_LEVEL_DIR / "data" / "problems") as f: PROBLEMS = f.read().splitlines() -MAX_REFUSE = len(PROBLEMS) - 5 +MAX_REFUSE = len(PROBLEMS) - 4 # -5 usually but not in 2020 because of covid-19