Major fixes to music system, youtube search working, a queue system, skip and stop, reload works, quit works, ping works. General refactors.
parent
391470c936
commit
f8a725b771
@ -1,5 +1,6 @@
|
|||||||
pingcommand
|
pingcommand
|
||||||
pongcommand
|
|
||||||
playMusic
|
playMusic
|
||||||
quit
|
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)
|
def pingcommand_main(event)
|
||||||
bot.message(with_text: "#{bang}Ping") do |event|
|
event.respond "Ping!"
|
||||||
ping(bot, event)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def ping(bot, event)
|
def pingcommand_getName()
|
||||||
event.respond 'Pong!'
|
return "ping"
|
||||||
|
end
|
||||||
|
|
||||||
|
def pingcommand_getCommand()
|
||||||
|
return "pingcommand_main"
|
||||||
end
|
end
|
@ -1,14 +1,16 @@
|
|||||||
def quit_initialize(bot, bang)
|
def quit_main(event)
|
||||||
bot.message(with_text: "#{bang}Quit") do |event|
|
|
||||||
quit(bot, event)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def quit(bot, event)
|
|
||||||
if event.user.id == 185533351866662913
|
if event.user.id == 185533351866662913
|
||||||
bot.send_message(event.channel.id, 'Bot is shutting down')
|
$bot.send_message(event.channel.id, 'Bot is shutting down')
|
||||||
bot.stop
|
$bot.stop
|
||||||
else
|
else
|
||||||
event.respond "You cannot quit this bot!"
|
event.respond "You cannot quit this bot!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def quit_getName()
|
||||||
|
return "quit"
|
||||||
|
end
|
||||||
|
|
||||||
|
def quit_getCommand()
|
||||||
|
return "quit_main"
|
||||||
|
end
|
@ -1,19 +1,12 @@
|
|||||||
def reload_initialize(bot, bang)
|
def reload_getName()
|
||||||
bot.message(with_text: "#{bang}Reload") do |event|
|
return "reload"
|
||||||
reload(event)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload(event)
|
def reload_getCommand()
|
||||||
event.respond 'Reloading!'
|
return "reload_main"
|
||||||
File.foreach("modules/modules.txt", chop: true) { |line|
|
end
|
||||||
mod = "./modules/" + line + "/main.rb"
|
|
||||||
code = "defined? #{line.delete("\n")}_initialize"
|
def reload_main(event)
|
||||||
if eval(code) == nil
|
emery_loadModules
|
||||||
load mod.delete("\n")
|
event.respond "Reloading!"
|
||||||
send("#{line.delete("\n")}_initialize", bot, bang)
|
|
||||||
else
|
|
||||||
load mod.delete("\n")
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
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…
Reference in New Issue