added effects to songs!
This commit is contained in:
@@ -3,10 +3,6 @@ from discord.ext.commands.context import Context
|
||||
from discord.ext.commands.converter import CommandError
|
||||
import config
|
||||
from . import queue
|
||||
import asyncio
|
||||
|
||||
# Track last activity time for each server
|
||||
last_activity = {}
|
||||
|
||||
# Joining/moving to the user's vc in a guild
|
||||
async def join_vc(ctx: Context):
|
||||
@@ -24,14 +20,11 @@ async def join_vc(ctx: Context):
|
||||
|
||||
# Join or move to the user's vc
|
||||
if ctx.voice_client is None:
|
||||
vc = await vc.connect(reconnect=True, timeout=60.0)
|
||||
vc = await vc.connect()
|
||||
else:
|
||||
# Safe to ignore type error for now
|
||||
vc = await ctx.voice_client.move_to(vc)
|
||||
|
||||
# Update last activity
|
||||
last_activity[ctx.guild.id] = asyncio.get_event_loop().time()
|
||||
|
||||
return vc
|
||||
|
||||
|
||||
@@ -52,60 +45,8 @@ async def leave_vc(ctx: Context):
|
||||
if author_vc is None or vc != author_vc:
|
||||
raise CommandError("You are not in this voice channel")
|
||||
|
||||
# Clear the queue for this server
|
||||
await queue.clear(ctx.guild.id)
|
||||
|
||||
# Stop any currently playing audio
|
||||
if ctx.voice_client.is_playing():
|
||||
ctx.voice_client.stop()
|
||||
|
||||
# Disconnect with force to ensure it actually leaves
|
||||
try:
|
||||
await ctx.voice_client.disconnect(force=True)
|
||||
except Exception as e:
|
||||
print(f"Error disconnecting: {e}")
|
||||
# If regular disconnect fails, try cleanup
|
||||
await ctx.voice_client.cleanup()
|
||||
|
||||
# Remove from activity tracker
|
||||
if ctx.guild.id in last_activity:
|
||||
del last_activity[ctx.guild.id]
|
||||
|
||||
|
||||
# Auto-disconnect if inactive
|
||||
async def check_inactivity(bot):
|
||||
"""Background task to check for inactive voice connections"""
|
||||
while True:
|
||||
try:
|
||||
current_time = asyncio.get_event_loop().time()
|
||||
|
||||
for guild_id, last_time in list(last_activity.items()):
|
||||
# If inactive for more than 5 minutes
|
||||
if current_time - last_time > 300: # 300 seconds = 5 minutes
|
||||
# Find the guild and voice client
|
||||
guild = bot.get_guild(guild_id)
|
||||
if guild and guild.voice_client:
|
||||
# Check if not playing
|
||||
if not guild.voice_client.is_playing():
|
||||
print(f"Auto-disconnecting from {guild.name} due to inactivity")
|
||||
await queue.clear(guild_id)
|
||||
try:
|
||||
await guild.voice_client.disconnect(force=True)
|
||||
except:
|
||||
pass
|
||||
del last_activity[guild_id]
|
||||
|
||||
# Check every 30 seconds
|
||||
await asyncio.sleep(30)
|
||||
except Exception as e:
|
||||
print(f"Error in inactivity checker: {e}")
|
||||
await asyncio.sleep(30)
|
||||
|
||||
|
||||
# Update activity timestamp when playing
|
||||
def update_activity(guild_id):
|
||||
"""Call this when a song starts playing"""
|
||||
last_activity[guild_id] = asyncio.get_event_loop().time()
|
||||
# Disconnect
|
||||
await ctx.voice_client.disconnect(force=False)
|
||||
|
||||
|
||||
# Build a display message for queuing a new song
|
||||
@@ -131,7 +72,17 @@ async def display_server_queue(ctx: Context, songs, n):
|
||||
color=config.get_color("main"))
|
||||
|
||||
current_song = await queue.get_current_song(ctx.guild.id)
|
||||
display = f"🔊 Currently playing: ``{current_song}``\n\n"
|
||||
loop_mode = await queue.get_loop_mode(ctx.guild.id)
|
||||
volume = await queue.get_volume(ctx.guild.id)
|
||||
effect = await queue.get_effect(ctx.guild.id)
|
||||
|
||||
# Add loop emoji based on mode
|
||||
loop_emojis = {'off': '', 'song': '🔂', 'queue': '🔁'}
|
||||
loop_emoji = loop_emojis.get(loop_mode, '')
|
||||
effect_emoji = queue.get_effect_emoji(effect)
|
||||
|
||||
display = f"🔊 Currently playing: ``{current_song}`` {loop_emoji}\n"
|
||||
display += f"Volume: {volume}% | Loop: {loop_mode} | Effect: {effect_emoji} {effect}\n\n"
|
||||
|
||||
for i, song in enumerate(songs):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user