diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..da2a82a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim + +WORKDIR /app + +ENV UV_COMPILE_BYTECODE=1 +ENV UV_LINK_MODE=copy + +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --frozen --no-install-project --no-dev + +ADD . /app + +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen --no-dev + +ENV PATH="/app/.venv/bin:$PATH" + +ENTRYPOINT [] + +CMD ["uv", "run", "python", "-m", "botbotbot"] diff --git a/botbotbot/voice.py b/botbotbot/voice.py index 2ebffb8..10fc3f3 100644 --- a/botbotbot/voice.py +++ b/botbotbot/voice.py @@ -42,6 +42,14 @@ class VoiceBot: guild_ids=self.guild_ids, ) ) + self.bot.add_application_command( + discord.SlashCommand( + self.unjoin_voice, + name="unjoin", + description="Déconnecter du channel vocal", + guild_ids=self.guild_ids, + ) + ) async def random_connect(self) -> None: while True: @@ -131,11 +139,16 @@ class VoiceBot: await self.disconnect_voice(channel.guild) if vo is None or vo.channel != channel: vo = await channel.connect() - self.vo[channel.guild.id] = vo + self.vo[channel.guild.id] = vo return vo async def disconnect_voice(self, guild: discord.Guild) -> None: if vo := self.vo.pop(guild.id, None): + if self.cambai is not None: + source = await discord.FFmpegOpusAudio.from_probe( + self.cambai.tts("À plus les jeunes !") + ) + await vo.play(source, wait_finish=True) await vo.disconnect() async def join_voice(self, ctx: discord.ApplicationContext) -> None: @@ -153,6 +166,21 @@ class VoiceBot: delete_after=30, ) + async def unjoin_voice(self, ctx: discord.ApplicationContext) -> None: + if ctx.user.voice: + await ctx.respond( + f"Disconnecting from voice channel {ctx.user.voice.channel}.", + ephemeral=True, + delete_after=30, + ) + await self.disconnect_voice(ctx.user.voice.channel.guild) + else: + await ctx.respond( + "You are not connected to a voice channel.", + ephemeral=True, + delete_after=30, + ) + async def on_voice_state_update( self, member: discord.Member, diff --git a/pyproject.toml b/pyproject.toml index 0d9c9bb..48512cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ dependencies = [ ] [project.scripts] -hasspy = "botbotbot:main" +botbotbot = "botbotbot:main" [dependency-groups] dev = [