first commit
This commit is contained in:
26
bot/commands/__init__.py
Normal file
26
bot/commands/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
import importlib.util
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def load_commands():
|
||||
"""
|
||||
Automatically discover and load command modules from bot/commands/.
|
||||
|
||||
Each module should call register_module() during import.
|
||||
"""
|
||||
commands_dir = os.path.dirname(__file__)
|
||||
for filename in os.listdir(commands_dir):
|
||||
if filename.endswith('.py') and filename != '__init__.py':
|
||||
module_name = filename[:-3] # remove .py
|
||||
module_path = os.path.join(commands_dir, filename)
|
||||
|
||||
try:
|
||||
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
logger.info(f"Loaded command module: {module_name}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to load command module {module_name}: {e}")
|
||||
67
bot/commands/music.py
Normal file
67
bot/commands/music.py
Normal file
@@ -0,0 +1,67 @@
|
||||
"""
|
||||
music.py - Prefix commands for music playback.
|
||||
|
||||
Register:
|
||||
!play <query> - Download and play a song (adds to queue if already playing)
|
||||
!skip - Skip current song, play next
|
||||
!stop - Stop playback, clear queue, leave voice
|
||||
!queue - Show current queue with details
|
||||
!nowplaying - Show currently playing track with remaining time
|
||||
"""
|
||||
|
||||
from bot.prefix_command_registry import register_prefix_command
|
||||
from bot import voice_manager
|
||||
|
||||
|
||||
async def handle_play(message, args):
|
||||
query = " ".join(args)
|
||||
if not query:
|
||||
await message.channel.send("Usage: `!play <song name or URL>`")
|
||||
return
|
||||
|
||||
await voice_manager.resolve_and_enqueue(message, query)
|
||||
|
||||
|
||||
async def handle_skip(message, args):
|
||||
guild_id = message.guild.id
|
||||
vc = voice_manager.connections.get(guild_id)
|
||||
if not vc:
|
||||
await message.channel.send("Not playing anything.")
|
||||
return
|
||||
|
||||
if not vc.is_playing():
|
||||
await message.channel.send("Not playing anything.")
|
||||
return
|
||||
|
||||
voice_manager.skip(guild_id)
|
||||
await message.channel.send("Skipped.")
|
||||
|
||||
|
||||
async def handle_stop(message, args):
|
||||
guild_id = message.guild.id
|
||||
vc = voice_manager.connections.get(guild_id)
|
||||
if not vc:
|
||||
await message.channel.send("Not playing anything.")
|
||||
return
|
||||
|
||||
voice_manager.stop(guild_id)
|
||||
await message.channel.send("Stopped and left voice channel.")
|
||||
|
||||
|
||||
async def handle_queue(message, args):
|
||||
guild_id = message.guild.id
|
||||
output = voice_manager.get_queue(guild_id)
|
||||
await message.channel.send(output)
|
||||
|
||||
|
||||
async def handle_nowplaying(message, args):
|
||||
guild_id = message.guild.id
|
||||
output = voice_manager.get_now_playing(guild_id)
|
||||
await message.channel.send(output)
|
||||
|
||||
|
||||
register_prefix_command("play", handle_play)
|
||||
register_prefix_command("skip", handle_skip)
|
||||
register_prefix_command("stop", handle_stop)
|
||||
register_prefix_command("queue", handle_queue)
|
||||
register_prefix_command("nowplaying", handle_nowplaying)
|
||||
Reference in New Issue
Block a user