Now correctly identifies YouTube videos, added attr_readers

This commit is contained in:
Matthieu Grieger 2014-11-20 22:41:59 -08:00
parent b3db878d9f
commit 70dc361f16
4 changed files with 54 additions and 6 deletions

View file

@ -124,4 +124,29 @@ ADMIN_MUTE = true
# DEFAULT VALUE: true
ADMIN_UNMUTE = true
# ---------------------
# MESSAGE CONFIGURATION
# ---------------------
# Message shown to users when they do not have permission to execute a command.
NO_PERMISSION_MSG = "You do not have permission to execute that command."
# Message shown to users when they try to move the bot to a non-existant channel.
CHANNEL_DOES_NOT_EXIST_MSG = "The channel you specified does not exist."
# Message shown to users when they attempt to add an invalid URL to the queue.
INVALID_URL_MSG = "The URL you submitted does not match the required format."
# Message shown to users when they attempt to use the stop command when no music is playing.
NO_MUSIC_PLAYING_MSG = "There is no music playing at the moment."
# Message shown to users when they issue a command that requires an argument and one was not supplied.
NO_ARGUMENT_MSG = "The command you issued requires an argument and you did not provide one. Make sure a space exists between the command and the argument."
# Message shown to users when they try to change the volume to a value outside the volume range.
NOT_IN_VOLUME_RANGE_MSG = "The volume you tried to supply is not in the allowed volume range. The value must be between #{LOWEST_VOLUME} and #{HIGHEST_VOLUME}."
# Message shown to users when they successfully change the volume.
VOLUME_SUCCESS_MSG = "You have successfully changed the volume to the following: %s."

View file

@ -9,6 +9,8 @@ require_relative "song_queue"
# Class that defines MumbleDJ behavior.
class MumbleDJ
attr_reader :username, :server_address, :server_port, :default_channel
# Initializes a new instance of MumbleDJ. The parameters are as follows:
# username: Desired username of the Mumble bot
# server_address: IP address/web address of Mumble server to connect to
@ -126,6 +128,8 @@ class MumbleDJ
def has_permission?(admin_command, sender)
if ENABLE_ADMINS and admin_command
return ADMINS.include?(sender)
else
return true
end
end
@ -133,7 +137,7 @@ class MumbleDJ
if OUTPUT_ENABLED
puts("#{sender} has added a song to the queue.")
end
if song_add_successful?(url, sender)
if @song_queue.add_song?(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.")

View file

@ -33,6 +33,8 @@ class Song
end
class YouTubeSong < Song
attr_reader :url, :submitter, :song_title, :song_duration, :song_thumbnail_url
# Initializes the YouTubeSong object and retrieves the song title,
# duration, and thumbnail URL from the YouTube API.
@ -45,4 +47,9 @@ class YouTubeSong < Song
@song_duration = ""
@song_thumbnail_url = ""
end
# Downloads the audio for the YouTube video and returns the filename.
def download_audio
end
end

View file

@ -7,6 +7,8 @@ require_relative "song"
# A specialized SongQueue class that handles queueing/unqueueing songs
# and other actions.
class SongQueue
attr_reader :queue
# Initializes a new song queue.
def initialize
@ -16,12 +18,20 @@ class SongQueue
# 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.
youtube_regex = /(https?:\/\/www\.youtube\.com\/watch\?v=([\d\a_\-]+))
|(https?:\/\/youtube\.com\/watch\?v=([\d\a_\-]+))
|(https?:\/\/youtu\.be\/([\d\a_\-]+))
|(https?:\/\/youtube\.com\/v\/([\d\a_\-]+))
|(https?:\/\/www\.youtube\.com\/v\/([\d\a_\-]+))/x
if youtube_regex.match(url)
audio_type = "youtube"
end
if @queue.empty?
song = YouTubeSong.new(url, submitter)
if audio_type == "youtube"
song = YouTubeSong.new(url, submitter)
end
@queue.push(song)
else
@queue.each do |song|
@ -29,7 +39,9 @@ class SongQueue
return false
end
end
song = YouTubeSong.new(url, submitter)
if audio_type == "youtube"
song = YouTubeSong.new(url, submitter)
end
@queue.push(song)
end
end