Quartessa/commands.py

85 lines
3.5 KiB
Python
Raw Normal View History

2025-01-18 21:45:25 -05:00
import discord
from discord import app_commands
from audio import (
play_audio,
stop_audio,
set_volume,
join_voice,
leave_voice,
pause_audio,
resume_audio,
repeat_modes,
2025-01-27 17:34:47 -05:00
_247_mode,
generate_recommendations,
)
2025-01-18 21:45:25 -05:00
2025-01-27 17:34:47 -05:00
async def setup_commands(client: discord.Client, guild_id: int | None = None) -> None:
@client.tree.command(name="join", description="Join the user's current voice channel.")
2025-01-27 17:34:47 -05:00
async def join(interaction: discord.Interaction) -> None:
2025-01-18 21:45:25 -05:00
await join_voice(interaction)
@client.tree.command(name="leave", description="Leave the current voice channel.")
2025-01-27 17:34:47 -05:00
async def leave(interaction: discord.Interaction) -> None:
2025-01-18 21:45:25 -05:00
await leave_voice(interaction)
@client.tree.command(name="play", description="Play a song by title or artist.")
2025-01-27 17:34:47 -05:00
async def play(interaction: discord.Interaction, query: str) -> None:
2025-01-18 21:45:25 -05:00
await play_audio(interaction, query)
@client.tree.command(name="stop", description="Stop playback and clear the queue.")
2025-01-27 17:34:47 -05:00
async def stop(interaction: discord.Interaction) -> None:
await stop_audio(interaction)
@client.tree.command(name="pause", description="Pause the current song.")
2025-01-27 17:34:47 -05:00
async def pause(interaction: discord.Interaction) -> None:
await pause_audio(interaction)
@client.tree.command(name="resume", description="Resume the paused song.")
2025-01-27 17:34:47 -05:00
async def resume(interaction: discord.Interaction) -> None:
await resume_audio(interaction)
@client.tree.command(name="repeat", description="Set the repeat mode for playback.")
@app_commands.describe(mode="Repeat mode: 'one', 'all', or 'off'")
2025-01-27 17:34:47 -05:00
async def repeat(interaction: discord.Interaction, mode: str) -> None:
guild_id = interaction.guild.id
valid_modes = ["one", "all", "off"]
if mode not in valid_modes:
await interaction.response.send_message(f"❌ **Invalid mode. Use one of: {', '.join(valid_modes)}.**")
return
repeat_modes[guild_id] = mode
await interaction.response.send_message(f"🔄 **Repeat mode set to:** {mode.capitalize()}.")
@client.tree.command(name="volume", description="Set playback volume.")
2025-01-27 17:34:47 -05:00
async def volume(interaction: discord.Interaction, level: int) -> None:
await set_volume(interaction, level)
2025-01-27 17:34:47 -05:00
@client.tree.command(name="247", description="Enable or disable 24/7 mode.")
@app_commands.describe(mode="on/off")
async def _247(interaction: discord.Interaction, mode: str) -> None:
guild_id = interaction.guild.id
if mode.lower() == "on":
_247_mode[guild_id] = True
await interaction.response.send_message("✅ **24/7 mode enabled. Amber will stay in the voice channel even when idle.**")
elif mode.lower() == "off":
_247_mode[guild_id] = False
await interaction.response.send_message("✅ **24/7 mode disabled. Amber will leave the voice channel when idle.**")
else:
await interaction.response.send_message("❌ **Invalid mode. Use 'on' or 'off'.**")
@client.tree.command(name="recommend", description="Get song recommendations based on your listening history.")
2025-01-27 17:34:47 -05:00
async def recommend(interaction: discord.Interaction) -> None:
user_id = interaction.user.id
recommendations = generate_recommendations(user_id)
embed = discord.Embed(
title="🎵 Recommended Songs",
description="\n".join(recommendations),
color=discord.Color.green()
)
await interaction.response.send_message(embed=embed)
2025-01-18 21:45:25 -05:00
await client.tree.sync()