descartes 0.5.1 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70d53614c92aa0c985b2c8514d8359beaf5a7570
4
- data.tar.gz: 220a70fb3ddbec37db16359468e811e157b5a0ef
3
+ metadata.gz: 2e04a1ec3c104c6178834d8bad31f6ec3541c597
4
+ data.tar.gz: 9bdddb1230425c304deccef0b14d110da7668242
5
5
  SHA512:
6
- metadata.gz: c224bd942027a29b915a3b4717514ab51cbd609163a14c3e3240aab7db3e50fff04af43189c02d330d35c88c5cb19975d3339addb4736f5999c5d19d550f229e
7
- data.tar.gz: c9ddbc0adc6a755d5a68a7dd38ed30bd096f410658c4df4121b63cd9653c90ffa182c5287e93c602d5b605f461cdbb560d763e9bb52d7246abd792135b621dd6
6
+ metadata.gz: 0a295fdbfba13164bb72c8293af021768bba17fbd141b78209077d8f05d29b06429edea339e5aed711fef3301263c298e051dc9bc9baf7bdfcf5cea394c6053b
7
+ data.tar.gz: 0e91e0ec5413b90a72b5abafb30b256e0795656d6f2c6d99b5dfc8139654307637e5392661704d254b2c88e5cc0d9d80d8cb1088c4c8a8497ad59782fa15cc20
data/bin/descartes CHANGED
@@ -15,22 +15,54 @@
15
15
  ##
16
16
 
17
17
  require 'descartes'
18
+ require 'optparse'
19
+ require 'fileutils'
18
20
 
19
- nickname = ARGV[0] || 'Descartes'
20
- server = ARGV[1] || 'irc.rizon.net'
21
- channels = ARGV[2..-1] || ['#aggvistnurummor']
22
- plugins = Descartes.load
21
+ options = {
22
+ :nickname => 'Descartes',
23
+ :server => 'irc.rizon.net',
24
+ :channels => ['#aggvistnurummor'],
25
+ :dotfiles => File.join(ENV['HOME'], '.descartes'),
26
+ :password => 'dat_password'
27
+ }
28
+
29
+ OptionParser.new { |o|
30
+ o.on '-n', '--nickname NICKNAME', 'bot\'s nickname' do |nickname|
31
+ options[:nickname] = nickname
32
+ end
33
+
34
+ o.on '-s', '--server SERVER', 'target IRC server' do |server|
35
+ options[:server] = server
36
+ end
37
+
38
+ o.on '-c', '--channel #chan1,#chan2,#chan3', 'target channels' do |channels|
39
+ options[:channels] = channels.split(?,).map { |s| s.strip }
40
+ end
41
+
42
+ o.on '-d', '--dotfiles PATH', 'folder where store config files' do |dotfiles|
43
+ options[:dotfiles] = dotfiles
44
+ end
45
+
46
+ o.on '-p', '--password password', 'target channel\'s password' do |password|
47
+ options[:password] = password
48
+ end
49
+ }.parse!
50
+
51
+ unless File.directory? options[:dotfiles]
52
+ files = File.join File.dirname(__FILE__), '../lib/descartes/modules/files'
53
+ FileUtils.cp_r files, options[:dotfiles]
54
+ end
23
55
 
24
56
  Cinch::Bot.new {
25
57
  configure do |c|
26
- c.nick = nickname
58
+ c.nick = options[:nickname]
27
59
  c.realname = 'Descartes'
28
60
  c.user = 'Descartes'
29
- c.server = server
30
- c.channels = channels
61
+ c.server = options[:server]
62
+ c.channels = options[:channels]
31
63
 
32
- c.plugins.plugins = [Cinch::Plugins::Login] + plugins
33
- c.plugins.options[Cinch::Plugins::Login] = { :password => 'dat_password' }
64
+ c.plugins.plugins = [Cinch::Plugins::Login] + Descartes.load(options)
65
+ c.plugins.options[Cinch::Plugins::Login] = { :password => options[:password] }
34
66
  end
35
67
 
36
68
  on :message, '!help' do |m|
@@ -77,5 +109,4 @@ Cinch::Bot.new {
77
109
  on :message, '!version' do |m|
78
110
  m.reply Descartes.version
79
111
  end
80
-
81
112
  }.start
@@ -13,7 +13,9 @@
13
13
  ##
14
14
 
15
15
  class Descartes
16
- def self.load
16
+ def self.load(options)
17
+ $options = options
18
+
17
19
  Dir.glob(File.expand_path('../modules/*.rb', __FILE__)).each { |plugin|
18
20
  require plugin
19
21
  }
@@ -1 +1 @@
1
- http://localhost:4567
1
+ http://pigro.omnivium.it:4567
@@ -13,4 +13,5 @@ http://i47.tinypic.com/fjj3gx.jpg
13
13
  Io dico solo che il Detective Conan è il motivo per cui il Giappone si meriterebbe un'altra bomba atomica.
14
14
  Ti farò lezioni di encode quando tua madre sarà in oncologia.
15
15
  Il Sindaco è comunista quanto Hitler / Si, forse un pochino di più / Nel senso che ha la passione in comune per il genocidio? / No, per le loli.
16
- La Ninna Nanna del Sindaco: Dormi dormi / bella bambina / che c'è il sindaco che s'avvicina. / Il letto traballa / e l'orsetto se la squaglia. / La mammina resta in cucina / e col babbo fa melina. / Basta solo che dal corridoio / non vedan la pelata di quell'avvoltoio.
16
+ La Ninna Nanna del Sindaco: Dormi dormi / bella bambina / che c'è il sindaco che s'avvicina. / Il letto traballa / e l'orsetto se la squaglia. / La mammina resta in cucina / e col babbo fa melina. / Basta solo che dal corridoio / non vedan la pelata di quell'avvoltoio.
17
+ Il fansub italiano è ostaggio di un manipolo di lanzichenecchi.
@@ -21,12 +21,12 @@ class Descartes
21
21
  include Cinch::Plugin
22
22
 
23
23
  def authenticate!
24
- file = File.join File.dirname(__FILE__), 'files', 'lastfm_api.yml'
24
+ file = File.join $options[:dotfiles], 'lastfm_api.yml'
25
25
  Rockstar.lastfm = YAML.load_file file
26
26
  end
27
27
 
28
28
  def get_lastfm_nicks_archive
29
- file = File.join File.dirname(__FILE__), 'files', 'lastfm_nicks.yml'
29
+ file = File.join $options[:dotfiles], 'lastfm_nicks.yml'
30
30
  FileUtils.touch file unless File.exists? file
31
31
  YAML.load_file(file) || {}
32
32
  end
@@ -37,16 +37,16 @@ class Descartes
37
37
 
38
38
  usernick = m.user.nick
39
39
  lastfmnick = get_lastfm_nicks_archive[usernick]
40
- m.reply "Hey #{usernick}, I don't know your Last.fm nick. add it using '!lastfmuser add <lastfmnick>'." unless lastfmnick
40
+ m.reply "Hey #{usernick.colorize}, I don't know your Last.fm nick. add it using '!lastfmuser add <lastfmnick>'." unless lastfmnick
41
41
 
42
42
  user = Rockstar::User.new lastfmnick
43
43
  track = user.recent_tracks.first
44
44
 
45
- album = track.album.empty? ? "in #{track.album}" : 'in no known album'
45
+ album = track.album.empty? ? 'in no known album' : "in #{track.album.colorize}"
46
46
  if track.now_playing?
47
- m.reply "#{lastfmnick} is listening to #{track.name} by #{track.artist} (#{album}) right now!"
47
+ m.reply "#{lastfmnick.colorize} is listening to #{track.name.colorize} by #{track.artist.colorize} (#{album}) right now!"
48
48
  else
49
- m.reply "The last song #{lastfmnick} listened to is #{track.name} by #{track.artist} (#{album})."
49
+ m.reply "The last song #{lastfmnick.colorize} listened to is #{track.name.colorize} by #{track.artist.colorize} (#{album})."
50
50
  end
51
51
  end
52
52
 
@@ -55,7 +55,7 @@ class Descartes
55
55
  nicks = get_lastfm_nicks_archive
56
56
  nicks[m.user.nick] = lastfmnick
57
57
 
58
- file = File.join File.dirname(__FILE__), 'files', 'lastfm_nicks.yml'
58
+ file = File.join $options[:dotfiles], 'lastfm_nicks.yml'
59
59
  File.open(file, ?w) { |f| f.write YAML.dump(nicks) }
60
60
 
61
61
  m.reply "Ok, added user #{lastfmnick}."
@@ -66,7 +66,7 @@ class Descartes
66
66
  nicks = get_lastfm_nicks_archive
67
67
  nicks.delete lastfmnick
68
68
 
69
- file = File.join File.dirname(__FILE__), 'files', 'lastfm_nicks.yml'
69
+ file = File.join $options[:dotfiles], 'lastfm_nicks.yml'
70
70
  File.open(file, ?w) { |f| f.write YAML.dump(nicks) }
71
71
 
72
72
  m.reply "Ok, removed user #{lastfmnick}."
@@ -17,57 +17,73 @@ require 'assonnato'
17
17
  class Descartes
18
18
  class Pigro
19
19
  include Cinch::Plugin
20
- match /dat_show (.+) (.+)/
20
+ match /show (.+)/
21
+
22
+ def execute(m, keyword)
23
+ s = keyword.split
24
+ n_ep = s.last.numeric? ? s.pop : nil
25
+ keyword = s.join
21
26
 
22
- def execute(m, keyword, n_ep)
23
27
  host = get_host 'pigro.txt'
24
- series = Assonnato::Show.new(host).search! keyword
28
+ shows = Assonnato::Show.new host
25
29
  episodes = Assonnato::Episode.new host
26
30
 
31
+ series = shows.search! keyword
32
+
27
33
  if series.empty?
28
34
  m.reply 'Series not found'
29
35
  return
30
36
  end
31
37
 
32
38
  series.each { |s|
33
- m.reply "#{s.name.colorize} (#{s.status} series of #{s.tot_episodes} episodes airing #{s.airing})"
34
- m.reply ''.tap { |staff|
35
- {
36
- :Translator => s.translator,
37
- :Editor => s.editor,
38
- :Checker => s.checker,
39
- :Timer => s.timer,
40
- :Typesetter => s.typesetter,
41
- :Encoder => s.encoder,
42
- :QC => s.qchecker
43
- }.each_pair { |key, val|
44
- staff << "#{key.to_s.colorize}: #{val} / " unless val.empty?
45
- }
46
- }[0..-4]
39
+ show = shows.get!(s.name).first
47
40
 
48
- eps = episodes.get! s.name, n_ep.to_i
49
- eps.each { |ep|
50
- m.reply "Episode #{ep.episode} - ".colorize.tap { |staff|
41
+ if n_ep.nil?
42
+ m.reply "#{show.name.colorize} (#{show.status} series of #{show.tot_episodes} episodes airing #{show.airing})"
43
+ m.reply ''.tap { |staff|
51
44
  {
52
- :Translation => ep.translation,
53
- :Editing => ep.editing,
54
- :Check => ep.checking,
55
- :Timing => ep.timing,
56
- :Typesetting => ep.typesetting,
57
- :Encoding => ep.encoding,
58
- :QC => ep.qchecking
45
+ :Translator => show.translator,
46
+ :Editor => show.editor,
47
+ :Checker => show.checker,
48
+ :Timer => show.timer,
49
+ :Typesetter => show.typesetter,
50
+ :Encoder => show.encoder,
51
+ :QC => show.qchecker
59
52
  }.each_pair { |key, val|
60
- staff << "#{key.to_s.colorize}: #{val ? 'gg' : 'nope'} / "
53
+ staff << "#{key.to_s.colorize}: #{val} / " unless val.empty?
61
54
  }
62
- staff << 'Download'.colorize + ": #{ep.download}" if ep.download
63
55
  }[0..-4]
64
- }
56
+ else
57
+ eps = episodes.get! show.name, n_ep.to_i
58
+ eps.each { |ep|
59
+ m.reply "Episode #{ep.episode} - ".colorize.tap { |staff|
60
+ {
61
+ :Translation => ep.translation,
62
+ :Editing => ep.editing,
63
+ :Check => ep.checking,
64
+ :Timing => ep.timing,
65
+ :Typesetting => ep.typesetting,
66
+ :Encoding => ep.encoding,
67
+ :QC => ep.qchecking
68
+ }.each_pair { |key, val|
69
+ staff << "#{key.to_s.colorize}: #{val ? 'gg' : 'nope'} / "
70
+ }
71
+ staff << 'Download'.colorize + ": #{ep.download}" unless ep.download.strip.empty?
72
+ }[0..-4]
73
+ }
74
+ end
65
75
  }
66
76
  end
67
77
 
68
78
  def get_host(f)
69
- file = File.join File.dirname(__FILE__), 'files', f
70
- File.exists?(file) ? File.read(file) : 'http://localhost'
79
+ file = File.join $options[:dotfiles], f
80
+
81
+ if File.exists? file
82
+ url = File.read(file).strip
83
+ return url unless url.empty?
84
+ end
85
+
86
+ 'http://pigro.omnivium.it:4567'
71
87
  end
72
88
  end
73
89
  end
@@ -19,7 +19,7 @@ class Descartes
19
19
  match /.*\?/, :prefix => lambda { |m| m.bot.nick }
20
20
 
21
21
  def execute(m)
22
- file = File.expand_path '../files/replies.txt', __FILE__
22
+ file = File.join $options[:dotfiles], 'replies.txt'
23
23
  m.reply [].tap { |ary|
24
24
  File.read(file).each_line { |line| ary << line unless line.strip.empty? }
25
25
  }.sample
@@ -19,7 +19,7 @@ class Descartes
19
19
  match 'Sindaco'
20
20
 
21
21
  def execute(m)
22
- file = File.expand_path '../files/sindaco.txt', __FILE__
22
+ file = File.join $options[:dotfiles], 'sindaco.txt'
23
23
  m.reply [].tap { |ary|
24
24
  File.read(file).each_line { |line| ary << line unless line.strip.empty? }
25
25
  }.sample
@@ -35,4 +35,8 @@ class String
35
35
  require 'htmlentities'
36
36
  HTMLEntities.new.decode self
37
37
  end
38
+
39
+ def numeric?
40
+ self.to_i.to_s == self || self.to_f.to_s == self
41
+ end
38
42
  end
@@ -14,6 +14,6 @@
14
14
 
15
15
  class Descartes
16
16
  def self.version
17
- '0.5.1'
17
+ '0.6'
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: descartes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Capuano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-28 00:00:00.000000000 Z
11
+ date: 2014-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cinch