More cleanup, implemented skips
This commit is contained in:
parent
24bd000c20
commit
b3db878d9f
|
@ -42,7 +42,7 @@ class MumbleDJ
|
|||
end
|
||||
end
|
||||
|
||||
self.set_callbacks
|
||||
set_callbacks
|
||||
|
||||
@client.connect
|
||||
@client.on_connected do
|
||||
|
@ -131,20 +131,28 @@ class MumbleDJ
|
|||
|
||||
def add(sender, url)
|
||||
if OUTPUT_ENABLED
|
||||
puts("#{@sender} has added a song to the queue.")
|
||||
puts("#{sender} has added a song to the queue.")
|
||||
end
|
||||
if song_add_successful?(url, @sender)
|
||||
@client.text_channel(@client.me.current_channel.name, "<b>#{@sender}</b> has added a song to the queue.")
|
||||
if song_add_successful?(url, sender)
|
||||
@client.text_channel(@client.me.current_channel.name, "<b>#{sender}</b> has added a song to the queue.")
|
||||
else
|
||||
@client.text_user(@sender, "The URL you provided was not valid.")
|
||||
@client.text_user(sender, "The URL you provided was not valid.")
|
||||
end
|
||||
end
|
||||
|
||||
def skip(sender)
|
||||
if OUTPUT_ENABLED
|
||||
puts("#{@sender} has voted to skip the current song.")
|
||||
puts("#{sender} has voted to skip the current song.")
|
||||
end
|
||||
if @song_queue.get_current_song.add_skip?(sender)
|
||||
@client.text_channel(@client.me.current_channel.name, "<b>#{sender}</b> has voted to skip the current song.")
|
||||
if @song_queue.get_current_song.skip_now?(@client.me.current_channel.users.count - 1)
|
||||
@client.text_channel(@client.me.current_channel.name, "Number of required skip votes has been met. Skipping song!")
|
||||
@song_queue.get_current_song.skip
|
||||
end
|
||||
else
|
||||
@client.text_user(sender, "You have already voted to skip this song.")
|
||||
end
|
||||
@song_queue.get_current_song.add_skip(@sender)
|
||||
end
|
||||
|
||||
def volume(sender, vol)
|
||||
|
|
|
@ -16,8 +16,19 @@ class Song
|
|||
end
|
||||
|
||||
# Adds a skipper to the skips array for the current song.
|
||||
def add_skip(username)
|
||||
|
||||
def add_skip?(username)
|
||||
if not @skips.include?(username)
|
||||
@skips << username
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# Determines if a skip should occur. Returns true if a skip is needed,
|
||||
# false otherwise.
|
||||
def skip_now?(total_users)
|
||||
return (total_users / @skips.count) >= SKIP_RATIO
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class SongQueue
|
|||
|
||||
# Checks if song already exists in the queue, and adds it if it doesn't
|
||||
# already exist.
|
||||
def add_song(url, submitter)
|
||||
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.
|
||||
|
@ -26,10 +26,11 @@ class SongQueue
|
|||
else
|
||||
@queue.each do |song|
|
||||
if song.url == url
|
||||
song = YouTubeSong.new(url, submitter)
|
||||
@queue.push(song)
|
||||
return false
|
||||
end
|
||||
end
|
||||
song = YouTubeSong.new(url, submitter)
|
||||
@queue.push(song)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Reference in a new issue