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

Début de la migration

parent 148dfd1a
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"
gem "rake"
gem "net-yail"
gem "cinch"
gem "rspec"
gem "activerecord"
gem "activesupport"
......
......@@ -2,59 +2,60 @@ GEM
remote: http://rubygems.org/
specs:
activerecord (1.6.0)
activesupport (3.2.11)
i18n (~> 0.6)
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
builder (3.1.4)
diff-lcs (1.1.3)
faraday (0.8.4)
builder (3.2.0)
cinch (2.0.4)
diff-lcs (1.2.1)
faraday (0.8.7)
multipart-post (~> 1.1)
hashie (1.2.0)
hashie (2.0.3)
httmultiparty (0.3.8)
httparty (>= 0.7.3)
multipart-post
httparty (0.9.0)
httparty (0.10.2)
multi_json (~> 1.0)
multi_xml
multi_xml (>= 0.5.2)
httpauth (0.2.0)
i18n (0.6.1)
jwt (0.1.5)
multi_json (>= 1.0)
multi_json (1.5.0)
multi_xml (0.5.1)
multipart-post (1.1.5)
net-yail (1.6.0)
nokogiri (1.5.6)
jwt (0.1.8)
multi_json (>= 1.5)
multi_json (1.7.2)
multi_xml (0.5.3)
multipart-post (1.2.0)
nokogiri (1.5.9)
oauth (0.4.7)
oauth2 (0.8.0)
oauth2 (0.9.1)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
multi_xml (~> 0.5)
rack (~> 1.2)
rack (1.4.3)
rake (10.0.3)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.1)
simple_oauth (0.1.9)
rack (1.5.2)
rake (10.0.4)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.0)
simple_oauth (0.2.0)
soundcloud (0.3.1)
hashie
httmultiparty (>= 0.3)
httparty (>= 0.7.3)
sqlite3 (1.3.6)
youtube_it (2.1.8)
sqlite3 (1.3.7)
youtube_it (2.1.13)
builder
faraday (~> 0.8)
nokogiri (~> 1.5.2)
oauth (~> 0.4.4)
oauth2 (~> 0.6)
simple_oauth (~> 0.1.5)
simple_oauth (>= 0.1.5)
PLATFORMS
ruby
......@@ -62,7 +63,7 @@ PLATFORMS
DEPENDENCIES
activerecord
activesupport
net-yail
cinch
rake
rspec
soundcloud
......
......@@ -20,8 +20,8 @@ class Options
exit
end
opts.on('-s', '--silent', 'set log to FATAL') do
@options[:silent] = true
opts.on('-v', '--verbose', 'enable verbose mode') do
@options[:verbose] = true
end
opts.on('-a', '--admin', 'admin nick') do
......@@ -29,7 +29,7 @@ class Options
end
opts.on('-n', '--network', 'server address') do
@options[:address] = arg
@options[:server] = arg
end
opts.on('-p', '--port', 'server port') do
......@@ -49,8 +49,11 @@ class Options
end
end
@options[:silent] ||= false
@options[:nicknames] ||= ['PlayBot', 'Play_Bot', 'Play__Bot', 'Play___Bot']
@options[:verbose] ||= false
@options[:nick] ||= "PlayBot"
@options[:nicks] ||= ['Play_Bot', 'Play__Bot', 'Play___Bot']
@options[:realname] || = "PlayBot"
@options[:user] ||= "PlayBot"
@options[:channels] ||= ['#hormone']
@options
end
......
......@@ -7,20 +7,21 @@ require 'soundcloud'
# SitePlugin for Soundcloud
#
# Need an client ID (soundcloud_client_id).
class SoundcloudPlugin < SitePlugin
def self.can_handle?(site)
site =~ /^https?:\/\/(www\.)?soundcloud\.com\/[a-zA-Z0-9\/_-]+$/
end
class SoundCloud
include Cinch::Plugin
public
def initialize(options)
@client = Soundcloud.new(:client_id => options[:soundcloud_client_id])
end
match /^https?:\/\/(www\.)?soundcloud\.com\/[a-zA-Z0-9\/_-]+$/
def get(url)
track = @client.get('/resolve', :url => url)
client = Soundcloud.new(:client_id => config[:client_id])
track = client.get('/resolve', :url => url)
url.gsub(/http:\/\//, 'https://')
{:title => track.title, :author => track.user.username, :url => url}
end
def execute(m, url)
infos = get(url)
m.reply("#{infos.title} | #{infos.author}")
end
end
require_relative '../lib/site_plugin.rb'
require 'rubygems'
require 'bundler/setup'
require 'cinch'
require 'youtube_it'
# SitePlugin for YouTube
class YoutubePlugin < SitePlugin
def self.can_handle?(site)
site =~ /^https?:\/\/((www.)?youtube.(fr|com)\/watch\?v=|youtu\.be\/)[a-zA-Z0-9-]+$/
end
class Youtube
include Cinch::Plugin
public
def initialize(options)
@client = YouTubeIt::Client.new
end
match /^https?:\/\/((www.)?youtube.(fr|com)\/watch\?v=|youtu\.be\/)[a-zA-Z0-9-]+$/
def get(url)
video = @client.video_by(url)
client = YouTubeIt::Client.new
video = client.video_by(url)
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
def execute(m, url)
infos = get(url)
m.reply("#{infos.title} | #{infos.author}")
end
end
#!/usr/bin/ruby
require 'rubygems'
require 'bundler/setup'
require 'cinch'
require 'active_support/core_ext/hash/except.rb'
require 'logger'
require_relative 'lib/playbot'
require_relative 'lib/options'
# This code start the PlayBot with somes options.
# --
# Changing working directory so the inclusion of plugin can be done correctly.
# I don't complety know why, but this is necessary.
Dir.chdir(File.expand_path File.dirname(__FILE__))
# --
# Add plugins folder to LOAD_PATH and subsequently require all plugins.
Dir[File.join('plugins', '*.rb')].each { |file| require_relative file }
# Monkey patch for String class
class String
def to_class
chain = self.split "::"
klass = Kernel
chain.each do |klass_string|
klass = klass.const_get klass_string
end
klass.is_a?(Class) ? klass : nil
rescue NameError
nil
end
end
# This code start the PlayBot with somes options.
options = Options.new.read_all
ActiveRecord::Base.establish_connection(options[:database])
ActiveRecord::Base.logger = Logger.new(File.open(options[:database][:log], 'a'))
bot = PlayBot.new(options)
bot.irc_loop
bot = Cinch::Bot.new do
configure do |c|
c = options
# we add the plugins
c.plugins.plugins = []
options[:plugins].each do |plugin|
c.plugins.plugins << plugin.to_class
c.plugins.options[plugin.to_class] = options[plugin.to_s].
end
c.plugins.prefix = nil
end
end
bot.start
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter