modified: Dockerfile
modified: bot.py
This commit is contained in:
@@ -4,6 +4,15 @@ FROM python:3.10-slim
|
||||
# Arbeitsverzeichnis erstellen
|
||||
WORKDIR /app
|
||||
|
||||
# System-Dependencies installieren (inkl. FFmpeg für Audio-Support)
|
||||
RUN apt-get update && apt-get install -y \
|
||||
ffmpeg \
|
||||
libffi-dev \
|
||||
libnacl-dev \
|
||||
python3-dev \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Kopiere die requirements-Datei und installiere die Abhängigkeiten
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
169
bot.py
169
bot.py
@@ -2359,9 +2359,21 @@ async def process_ai_queue():
|
||||
await channel.send(embed=embed)
|
||||
|
||||
if ctx.voice_client: # If bot is in a voice channel
|
||||
tts = gTTS(assistant_message, lang="en")
|
||||
tts.save("response.mp3")
|
||||
ctx.voice_client.play(discord.FFmpegPCMAudio("response.mp3"))
|
||||
try:
|
||||
import shutil
|
||||
# Check if FFmpeg is available
|
||||
if not shutil.which("ffmpeg"):
|
||||
await channel.send("⚠️ FFmpeg is not available. Audio playback disabled. (This should not happen in Docker deployment)")
|
||||
else:
|
||||
tts = gTTS(assistant_message, lang="en")
|
||||
tts.save("response.mp3")
|
||||
|
||||
# Check if bot is still connected before playing
|
||||
if ctx.voice_client and ctx.voice_client.is_connected():
|
||||
ctx.voice_client.play(discord.FFmpegPCMAudio("response.mp3"))
|
||||
await channel.send("🔊 Playing TTS audio...")
|
||||
except Exception as e:
|
||||
await channel.send(f"⚠️ TTS audio playback failed: {str(e)}")
|
||||
|
||||
user_history.append({"role": "assistant", "content": assistant_message})
|
||||
|
||||
@@ -5940,6 +5952,157 @@ async def contact_status(ctx):
|
||||
await ctx.send(f"Error getting contact status: {e}")
|
||||
logger.error(f"Error in contact_status: {e}")
|
||||
|
||||
@client.hybrid_command()
|
||||
async def join_voice(ctx):
|
||||
"""Join the voice channel that the user is currently in."""
|
||||
# Check if it's a slash command and defer if needed
|
||||
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
|
||||
if is_slash_command:
|
||||
await ctx.defer()
|
||||
|
||||
# Helper function for sending responses
|
||||
async def send_response(content=None, embed=None, ephemeral=False):
|
||||
try:
|
||||
if is_slash_command and hasattr(ctx, 'followup'):
|
||||
if embed:
|
||||
return await ctx.followup.send(embed=embed, ephemeral=ephemeral)
|
||||
else:
|
||||
return await ctx.followup.send(content, ephemeral=ephemeral)
|
||||
else:
|
||||
# Fallback for regular commands or if followup isn't available
|
||||
if embed:
|
||||
return await ctx.send(embed=embed)
|
||||
else:
|
||||
return await ctx.send(content)
|
||||
except Exception as e:
|
||||
# Final fallback
|
||||
if embed:
|
||||
return await ctx.send(embed=embed)
|
||||
else:
|
||||
return await ctx.send(content)
|
||||
|
||||
if ctx.author.voice is None:
|
||||
await send_response("❌ You need to be in a voice channel for me to join!")
|
||||
return
|
||||
|
||||
voice_channel = ctx.author.voice.channel
|
||||
|
||||
if ctx.voice_client is not None:
|
||||
if ctx.voice_client.channel == voice_channel:
|
||||
await send_response("🔊 I'm already in your voice channel!")
|
||||
return
|
||||
else:
|
||||
await ctx.voice_client.move_to(voice_channel)
|
||||
await send_response(f"🔊 Moved to **{voice_channel.name}**!")
|
||||
return
|
||||
|
||||
try:
|
||||
await voice_channel.connect()
|
||||
await send_response(f"✅ Joined **{voice_channel.name}**! You can now use TTS features.")
|
||||
except Exception as e:
|
||||
await send_response(f"❌ Failed to join voice channel: {str(e)}")
|
||||
|
||||
@client.hybrid_command()
|
||||
async def leave_voice(ctx):
|
||||
"""Leave the current voice channel."""
|
||||
# Check if it's a slash command and defer if needed
|
||||
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
|
||||
if is_slash_command:
|
||||
await ctx.defer()
|
||||
|
||||
# Helper function for sending responses
|
||||
async def send_response(content=None, embed=None, ephemeral=False):
|
||||
try:
|
||||
if is_slash_command and hasattr(ctx, 'followup'):
|
||||
if embed:
|
||||
return await ctx.followup.send(embed=embed, ephemeral=ephemeral)
|
||||
else:
|
||||
return await ctx.followup.send(content, ephemeral=ephemeral)
|
||||
else:
|
||||
# Fallback for regular commands or if followup isn't available
|
||||
if embed:
|
||||
return await ctx.send(embed=embed)
|
||||
else:
|
||||
return await ctx.send(content)
|
||||
except Exception as e:
|
||||
# Final fallback
|
||||
if embed:
|
||||
return await ctx.send(embed=embed)
|
||||
else:
|
||||
return await ctx.send(content)
|
||||
|
||||
if ctx.voice_client is None:
|
||||
await send_response("❌ I'm not in a voice channel!")
|
||||
return
|
||||
|
||||
try:
|
||||
await ctx.voice_client.disconnect()
|
||||
await send_response("👋 Left the voice channel!")
|
||||
except Exception as e:
|
||||
await send_response(f"❌ Failed to leave voice channel: {str(e)}")
|
||||
|
||||
@client.hybrid_command()
|
||||
async def test_tts(ctx, *, text: str = "Hello! This is a TTS test."):
|
||||
"""Test TTS functionality with custom text."""
|
||||
# Check if it's a slash command and defer if needed
|
||||
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
|
||||
if is_slash_command:
|
||||
await ctx.defer()
|
||||
|
||||
# Helper function for sending responses
|
||||
async def send_response(content=None, embed=None, ephemeral=False):
|
||||
try:
|
||||
if is_slash_command and hasattr(ctx, 'followup'):
|
||||
if embed:
|
||||
return await ctx.followup.send(embed=embed, ephemeral=ephemeral)
|
||||
else:
|
||||
return await ctx.followup.send(content, ephemeral=ephemeral)
|
||||
else:
|
||||
# Fallback for regular commands or if followup isn't available
|
||||
if embed:
|
||||
return await ctx.send(embed=embed)
|
||||
else:
|
||||
return await ctx.send(content)
|
||||
except Exception as e:
|
||||
# Final fallback
|
||||
if embed:
|
||||
return await ctx.send(embed=embed)
|
||||
else:
|
||||
return await ctx.send(content)
|
||||
|
||||
if ctx.voice_client is None:
|
||||
await send_response("❌ I need to be in a voice channel first! Use `/join_voice` to get me connected.")
|
||||
return
|
||||
|
||||
if len(text) > 500:
|
||||
await send_response("❌ Text is too long! Please keep it under 500 characters.")
|
||||
return
|
||||
|
||||
try:
|
||||
import shutil
|
||||
from gtts import gTTS
|
||||
|
||||
# Check if FFmpeg is available
|
||||
if not shutil.which("ffmpeg"):
|
||||
await send_response("⚠️ FFmpeg is not available. (This should not happen in Docker deployment)")
|
||||
return
|
||||
|
||||
# Generate TTS audio
|
||||
await send_response("🔄 Generating TTS audio...")
|
||||
|
||||
tts = gTTS(text, lang="en")
|
||||
tts.save("tts_test.mp3")
|
||||
|
||||
# Check if bot is still connected before playing
|
||||
if ctx.voice_client and ctx.voice_client.is_connected():
|
||||
ctx.voice_client.play(discord.FFmpegPCMAudio("tts_test.mp3"))
|
||||
await send_response(f"🔊 Playing TTS: \"{text[:100]}{'...' if len(text) > 100 else ''}\"")
|
||||
else:
|
||||
await send_response("❌ Lost connection to voice channel!")
|
||||
|
||||
except Exception as e:
|
||||
await send_response(f"❌ TTS test failed: {str(e)}")
|
||||
|
||||
try:
|
||||
# Initialize database tables
|
||||
create_warnings_table()
|
||||
|
||||
Reference in New Issue
Block a user