Major fixes to music system, youtube search working, a queue system, skip and stop, reload works, quit works, ping works. General refactors.

master
Astoria Floyd 3 years ago
parent 391470c936
commit f8a725b771

@ -1,5 +1,6 @@
pingcommand
pongcommand
playMusic
quit
reload
reload
skipMusic
stopMusic

@ -0,0 +1,66 @@
def playMusic_initialize(bot, bang)
bot.message(start_with: "#{bang}Play ") do |event|
playMusic(bot, event, bang)
end
bot.message(with_text: "#{bang}Play") do |event|
event.respond "Please provide youtube link!"
end
end
def playMusic_defined()
puts "This should not run"
end
def playMusic(bot, event, bang)
message = event.content
author = event.author
voice_channel = event.author.voice_channel.id
server = event.server
arguments = message.sub("#{bang}Play ", '').split.first
#event.voice.play_file('./example.mp3')
if arguments.include? "&list"
event.respond "Do not play playlists. They are unsupported."
elsif 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
elsif arguments.include? "youtu"
actuallyPlayMusic(bot, event, arguments, voice_channel, server)
else
event.respond "Invalid youtube link!"
end
end
def actuallyPlayMusic(bot, event, arguments, voice_channel, server)
event.respond "Playing song! This may take some time."
bot.voice_connect(voice_channel)
ENV["#{voice_channel}"] = 'playing'
tempFile = Dir::Tmpname.create(['youtubedlruby-', '.mp3']) {}
cmd = "yt-dlp --extract-audio --audio-format mp3 --output " + tempFile + " " + arguments
if arguments.include? "youtu"
system(cmd)
end
event.voice.play_file(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(bot, event, $queue[voice_channel].shift, voice_channel, server)
else
bot.voice_destroy(server)
event.respond "Done playing!"
ENV["#{voice_channel}"] = 'open'
end
else
bot.voice_destroy(server)
event.respond "Done playing!"
ENV["#{voice_channel}"] = 'open'
end
end

@ -1,9 +1,11 @@
def pingcommand_initialize(bot, bang)
bot.message(with_text: "#{bang}Ping") do |event|
ping(bot, event)
end
def pingcommand_main(event)
event.respond "Ping!"
end
def ping(bot, event)
event.respond 'Pong!'
def pingcommand_getName()
return "ping"
end
def pingcommand_getCommand()
return "pingcommand_main"
end

@ -1,65 +1,72 @@
def playMusic_initialize(bot, bang)
bot.message(start_with: "#{bang}Play ") do |event|
playMusic(bot, event, bang)
end
bot.message(with_text: "#{bang}Play") do |event|
event.respond "Please provide youtube link!"
end
def playMusic_getName()
return "play"
end
def playMusic_defined()
puts "This should not run"
def playMusic_getCommand()
return "playMusic_main"
end
def playMusic(bot, event, bang)
def playMusic_main(event)
message = event.content
author = event.author
voice_channel = author.voice_channel.id
server = event.server
arguments = message.sub("#{bang}Play ", '').split.first
#event.voice.play_file('./example.mp3')
if arguments.include? "&list"
event.respond "Do not play playlists. They are unsupported."
elsif 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]
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
$queue[voice_channel].push arguments
puts $queue[voice_channel]
actuallyPlayMusic(event, arguments, voice_channel)
end
elsif arguments.include? "youtu"
actuallyPlayMusic(bot, event, arguments, voice_channel, server)
else
event.respond "Invalid youtube link!"
end
end
def actuallyPlayMusic(bot, event, arguments, voice_channel, server)
event.respond "Playing song! This may take some time."
bot.voice_connect(voice_channel)
def actuallyPlayMusic(event, arguments, voice_channel)
event.respond "Searching for song! This may take some time."
ENV["#{voice_channel}"] = 'playing'
tempFile = Dir::Tmpname.create(['youtubedlruby-', '.mp3']) {}
cmd = "yt-dlp --extract-audio --audio-format mp3 --output " + tempFile + " " + arguments
if arguments.include? "youtu"
system(cmd)
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
event.voice.play_file(tempFile)
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(bot, event, $queue[voice_channel].shift, voice_channel, server)
actuallyPlayMusic(event, $queue[voice_channel].shift, voice_channel)
else
bot.voice_destroy(server)
$voicebots.delete(voice_channel)
voiceBot.destroy()
event.respond "Done playing!"
ENV["#{voice_channel}"] = 'open'
end
else
bot.voice_destroy(server)
$voicebots.delete(voice_channel)
voiceBot.destroy()
event.respond "Done playing!"
ENV["#{voice_channel}"] = 'open'
end

@ -1,14 +1,16 @@
def quit_initialize(bot, bang)
bot.message(with_text: "#{bang}Quit") do |event|
quit(bot, event)
end
end
def quit(bot, event)
def quit_main(event)
if event.user.id == 185533351866662913
bot.send_message(event.channel.id, 'Bot is shutting down')
bot.stop
$bot.send_message(event.channel.id, 'Bot is shutting down')
$bot.stop
else
event.respond "You cannot quit this bot!"
end
end
def quit_getName()
return "quit"
end
def quit_getCommand()
return "quit_main"
end

@ -1,19 +1,12 @@
def reload_initialize(bot, bang)
bot.message(with_text: "#{bang}Reload") do |event|
reload(event)
end
def reload_getName()
return "reload"
end
def reload(event)
event.respond 'Reloading!'
File.foreach("modules/modules.txt", chop: true) { |line|
mod = "./modules/" + line + "/main.rb"
code = "defined? #{line.delete("\n")}_initialize"
if eval(code) == nil
load mod.delete("\n")
send("#{line.delete("\n")}_initialize", bot, bang)
else
load mod.delete("\n")
end
}
def reload_getCommand()
return "reload_main"
end
def reload_main(event)
emery_loadModules
event.respond "Reloading!"
end

@ -0,0 +1,19 @@
def skipMusic_getName()
return "skip"
end
def skipMusic_getCommand()
return "skipMusic_main"
end
def skipMusic_main(event)
voice_channel = event.author.voice_channel.id
if ENV["#{voice_channel}"] == 'playing'
event.respond "Skipping currently playing song"
voiceBot = $voicebots[voice_channel]
voiceBot.stop_playing()
ENV["#{voice_channel}"] = 'open'
else
event.respond "Bot not playing!"
end
end

@ -0,0 +1,24 @@
def stopMusic_getName()
return "stop"
end
def stopMusic_getCommand()
return "stopMusic_main"
end
def stopMusic_main(event)
voice_channel = event.author.voice_channel.id
if ENV["#{voice_channel}"] == 'playing'
event.respond "Stopping music"
while $queue[voice_channel][0] != nil
puts "Stop 2"
$queue[voice_channel].pop
end
voiceBot = $voicebots[voice_channel]
voiceBot.destroy()
ENV["#{voice_channel}"] = 'open'
else
event.respond "Bot not playing!"
end
end
Loading…
Cancel
Save