Updates to the music modules, plus a few currently unfinished ones. Check modules.txt for both the ones loaded by default, and the ones which are safe.

master
Astoria Floyd 3 years ago
parent bea9003ea8
commit c9a496d478

@ -0,0 +1,28 @@
def listQueue_getCommand()
return ["list", "listQueue_main"]
end
def listQueue_main(event)
voice_channel = event.author.voice_channel.id
if ENV["#{voice_channel}"] == 'playing'
if $queue.key?(voice_channel)
if $queue[voice_channel][0] != nil
x = $queue[voice_channel].length()
y = 0
qlist = ''
while x >= 1
qlist = qlist + "#{$queue[voice_channel][y].lstrip}\n"
y = y + 1
x= x - 1
end
event.respond "Current queue is:\n" + qlist
else
event.respond "No queue!"
end
else
event.respond "No queue!"
end
else
event.respond "Bot not playing!"
end
end

@ -3,4 +3,6 @@ playMusic
quit
reload
skipMusic
stopMusic
stopMusic
volumeMusic
listQueue

@ -1,66 +1,19 @@
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 pauseMusic_getName()
return "pause"
end
def playMusic_defined()
puts "This should not run"
def pauseMusic_getCommand()
return "pauseMusic_main"
end
def playMusic(bot, event, bang)
message = event.content
author = event.author
def pauseMusic_main(event)
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
if ENV["#{voice_channel}"] == 'playing'
event.respond "Pausing currently playing song"
voiceBot = $voicebots[voice_channel]
voiceBot.pause()
ENV["#{voice_channel}"] = 'paused'
else
bot.voice_destroy(server)
event.respond "Done playing!"
ENV["#{voice_channel}"] = 'open'
event.respond "Bot not playing!"
end
end

@ -2,10 +2,6 @@ def pingcommand_main(event)
event.respond "Ping!"
end
def pingcommand_getName()
return "ping"
end
def pingcommand_getCommand()
return "pingcommand_main"
return ["ping", "pingcommand_main"]
end

@ -1,9 +1,5 @@
def playMusic_getName()
return "play"
end
def playMusic_getCommand()
return "playMusic_main"
return ["play", "playMusic_main"]
end
def playMusic_main(event)
@ -12,7 +8,7 @@ def playMusic_main(event)
event.respond "Please add a search query"
else
voice_channel = event.author.voice_channel.id
arguments = message.sub("!Play ", '').chomp
arguments = message.sub(/(!play)/i, '').chomp
#event.voice.play_file('./example.mp3')
if ENV["#{voice_channel}"] == 'playing'
event.respond "Music currently playing. Adding to queue"
@ -32,7 +28,7 @@ end
def actuallyPlayMusic(event, arguments, voice_channel)
event.respond "Searching for song! This may take some time."
ENV["#{voice_channel}"] = 'playing'
ENV["#{voice_channel}"] = ( 'playing' || 'paused' )
if $voicebots.key?(voice_channel) == false
voiceBot = $bot.voice_connect(voice_channel)
$voicebots[voice_channel] = voiceBot

@ -1,3 +1,7 @@
def quit_getCommand()
return ["quit", "quit_main"]
end
def quit_main(event)
if event.user.id == 185533351866662913
$bot.send_message(event.channel.id, 'Bot is shutting down')
@ -5,12 +9,4 @@ def quit_main(event)
else
event.respond "You cannot quit this bot!"
end
end
def quit_getName()
return "quit"
end
def quit_getCommand()
return "quit_main"
end

@ -1,9 +1,5 @@
def reload_getName()
return "reload"
end
def reload_getCommand()
return "reload_main"
return ["reload", "reload_main"]
end
def reload_main(event)

@ -1,9 +1,5 @@
def skipMusic_getName()
return "skip"
end
def skipMusic_getCommand()
return "skipMusic_main"
return ["skip", "skipMusic_main"]
end
def skipMusic_main(event)

@ -1,9 +1,5 @@
def stopMusic_getName()
return "stop"
end
def stopMusic_getCommand()
return "stopMusic_main"
return ["stop", "stopMusic_main"]
end
@ -11,9 +7,11 @@ 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
if $queue.key?(voice_channel)
while $queue[voice_channel][0] != nil
puts "Stop 2"
$queue[voice_channel].pop
end
end
voiceBot = $voicebots[voice_channel]
voiceBot.destroy()

@ -0,0 +1,19 @@
def unpauseMusic_getName()
return "unpause"
end
def unpauseMusic_getCommand()
return "unpauseMusic_main"
end
def unpauseMusic_main(event)
voice_channel = event.author.voice_channel.id
if ENV["#{voice_channel}"] == 'paused'
event.respond "Unpausing currently playing song"
voiceBot = $voicebots[voice_channel]
voiceBot.continue()
ENV["#{voice_channel}"] = 'playing'
else
event.respond "Bot not paused!"
end
end

@ -0,0 +1,25 @@
def volumeMusic_getCommand()
return ["volume", "volumeMusic_main"]
end
def volumeMusic_main(event)
message = event.content
arguments = message.sub(/(!volume)/i, '').chomp
if arguments == ''
event.respond "Please add a volume from 1-200"
else
voice_channel = event.author.voice_channel.id
if ENV["#{voice_channel}"] == 'playing'
volVal = arguments.split.first.to_f
voiceBot = $voicebots[voice_channel]
volVal = volVal / 100
puts volVal
voiceBot.volume = volVal
volVal = volVal * 100
str = "Setting currently playing volume to " + volVal.to_s
event.respond str
else
event.respond "Bot not playing!"
end
end
end
Loading…
Cancel
Save