diff --git a/mumbledj/mumbledj.rb b/mumbledj/mumbledj.rb index 78d365c..ae201df 100644 --- a/mumbledj/mumbledj.rb +++ b/mumbledj/mumbledj.rb @@ -4,6 +4,7 @@ require "mumble-ruby" require_relative "config" +require_relative "song_queue" # Class that defines MumbleDJ behavior. class MumbleDJ @@ -21,6 +22,7 @@ class MumbleDJ @server_address = server_address @server_port = server_port @default_channel = default_channel + @song_queue = SongQueue.new Mumble.configure do |conf| conf.sample_rate = 48000 @@ -79,9 +81,18 @@ class MumbleDJ else @client.text_user(@sender, "The URL you provided was not valid.") end + else + @client.text_user(@sender, NO_PERMISSION_MSG) end when SKIP_ALIAS - puts("Skip command request.") + if has_permission?(ADMIN_SKIP, @sender) + if OUTPUT_ENABLED + puts("#{@sender} has voted to skip the current song.") + end + @song_queue.get_current_song.add_skip(@sender) + else + @client.text_user(@sender, NO_PERMISSION_MSG) + end when VOLUME_ALIAS puts("Volume command request.") when MOVE_ALIAS @@ -91,11 +102,18 @@ class MumbleDJ rescue Mumble::ChannelNotFound @client.text_user(@sender, "The channel you provided does not exist.") end + else + @client.text_user(@sender, NO_PERMISSION_MSG) end + # This one doesn't work for some reason. Gotta do some testing. when KILL_ALIAS - puts("Kill command request.") + if has_permission?(ADMIN_KILL, @sender) + disconnect + else + @client.text_user(@sender, NO_PERMISSION_MSG) + end else - puts("The command you have entered is not valid.") + @client.text_user(@sender, INVALID_COMMAND_MSG) end end end @@ -108,12 +126,6 @@ class MumbleDJ end end - # Attempts to add the requested song to the queue, returns true if the - # song was successfully queued, false otherwise. - def song_add_successful?(song_url, sender) - - end - # Safely disconnects the bot from the server. def disconnect @client.disconnect diff --git a/mumbledj/song.rb b/mumbledj/song.rb new file mode 100644 index 0000000..51cefb0 --- /dev/null +++ b/mumbledj/song.rb @@ -0,0 +1,37 @@ +# MumbleDJ v2 +# By Matthieu Grieger +# song.rb + +# Base Song class that defines default behavior for any kind of song. +class Song + + # Starts the song. + def start + + end + + # Gets the name of the user who submitted the song. + def get_submitter + return @submitter + end + + # Adds a skipper to the skips array for the current song. + def add_skip(username) + + end +end + +class YouTubeSong < Song + + # Initializes the YouTubeSong object and retrieves the song title, + # duration, and thumbnail URL from the YouTube API. + def initialize(url, submitter) + @url = url + @submitter = submitter + @skips = [] + # TODO: Retrieve YouTube information + @song_title = "" + @song_duration = "" + @song_thumbnail_url = "" + end +end diff --git a/mumbledj/song_queue.rb b/mumbledj/song_queue.rb new file mode 100644 index 0000000..697a271 --- /dev/null +++ b/mumbledj/song_queue.rb @@ -0,0 +1,67 @@ +# MumbleDJ v2 +# By Matthieu Grieger +# song_queue.rb + +require_relative "song" + +# A specialized SongQueue class that handles queueing/unqueueing songs +# and other actions. +class SongQueue + + # Initializes a new song queue. + def initialize + @queue = [] + end + + # Checks if song already exists in the queue, and adds it if it doesn't + # already exist. + def add_song(url, submitter) + # TODO: Determine which kind of URL is given (probably using regex), + # and instantiate the correct Song object. + # Example for a YouTube URL given below. + + if @queue.empty? + song = YouTubeSong.new(url, submitter) + @queue.push(song) + else + @queue.each do |song| + if song.url == url + song = YouTubeSong.new(url, submitter) + @queue.push(song) + end + end + end + end + + # Processes a song delete request. Searches the queue for songs with + # titles containing the keyword. If found, the song is deleted if the + # username of the user who requested the deletion matches the + # username of who originally added the song. + def delete_song?(keyword, username) + if not @queue.empty? + @queue.each do |song| + if song.song_title.includes?(keyword) + if song.get_submitter == username + @queue.delete(song) + return true + end + end + end + return false + else + return false + end + + end + + # Returns a formatted string that contains information about the next + # song in the queue. + def peek_next + + end + + # Returns the current Song object from the queue. + def get_current_song + return @queue[0] + end +end