From c9a496d47875571f9cb5075ca944e61c9d8f9678 Mon Sep 17 00:00:00 2001 From: Astoria Floyd Date: Sat, 20 Nov 2021 17:57:10 -0600 Subject: [PATCH] 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. --- modules/listQueue/main.rb | 28 +++++++++++++++ modules/modules.txt | 4 ++- modules/pauseMusic/main.rb | 69 ++++++------------------------------ modules/pingcommand/main.rb | 6 +--- modules/playMusic/main.rb | 10 ++---- modules/quit/main.rb | 12 +++---- modules/reload/main.rb | 6 +--- modules/skipMusic/main.rb | 6 +--- modules/stopMusic/main.rb | 14 ++++---- modules/unpauseMusic/main.rb | 19 ++++++++++ modules/volumeMusic/main.rb | 25 +++++++++++++ 11 files changed, 102 insertions(+), 97 deletions(-) create mode 100644 modules/listQueue/main.rb create mode 100644 modules/unpauseMusic/main.rb create mode 100644 modules/volumeMusic/main.rb diff --git a/modules/listQueue/main.rb b/modules/listQueue/main.rb new file mode 100644 index 0000000..a6034d3 --- /dev/null +++ b/modules/listQueue/main.rb @@ -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 \ No newline at end of file diff --git a/modules/modules.txt b/modules/modules.txt index 78f3b1e..18a5c1a 100644 --- a/modules/modules.txt +++ b/modules/modules.txt @@ -3,4 +3,6 @@ playMusic quit reload skipMusic -stopMusic \ No newline at end of file +stopMusic +volumeMusic +listQueue \ No newline at end of file diff --git a/modules/pauseMusic/main.rb b/modules/pauseMusic/main.rb index c375dee..4363cbe 100644 --- a/modules/pauseMusic/main.rb +++ b/modules/pauseMusic/main.rb @@ -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 \ No newline at end of file diff --git a/modules/pingcommand/main.rb b/modules/pingcommand/main.rb index e4461c7..b38f8ba 100644 --- a/modules/pingcommand/main.rb +++ b/modules/pingcommand/main.rb @@ -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 \ No newline at end of file diff --git a/modules/playMusic/main.rb b/modules/playMusic/main.rb index c4bf220..251a704 100644 --- a/modules/playMusic/main.rb +++ b/modules/playMusic/main.rb @@ -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 diff --git a/modules/quit/main.rb b/modules/quit/main.rb index ddb6057..cff07ba 100644 --- a/modules/quit/main.rb +++ b/modules/quit/main.rb @@ -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 \ No newline at end of file diff --git a/modules/reload/main.rb b/modules/reload/main.rb index 277223e..0aafcb5 100644 --- a/modules/reload/main.rb +++ b/modules/reload/main.rb @@ -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) diff --git a/modules/skipMusic/main.rb b/modules/skipMusic/main.rb index 2e2a2a2..d7009f5 100644 --- a/modules/skipMusic/main.rb +++ b/modules/skipMusic/main.rb @@ -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) diff --git a/modules/stopMusic/main.rb b/modules/stopMusic/main.rb index 8803e2c..8f952f0 100644 --- a/modules/stopMusic/main.rb +++ b/modules/stopMusic/main.rb @@ -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() diff --git a/modules/unpauseMusic/main.rb b/modules/unpauseMusic/main.rb new file mode 100644 index 0000000..3b87839 --- /dev/null +++ b/modules/unpauseMusic/main.rb @@ -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 \ No newline at end of file diff --git a/modules/volumeMusic/main.rb b/modules/volumeMusic/main.rb new file mode 100644 index 0000000..ee47ec4 --- /dev/null +++ b/modules/volumeMusic/main.rb @@ -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 \ No newline at end of file