35 lines
1.2 KiB
Kotlin
35 lines
1.2 KiB
Kotlin
package nl.voidcorp.discord.commands.music
|
|
|
|
import nl.voidcorp.discord.command.*
|
|
import nl.voidcorp.discord.music.AudioLoadHandler
|
|
import nl.voidcorp.discord.music.PlayerManager
|
|
import org.springframework.stereotype.Service
|
|
|
|
@Service
|
|
class Play(val playerManager: PlayerManager) :
|
|
Command("play", location = CommandSource.GUILD, group = CommandGroup.MUSIC, usage = "play song url (or song name prepended with ytsearch:)") {
|
|
override fun handle(event: CommandMessage): CommandResult {
|
|
val chan = event.member!!.voiceState!!.channel
|
|
if (chan == null) {
|
|
event.reply("Please join a voice channel to play music!")
|
|
return CommandResult.SUCCESS
|
|
} else if (event.params.drop(1).isEmpty()) {
|
|
event.reply("I'm going to need a url or a search term to actually find a song...")
|
|
return CommandResult.PARAMETERS
|
|
}
|
|
|
|
val am = event.guild!!.audioManager
|
|
|
|
|
|
val ts = playerManager.getGuildPlayer(event.guild)
|
|
|
|
if (!ts.playing) {
|
|
am.openAudioConnection(chan)
|
|
}
|
|
|
|
playerManager.loadItem(event.params.drop(1).joinToString(" "), AudioLoadHandler(ts))
|
|
|
|
|
|
return CommandResult.SUCCESS
|
|
}
|
|
} |