diff options
Diffstat (limited to '')
| -rw-r--r-- | cogs/ai.py | 1 | ||||
| -rw-r--r-- | cogs/voice.py | 60 | ||||
| -rw-r--r-- | requirements.txt | 88 |
3 files changed, 84 insertions, 65 deletions
| @@ -1,7 +1,6 @@ | |||
| 1 | import os | 1 | import os |
| 2 | 2 | ||
| 3 | import discord | 3 | import discord |
| 4 | import google.generativeai as genai | ||
| 5 | from discord.ext import commands | 4 | from discord.ext import commands |
| 6 | import logging | 5 | import logging |
| 7 | import requests | 6 | import requests |
diff --git a/cogs/voice.py b/cogs/voice.py new file mode 100644 index 0000000..600a7eb --- /dev/null +++ b/cogs/voice.py | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | import discord | ||
| 2 | from discord.ext import commands | ||
| 3 | import logging | ||
| 4 | import asyncio | ||
| 5 | |||
| 6 | logger = logging.getLogger(__name__) | ||
| 7 | |||
| 8 | class Voice(commands.Cog): | ||
| 9 | def __init__(self, bot): | ||
| 10 | self.bot = bot | ||
| 11 | |||
| 12 | async def ensure_voice_client(self, ctx): | ||
| 13 | """Ensure we have a valid voice client connection.""" | ||
| 14 | if not ctx.author.voice or not ctx.author.voice.channel: | ||
| 15 | await ctx.send("You need to be in a voice channel first!") | ||
| 16 | return None | ||
| 17 | |||
| 18 | voice_client = discord.utils.get(self.bot.voice_clients, guild=ctx.guild) | ||
| 19 | |||
| 20 | # If no voice client exists, create one | ||
| 21 | if not voice_client or not voice_client.is_connected(): | ||
| 22 | try: | ||
| 23 | voice_client = await ctx.author.voice.channel.connect(timeout=30.0, reconnect=True) | ||
| 24 | logger.info(f"Connected to voice channel: {ctx.author.voice.channel}") | ||
| 25 | except asyncio.TimeoutError: | ||
| 26 | await ctx.send("Connection to voice channel timed out.") | ||
| 27 | except discord.ClientException as e: | ||
| 28 | logger.error(f"Failed to connect to voice channel: {e}") | ||
| 29 | await ctx.send("Failed to connect to voice channel. Please try again.", ephemeral=True) | ||
| 30 | # If we're in a different channel, move to the user's channel | ||
| 31 | elif voice_client.channel != ctx.author.voice.channel: | ||
| 32 | try: | ||
| 33 | await voice_client.move_to(ctx.author.voice.channel) | ||
| 34 | logger.info(f"Moved to voice channel: {ctx.author.voice.channel}") | ||
| 35 | except asyncio.TimeoutError: | ||
| 36 | await ctx.send("Connection to voice channel timed out.") | ||
| 37 | except discord.ClientException as e: | ||
| 38 | logger.error(f"Failed to move to voice channel: {e}") | ||
| 39 | await ctx.send("Failed to move to your voice channel. Please try again.", ephemeral=True) | ||
| 40 | |||
| 41 | # Verify the connection is healthy | ||
| 42 | if not voice_client.is_connected(): | ||
| 43 | try: | ||
| 44 | await voice_client.connect(reconnect=True, timeout=10.0) | ||
| 45 | except Exception as e: | ||
| 46 | logger.error(f"Failed to reconnect to voice: {e}") | ||
| 47 | await ctx.send("Failed to establish voice connection. Please try again.") | ||
| 48 | return None | ||
| 49 | |||
| 50 | async def connect(self, ctx): | ||
| 51 | """Connect to the user's voice channel with improved connection handling.""" | ||
| 52 | voice_client = await self.ensure_voice_client(ctx) | ||
| 53 | if not voice_client: | ||
| 54 | return None | ||
| 55 | |||
| 56 | return voice_client | ||
| 57 | |||
| 58 | |||
| 59 | def setup(bot): | ||
| 60 | bot.add_cog(Voice(bot)) \ No newline at end of file | ||
diff --git a/requirements.txt b/requirements.txt index 1207ad7..958bc7d 100644 --- a/requirements.txt +++ b/requirements.txt | |||
| @@ -1,74 +1,34 @@ | |||
| 1 | aiohappyeyeballs==2.6.1 | 1 | aiohappyeyeballs==2.6.1 |
| 2 | aiohttp==3.12.15 | 2 | aiohttp==3.13.3 |
| 3 | aiosignal==1.4.0 | 3 | aiosignal==1.4.0 |
| 4 | annotated-types==0.7.0 | 4 | anyio==4.12.0 |
| 5 | anyio==4.11.0 | 5 | attrs==25.4.0 |
| 6 | apsw==3.50.4.0 | 6 | beautifulsoup4==4.14.3 |
| 7 | audioop-lts==0.2.2 | 7 | certifi==2025.11.12 |
| 8 | cachetools==6.2.0 | ||
| 9 | certifi==2025.8.3 | ||
| 10 | cffi==2.0.0 | 8 | cffi==2.0.0 |
| 11 | click==8.3.0 | 9 | charset-normalizer==3.4.4 |
| 12 | cryptography==46.0.1 | 10 | click==8.1.8 |
| 13 | cssselect==1.3.0 | 11 | dotenv==0.9.9 |
| 14 | ffmpeg-python==0.2.0 | 12 | ffmpeg==1.4 |
| 15 | frozenlist==1.7.0 | 13 | frozenlist==1.8.0 |
| 16 | future==1.0.0 | ||
| 17 | google-ai-generativelanguage==0.7.0 | ||
| 18 | google-api-core==2.25.1 | ||
| 19 | google-api-python-client==2.183.0 | ||
| 20 | google-auth==2.40.3 | ||
| 21 | google-auth-httplib2==0.2.0 | ||
| 22 | google-genai==1.38.0 | ||
| 23 | google-generativeai==0.8.5 | ||
| 24 | googleapis-common-protos==1.70.0 | ||
| 25 | grpcio==1.75.0 | ||
| 26 | grpcio-status==1.75.0 | ||
| 27 | gTTS==2.5.4 | 14 | gTTS==2.5.4 |
| 28 | h11==0.16.0 | 15 | h11==0.16.0 |
| 29 | httpcore==1.0.9 | 16 | httpcore==1.0.9 |
| 30 | httplib2==0.31.0 | ||
| 31 | httpx==0.28.1 | 17 | httpx==0.28.1 |
| 32 | idna==3.10 | 18 | idna==3.11 |
| 33 | incremental==24.7.2 | 19 | multidict==6.7.0 |
| 34 | jaraco.collections==5.2.1 | 20 | mutagen==1.47.0 |
| 35 | jaraco.functools==4.3.0 | 21 | propcache==0.4.1 |
| 36 | msgpack==1.1.1 | 22 | py-cord==2.7.0 |
| 37 | multidict==6.6.4 | ||
| 38 | path==17.1.1 | ||
| 39 | pdftotext==3.0.0 | ||
| 40 | propcache==0.3.2 | ||
| 41 | proto-plus==1.26.1 | ||
| 42 | protobuf==6.32.1 | ||
| 43 | psutil==7.1.0 | ||
| 44 | py-cord==2.6.1 | ||
| 45 | pyasn1==0.6.1 | ||
| 46 | pyasn1_modules==0.4.2 | ||
| 47 | pycparser==2.23 | 23 | pycparser==2.23 |
| 48 | pydantic==2.11.9 | 24 | PyNaCl==1.6.2 |
| 49 | pydantic_core==2.39.0 | 25 | python-dotenv==1.2.1 |
| 50 | PyGObject==3.54.2 | ||
| 51 | rapidfuzz==3.14 | ||
| 52 | PyNaCl==1.6.0 | ||
| 53 | PyOpenGL==3.1.10 | ||
| 54 | pyparsing==3.2.5 | ||
| 55 | python-dateutil==2.9.0.post0 | ||
| 56 | python-dotenv==1.1.1 | ||
| 57 | pytube==15.0.0 | 26 | pytube==15.0.0 |
| 58 | rsa==4.9.1 | 27 | RapidFuzz==3.14.3 |
| 59 | sniffio==1.3.1 | 28 | requests==2.32.5 |
| 60 | tbb==2022.2.0 | 29 | soupsieve==2.8.1 |
| 61 | tcmlib==1.4.0 | 30 | typing_extensions==4.15.0 |
| 62 | tenacity==9.1.2 | 31 | urllib3==2.6.2 |
| 63 | Twisted==25.5.0 | 32 | yarl==1.22.0 |
| 64 | txaio==25.6.1 | ||
| 65 | typing-inspection==0.4.1 | ||
| 66 | uritemplate==4.2.0 | ||
| 67 | websockets==15.0.1 | ||
| 68 | wsaccel==0.6.7 | ||
| 69 | yarl==1.20.1 | ||
| 70 | youtube-search-python==1.6.6 | 33 | youtube-search-python==1.6.6 |
| 71 | yt-dlp==2025.9.23 | 34 | yt-dlp==2025.12.8 |
| 72 | zeroconf==0.147.2 | ||
| 73 | zope.event==6.0 | ||
| 74 | zope.interface==8.0.1 | ||
