|
|
|
def playMusic_getName()
|
|
|
|
return "play"
|
|
|
|
end
|
|
|
|
|
|
|
|
def playMusic_getCommand()
|
|
|
|
return "playMusic_main"
|
|
|
|
end
|
|
|
|
|
|
|
|
def playMusic_main(event)
|
|
|
|
message = event.content
|
|
|
|
if message == ''
|
|
|
|
event.respond "Please add a search query"
|
|
|
|
else
|
|
|
|
voice_channel = event.author.voice_channel.id
|
|
|
|
arguments = message.sub("!Play ", '').chomp
|
|
|
|
#event.voice.play_file('./example.mp3')
|
|
|
|
if ENV["#{voice_channel}"] == 'playing'
|
|
|
|
event.respond "Music currently playing. Adding to queue"
|
|
|
|
if $queue.key?(voice_channel) == false
|
|
|
|
$queue[voice_channel] = Array.new
|
|
|
|
$queue[voice_channel].push arguments
|
|
|
|
puts $queue[voice_channel]
|
|
|
|
else
|
|
|
|
$queue[voice_channel].push arguments
|
|
|
|
puts $queue[voice_channel]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
actuallyPlayMusic(event, arguments, voice_channel)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def actuallyPlayMusic(event, arguments, voice_channel)
|
|
|
|
event.respond "Searching for song! This may take some time."
|
|
|
|
ENV["#{voice_channel}"] = 'playing'
|
|
|
|
if $voicebots.key?(voice_channel) == false
|
|
|
|
voiceBot = $bot.voice_connect(voice_channel)
|
|
|
|
$voicebots[voice_channel] = voiceBot
|
|
|
|
puts "Instance 1"
|
|
|
|
else
|
|
|
|
voiceBot = $voicebots[voice_channel]
|
|
|
|
puts "Instance 2"
|
|
|
|
end
|
|
|
|
tempFile = Dir::Tmpname.create(['youtubedlruby-', '.mp3']) {}
|
|
|
|
id = `yt-dlp --get-id 'ytsearch:#{arguments}'`
|
|
|
|
puts id
|
|
|
|
name = `yt-dlp --get-title #{id}`
|
|
|
|
puts name
|
|
|
|
cmd = "yt-dlp --extract-audio --audio-format mp3 --output " + tempFile + " https://www.youtube.com/watch?v=#{id}"
|
|
|
|
system(cmd)
|
|
|
|
puts "#{arguments}"
|
|
|
|
event.respond "Playing #{name.chomp}!"
|
|
|
|
voiceBot.play_file(tempFile)
|
|
|
|
#puts arguments
|
|
|
|
#puts tempFile
|
|
|
|
File.delete(tempFile) if File.exist?(tempFile)
|
|
|
|
if $queue.key?(voice_channel) == true
|
|
|
|
if $queue[voice_channel][0] != nil
|
|
|
|
event.respond "Queue exists. Playing next song."
|
|
|
|
actuallyPlayMusic(event, $queue[voice_channel].shift, voice_channel)
|
|
|
|
else
|
|
|
|
$voicebots.delete(voice_channel)
|
|
|
|
voiceBot.destroy()
|
|
|
|
event.respond "Done playing!"
|
|
|
|
ENV["#{voice_channel}"] = 'open'
|
|
|
|
end
|
|
|
|
else
|
|
|
|
$voicebots.delete(voice_channel)
|
|
|
|
voiceBot.destroy()
|
|
|
|
event.respond "Done playing!"
|
|
|
|
ENV["#{voice_channel}"] = 'open'
|
|
|
|
end
|
|
|
|
end
|