diff --git a/Emery.rb b/Emery.rb index a91036c..ccb1509 100755 --- a/Emery.rb +++ b/Emery.rb @@ -10,8 +10,13 @@ bang = '!' def loadCommands(bot, bang) File.foreach("modules/modules.txt", chop: true) { |line| mod = "./modules/" + line + "/main.rb" - load mod.delete("\n") - send("#{line.delete("\n")}", bot, bang) + 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 } end $queue = {} diff --git a/modules/modules.txt b/modules/modules.txt index 2e8b83b..e39930a 100644 --- a/modules/modules.txt +++ b/modules/modules.txt @@ -1,4 +1,5 @@ pingcommand pongcommand playMusic -quit \ No newline at end of file +quit +reload \ No newline at end of file diff --git a/modules/pingcommand/main.rb b/modules/pingcommand/main.rb index bf85f15..083f2b6 100644 --- a/modules/pingcommand/main.rb +++ b/modules/pingcommand/main.rb @@ -1,5 +1,9 @@ -def pingcommand(bot, bang) +def pingcommand_initialize(bot, bang) bot.message(with_text: "#{bang}Ping") do |event| - event.respond 'Pong!' + ping(bot, event) end +end + +def ping(bot, event) + event.respond 'Pong!' end \ No newline at end of file diff --git a/modules/playMusic/main.rb b/modules/playMusic/main.rb index 939696c..78cab91 100644 --- a/modules/playMusic/main.rb +++ b/modules/playMusic/main.rb @@ -1,34 +1,43 @@ -def playMusic(bot, bang) +def playMusic_initialize(bot, bang) bot.message(start_with: "#{bang}Play ") do |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] - 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 + 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 = 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) diff --git a/modules/pongcommand/main.rb b/modules/pongcommand/main.rb index a718633..fafab6d 100644 --- a/modules/pongcommand/main.rb +++ b/modules/pongcommand/main.rb @@ -1,5 +1,9 @@ -def pongcommand(bot, bang) +def pongcommand_initialize(bot, bang) bot.message(with_text: "#{bang}Pong") do |event| - event.respond 'Ping!' + pong(event) end +end + +def pong(event) + event.respond 'Ping!!' end \ No newline at end of file diff --git a/modules/quit/main.rb b/modules/quit/main.rb index 29d8718..34ee4a6 100644 --- a/modules/quit/main.rb +++ b/modules/quit/main.rb @@ -1,7 +1,14 @@ -def quit(bot, bang) +def quit_initialize(bot, bang) bot.message(with_text: "#{bang}Quit") do |event| - break unless event.user.id == 185533351866662913 + quit(bot, event) + end +end + +def quit(bot, event) + if event.user.id == 185533351866662913 bot.send_message(event.channel.id, 'Bot is shutting down') bot.stop + else + event.respond "You cannot quit this bot!" end end \ No newline at end of file diff --git a/modules/reload/main.rb b/modules/reload/main.rb new file mode 100644 index 0000000..b76216d --- /dev/null +++ b/modules/reload/main.rb @@ -0,0 +1,19 @@ +def reload_initialize(bot, bang) + bot.message(with_text: "#{bang}Reload") do |event| + reload(event) + end +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 + } +end \ No newline at end of file