From 5e75dd73a81d6151ff2b71a63ae10bd48650668c Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 4 May 2025 20:58:42 +0200 Subject: [PATCH 1/2] Add unjoin_voice command to allow users to disconnect from voice channels --- botbotbot/voice.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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, From 5faf0b9487720fc4e7e1a9ea623d10220e47c4a9 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 4 May 2025 21:10:41 +0200 Subject: [PATCH 2/2] Add Dockerfile for containerized deployment of the bot --- Dockerfile | 22 ++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Dockerfile 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/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 = [