Now correctly identifies YouTube videos, added attr_readers
This commit is contained in:
parent
b3db878d9f
commit
70dc361f16
|
@ -124,4 +124,29 @@ ADMIN_MUTE = true
|
||||||
# DEFAULT VALUE: true
|
# DEFAULT VALUE: true
|
||||||
ADMIN_UNMUTE = 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."
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ require_relative "song_queue"
|
||||||
# Class that defines MumbleDJ behavior.
|
# Class that defines MumbleDJ behavior.
|
||||||
class MumbleDJ
|
class MumbleDJ
|
||||||
|
|
||||||
|
attr_reader :username, :server_address, :server_port, :default_channel
|
||||||
|
|
||||||
# Initializes a new instance of MumbleDJ. The parameters are as follows:
|
# Initializes a new instance of MumbleDJ. The parameters are as follows:
|
||||||
# username: Desired username of the Mumble bot
|
# username: Desired username of the Mumble bot
|
||||||
# server_address: IP address/web address of Mumble server to connect to
|
# server_address: IP address/web address of Mumble server to connect to
|
||||||
|
@ -126,6 +128,8 @@ class MumbleDJ
|
||||||
def has_permission?(admin_command, sender)
|
def has_permission?(admin_command, sender)
|
||||||
if ENABLE_ADMINS and admin_command
|
if ENABLE_ADMINS and admin_command
|
||||||
return ADMINS.include?(sender)
|
return ADMINS.include?(sender)
|
||||||
|
else
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -133,7 +137,7 @@ class MumbleDJ
|
||||||
if OUTPUT_ENABLED
|
if OUTPUT_ENABLED
|
||||||
puts("#{sender} has added a song to the queue.")
|
puts("#{sender} has added a song to the queue.")
|
||||||
end
|
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.")
|
@client.text_channel(@client.me.current_channel.name, "<b>#{sender}</b> has added a song to the queue.")
|
||||||
else
|
else
|
||||||
@client.text_user(sender, "The URL you provided was not valid.")
|
@client.text_user(sender, "The URL you provided was not valid.")
|
||||||
|
|
|
@ -33,6 +33,8 @@ class Song
|
||||||
end
|
end
|
||||||
|
|
||||||
class YouTubeSong < Song
|
class YouTubeSong < Song
|
||||||
|
|
||||||
|
attr_reader :url, :submitter, :song_title, :song_duration, :song_thumbnail_url
|
||||||
|
|
||||||
# Initializes the YouTubeSong object and retrieves the song title,
|
# Initializes the YouTubeSong object and retrieves the song title,
|
||||||
# duration, and thumbnail URL from the YouTube API.
|
# duration, and thumbnail URL from the YouTube API.
|
||||||
|
@ -45,4 +47,9 @@ class YouTubeSong < Song
|
||||||
@song_duration = ""
|
@song_duration = ""
|
||||||
@song_thumbnail_url = ""
|
@song_thumbnail_url = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Downloads the audio for the YouTube video and returns the filename.
|
||||||
|
def download_audio
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,8 @@ require_relative "song"
|
||||||
# A specialized SongQueue class that handles queueing/unqueueing songs
|
# A specialized SongQueue class that handles queueing/unqueueing songs
|
||||||
# and other actions.
|
# and other actions.
|
||||||
class SongQueue
|
class SongQueue
|
||||||
|
|
||||||
|
attr_reader :queue
|
||||||
|
|
||||||
# Initializes a new song queue.
|
# Initializes a new song queue.
|
||||||
def initialize
|
def initialize
|
||||||
|
@ -16,12 +18,20 @@ class SongQueue
|
||||||
# Checks if song already exists in the queue, and adds it if it doesn't
|
# Checks if song already exists in the queue, and adds it if it doesn't
|
||||||
# already exist.
|
# already exist.
|
||||||
def add_song?(url, submitter)
|
def add_song?(url, submitter)
|
||||||
# TODO: Determine which kind of URL is given (probably using regex),
|
youtube_regex = /(https?:\/\/www\.youtube\.com\/watch\?v=([\d\a_\-]+))
|
||||||
# and instantiate the correct Song object.
|
|(https?:\/\/youtube\.com\/watch\?v=([\d\a_\-]+))
|
||||||
# Example for a YouTube URL given below.
|
|(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?
|
if @queue.empty?
|
||||||
song = YouTubeSong.new(url, submitter)
|
if audio_type == "youtube"
|
||||||
|
song = YouTubeSong.new(url, submitter)
|
||||||
|
end
|
||||||
@queue.push(song)
|
@queue.push(song)
|
||||||
else
|
else
|
||||||
@queue.each do |song|
|
@queue.each do |song|
|
||||||
|
@ -29,7 +39,9 @@ class SongQueue
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
song = YouTubeSong.new(url, submitter)
|
if audio_type == "youtube"
|
||||||
|
song = YouTubeSong.new(url, submitter)
|
||||||
|
end
|
||||||
@queue.push(song)
|
@queue.push(song)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue