Skip to content
Extraits de code Groupes Projets
Valider ce3c9efa rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

Database support, new config file location

Links are now registered in a database !
Its configurtion muste be
defined in the database section in the config file. The migration for
the database can be done simply using "rake".

The config file has moved !
He must be located at "~/.playbot/config".

Site Plugins return value has changed !
The hash must contain a new key "url". It allow the plugin to normalize
it if many different url can link to a same content.
parent 49dcb78e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
source "http://rubygems.org" source "http://rubygems.org"
gem "rake"
gem "net-yail" gem "net-yail"
gem "rspec" gem "rspec"
gem "activerecord"
gem "sqlite3"
gem "youtube_it" gem "youtube_it"
gem "soundcloud" gem "soundcloud"
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
activerecord (2.3.14)
activesupport (= 2.3.14)
activesupport (2.3.14)
builder (3.1.4) builder (3.1.4)
diff-lcs (1.1.3) diff-lcs (1.1.3)
faraday (0.8.4) faraday (0.8.4)
...@@ -28,6 +31,7 @@ GEM ...@@ -28,6 +31,7 @@ GEM
multi_json (~> 1.0) multi_json (~> 1.0)
rack (~> 1.2) rack (~> 1.2)
rack (1.4.1) rack (1.4.1)
rake (0.9.2.2)
rspec (2.12.0) rspec (2.12.0)
rspec-core (~> 2.12.0) rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0) rspec-expectations (~> 2.12.0)
...@@ -41,6 +45,7 @@ GEM ...@@ -41,6 +45,7 @@ GEM
hashie hashie
httmultiparty (>= 0.3) httmultiparty (>= 0.3)
httparty (>= 0.7.3) httparty (>= 0.7.3)
sqlite3 (1.3.6)
youtube_it (2.1.8) youtube_it (2.1.8)
builder builder
faraday (~> 0.8) faraday (~> 0.8)
...@@ -53,7 +58,10 @@ PLATFORMS ...@@ -53,7 +58,10 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
activerecord
net-yail net-yail
rake
rspec rspec
soundcloud soundcloud
sqlite3
youtube_it youtube_it
require 'active_record'
require 'logger'
require_relative 'lib/options.rb'
task :default => :migrate
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
task :migrate => :environment do
ActiveRecord::Migrator.migrate('lib/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
end
task :environment do
config = Options.new.read_file
ActiveRecord::Base.establish_connection(config[:database])
ActiveRecord::Base.logger = Logger.new(File.open('log/database.log', 'a'))
end
require 'rubygems'
require 'bundler/setup'
class CreateMusics < ActiveRecord::Migration
def self.up
create_table :musics do |t|
t.string :title, :null => false
t.string :author, :null => false
t.string :sender, :null => false
t.string :url, :null => false
t.string :file
end
add_index :musics, :url, :unique
end
def self.down
drop_table :musics
end
end
require 'rubygems'
require 'bundler/setup'
require 'active_record'
class Music < ActiveRecord::Base
end
...@@ -3,7 +3,7 @@ require 'yaml' ...@@ -3,7 +3,7 @@ require 'yaml'
# Allow us to get options, set by user or default ones. # Allow us to get options, set by user or default ones.
class Options class Options
def initialize(file = "#{ENV['HOME']}/.playbot") def initialize(file = "#{ENV['HOME']}/.playbot/config")
@options = {} @options = {}
@file = file @file = file
end end
......
...@@ -5,6 +5,7 @@ require 'bundler/setup' ...@@ -5,6 +5,7 @@ require 'bundler/setup'
require 'net/yail/irc_bot' require 'net/yail/irc_bot'
require_relative 'site_plugin.rb' require_relative 'site_plugin.rb'
require_relative 'music.rb'
# -- # --
...@@ -79,7 +80,13 @@ class PlayBot < IRCBot ...@@ -79,7 +80,13 @@ class PlayBot < IRCBot
return if handler.nil? return if handler.nil?
content = handler.new(@options).get(url) content = handler.new(@options).get(url)
music = Music.create(
msg(event.channel, "#{content[:title]} | #{content[:author]}") :title => content[:title],
:author => content[:author],
:sender => event.nick,
:url => content[:url],
:file => nil)
msg(event.channel, "#{music.title} | #{music.author}")
end end
end end
...@@ -19,7 +19,8 @@ class SoundcloudPlugin < SitePlugin ...@@ -19,7 +19,8 @@ class SoundcloudPlugin < SitePlugin
def get(url) def get(url)
track = @client.get('/resolve', :url => url) track = @client.get('/resolve', :url => url)
url.gsub(/http:\/\//, 'https://')
{:title => track.title, :author => track.user.username} {:title => track.title, :author => track.user.username, :url => url}
end end
end end
...@@ -17,6 +17,7 @@ class YoutubePlugin < SitePlugin ...@@ -17,6 +17,7 @@ class YoutubePlugin < SitePlugin
def get(url) def get(url)
video = @client.video_by(url) video = @client.video_by(url)
{:title => video.title, :author => video.author.name} url.gsub(/https?:\/\/(www.)?youtube.(fr|com)\/watch\?v=|youtu\.be/, 'https://www.youtube.com')
{:title => video.title, :author => video.author.name, :url => url}
end end
end end
#!/usr/bin/ruby #!/usr/bin/ruby
require 'active_record'
require 'logger' require 'logger'
require_relative 'lib/playbot' require_relative 'lib/playbot'
...@@ -8,7 +9,8 @@ require_relative 'lib/options' ...@@ -8,7 +9,8 @@ require_relative 'lib/options'
# This code start the PlayBot with somes options. # This code start the PlayBot with somes options.
options = Options.new.read_all options = Options.new.read_all
puts options
ActiveRecord::Base.establish_connection(options[:database])
bot = PlayBot.new(options) bot = PlayBot.new(options)
bot.irc_loop bot.irc_loop
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter