bitbckt-botbckt 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -20,8 +20,6 @@ begin
20
20
  g.add_dependency('activesupport')
21
21
  g.add_dependency('json', '>= 1.1.2')
22
22
  g.add_dependency('hpricot', '>= 0.6')
23
- g.add_dependency('em-redis', '>= 0.1.1')
24
- g.add_dependency('em-http', '>= 0.1.6')
25
23
  end
26
24
  rescue LoadError
27
25
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 3
2
+ :patch: 1
3
3
  :major: 0
4
4
  :minor: 4
data/lib/botbckt.rb CHANGED
@@ -1,23 +1,3 @@
1
- %w{ rubygems eventmachine activesupport ostruct json cgi hpricot singleton optparse em-redis em-http }.each { |lib| require lib }
1
+ %w{ rubygems eventmachine activesupport ostruct json open-uri cgi hpricot singleton optparse }.each { |lib| require lib }
2
2
  %w{ irc store bot utilities command cmd }.each { |lib| require File.dirname(__FILE__) + "/botbckt/#{ lib }" }
3
3
  Dir[File.dirname(__FILE__) + '/botbckt/commands/*'].each { |lib| require lib }
4
-
5
- module Kernel
6
- private
7
- alias open_uri_original_open open
8
-
9
- def open(name, *rest, &block) #:nodoc:
10
- if name.respond_to?(:open)
11
- name.open(*rest, &block)
12
- elsif name.respond_to?(:to_str) &&
13
- %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name
14
- uri = URI.parse(name)
15
- http = EventMachine::HttpRequest.new("#{uri.scheme}://#{uri.host}#{uri.path}").get :query => uri.query
16
- http.callback { |request| yield request.response }
17
- else
18
- open_uri_original_open(name, *rest, &block)
19
- end
20
- end
21
- module_function :open
22
-
23
- end
data/lib/botbckt/bot.rb CHANGED
@@ -6,8 +6,8 @@ module Botbckt #:nodoc:
6
6
  include Singleton
7
7
  include ActiveSupport::BufferedLogger::Severity
8
8
 
9
- AFFIRMATIVE = ["'Sea, mhuise.", "In Ordnung", "Ik begrijp het", "Alles klar", "Ok.", "Roger.", "You don't have to tell me twice.", "Ack. Ack.", "C'est bon!"]
10
- NEGATIVE = ["Titim gan éirí ort.", "Gabh mo leithscéal?", "No entiendo", "excusez-moi", "Excuse me?", "Huh?", "I don't understand.", "Pardon?", "It's greek to me.", "Wat zeg je me nou?"]
9
+ AFFIRMATIVE = ["'Sea, mhuise.", "In Ordnung", "Ik begrijp", "Alles klar", "Ok.", "Roger.", "You don't have to tell me twice.", "Ack. Ack.", "C'est bon!"]
10
+ NEGATIVE = ["Titim gan éirí ort.", "Gabh mo leithscéal?", "No entiendo", "excusez-moi", "Excuse me?", "Huh?", "I don't understand.", "Pardon?", "It's greek to me."]
11
11
 
12
12
  attr_accessor :logger
13
13
  attr_accessor :store
@@ -35,7 +35,7 @@ module Botbckt #:nodoc:
35
35
 
36
36
  if daemonize || daemonize.nil?
37
37
  EventMachine::fork_reactor do
38
- start! options
38
+ start!
39
39
 
40
40
  if pid
41
41
  File.open(pid, 'w') { |file| file.write("#{Process.pid}") }
@@ -44,7 +44,7 @@ module Botbckt #:nodoc:
44
44
 
45
45
  end
46
46
  else
47
- EventMachine::run { start! options }
47
+ EventMachine::run { start! }
48
48
  end
49
49
  end
50
50
 
@@ -89,9 +89,8 @@ module Botbckt #:nodoc:
89
89
  languages << LANGUAGES.values.sort_by{ rand }.slice(0...TRANSLATE_ATTEMPTS)
90
90
  languages << MAIN_LANGUAGE # always end with main
91
91
 
92
- gooble(text, languages.flatten) do |result|
93
- say result, channel
94
- end
92
+ result = gooble(text, languages.flatten)
93
+ say result, channel
95
94
  end
96
95
 
97
96
  private
@@ -99,16 +98,15 @@ module Botbckt #:nodoc:
99
98
  # args
100
99
  # text<String>: text to translate
101
100
  # langs<Array>: languages to translate from/to
102
- def self.gooble(text, languages, &block) #:nodoc:
101
+ def self.gooble(text, languages) #:nodoc:
103
102
  if languages.length >= 2
104
103
  pair = "#{languages[0]}|#{languages[1]}"
105
- open("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=#{CGI.escape(text)}&langpair=#{CGI.escape(pair)}") do |json|
106
- response = JSON.parse(json) # could check for failed response with response['responseStatus'] != 200
107
- languages.shift
108
- gooble(response['responseData']['translatedText'], languages)
109
- end
104
+ json = open("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=#{CGI.escape(text)}&langpair=#{CGI.escape(pair)}")
105
+ response = JSON.parse(json.read) # could check for failed response with response['responseStatus'] != 200
106
+ languages.shift
107
+ gooble(response['responseData']['translatedText'], languages)
110
108
  else
111
- yield text
109
+ text
112
110
  end
113
111
  end
114
112
 
@@ -14,24 +14,22 @@ module Botbckt #:nodoc:
14
14
  trigger :google
15
15
 
16
16
  def call(sender, channel, query)
17
- google(query) do |result|
18
- say "First out of #{result.first} results:", channel
19
- say result.last['titleNoFormatting'], channel
20
- say result.last['unescapedUrl'], channel
21
- end
17
+ result = google(query)
18
+ say "First out of #{result.first} results:", channel
19
+ say result.last['titleNoFormatting'], channel
20
+ say result.last['unescapedUrl'], channel
22
21
  end
23
22
 
24
23
  private
25
24
 
26
- def google(term, &block) #:nodoc:
27
- open("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=#{CGI.escape(term)}") do |json|
28
- response = JSON.parse(json)
25
+ def google(term) #:nodoc:
26
+ json = open("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=#{CGI.escape(term)}")
27
+ response = JSON.parse(json.read)
29
28
 
30
- yield [
31
- response['responseData']['cursor']['estimatedResultCount'],
32
- response['responseData']['results'].first
33
- ]
34
- end
29
+ [
30
+ response['responseData']['cursor']['estimatedResultCount'],
31
+ response['responseData']['results'].first
32
+ ]
35
33
  end
36
34
 
37
35
  end
@@ -10,17 +10,13 @@ module Botbckt #:nodoc:
10
10
  trigger :meme
11
11
 
12
12
  def call(sender, channel, *args)
13
- meme do |msg|
14
- say msg, channel
15
- end
13
+ say meme, channel
16
14
  end
17
15
 
18
16
  private
19
17
 
20
- def meme(&block) #:nodoc:
21
- open("http://meme.boxofjunk.ws/moar.txt?lines=1") do |response|
22
- yield response.chomp
23
- end
18
+ def meme #:nodoc:
19
+ open("http://meme.boxofjunk.ws/moar.txt?lines=1").read.chomp
24
20
  end
25
21
 
26
22
  end
@@ -12,9 +12,7 @@ module Botbckt #:nodoc:
12
12
 
13
13
  def call(sender, channel, symbol)
14
14
  begin
15
- stock_price(symbol.split(' ').first) do |ticker|
16
- say ticker, channel
17
- end
15
+ say stock_price(symbol.split(' ').first), channel
18
16
  # TODO: Log me.
19
17
  rescue OpenURI::HTTPError => e
20
18
  say Botbckt::Bot.befuddled, channel
@@ -23,14 +21,13 @@ module Botbckt #:nodoc:
23
21
 
24
22
  private
25
23
 
26
- def stock_price(symbol, &block) #:nodoc:
27
- open("http://www.google.com/finance/info?q=#{CGI.escape(symbol)}") do |json|
28
- response = JSON.parse(json[4..-1]).first
24
+ def stock_price(symbol) #:nodoc:
25
+ json = open("http://www.google.com/finance/info?q=#{CGI.escape(symbol)}")
26
+ response = JSON.parse(json.read[4..-1]).first
29
27
 
30
- ticker, price, change = response['t'], response['l'], response['c']
28
+ ticker, price, change = response['t'], response['l'], response['c']
31
29
 
32
- yield "#{ticker} - $#{price} (#{change})"
33
- end
30
+ "#{ticker} - $#{price} (#{change})"
34
31
  end
35
32
  end
36
33
 
@@ -13,9 +13,7 @@ module Botbckt #:nodoc:
13
13
 
14
14
  trigger :forecast do |sender, channel, query|
15
15
  begin
16
- forecast(query) do |msg|
17
- say msg, channel
18
- end
16
+ say forecast(query), channel
19
17
  # TODO: Log me.
20
18
  rescue OpenURI::HTTPError => e
21
19
  say Botbckt::Bot.befuddled, channel
@@ -24,9 +22,7 @@ module Botbckt #:nodoc:
24
22
 
25
23
  trigger :conditions do |sender, channel, query|
26
24
  begin
27
- conditions(query) do |msg|
28
- say msg, channel
29
- end
25
+ say conditions(query), channel
30
26
  # TODO: Log me.
31
27
  rescue OpenURI::HTTPError => e
32
28
  say Botbckt::Bot.befuddled, channel
@@ -35,28 +31,23 @@ module Botbckt #:nodoc:
35
31
 
36
32
  private
37
33
 
38
- def self.conditions(query, &block) #:nodoc:
39
- search(query) do |response|
40
- xml = (response/'txt_forecast')
41
- daytime = (xml/'forecastday[1]')
42
- evening = (xml/'forecastday[2]')
34
+ def self.conditions(query) #:nodoc:
35
+ xml = (search(query)/'txt_forecast')
36
+ daytime = (xml/'forecastday[1]')
37
+ evening = (xml/'forecastday[2]')
43
38
 
44
- yield "Today: #{(daytime/'fcttext').inner_html}\nTonight: #{(evening/'fcttext').inner_html}"
45
- end
39
+ "Today: #{(daytime/'fcttext').inner_html}\nTonight: #{(evening/'fcttext').inner_html}"
46
40
  end
47
41
 
48
- def self.forecast(query, &block) #:nodoc:
49
- search(query) do |response|
50
- xml = (response/'simpleforecast/forecastday[1]')
42
+ def self.forecast(query) #:nodoc:
43
+ xml = (search(query)/'simpleforecast/forecastday[1]')
51
44
 
52
- yield "Today's Forecast: #{(xml/'high/fahrenheit').inner_html}F/#{(xml/'low/fahrenheit').inner_html}F (#{(xml/'conditions').inner_html})"
53
- end
45
+ "Today's Forecast: #{(xml/'high/fahrenheit').inner_html}F/#{(xml/'low/fahrenheit').inner_html}F (#{(xml/'conditions').inner_html})"
54
46
  end
55
47
 
56
- def self.search(query, &block) #:nodoc:
57
- open("http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=#{CGI.escape(query)}") do |xml|
58
- yield Hpricot.XML(xml)
59
- end
48
+ def self.search(query) #:nodoc:
49
+ xml = open("http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=#{CGI.escape(query)}")
50
+ Hpricot.XML(xml)
60
51
  end
61
52
 
62
53
  end
data/lib/botbckt/store.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'em-redis'
2
+
1
3
  module Botbckt #:nodoc:
2
4
 
3
5
  # Implements a basic key/value store API for cross-session state storage.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitbckt-botbckt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mitchell
@@ -52,26 +52,6 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: "0.6"
54
54
  version:
55
- - !ruby/object:Gem::Dependency
56
- name: em-redis
57
- type: :runtime
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: 0.1.1
64
- version:
65
- - !ruby/object:Gem::Dependency
66
- name: em-http
67
- type: :runtime
68
- version_requirement:
69
- version_requirements: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: 0.1.6
74
- version:
75
55
  description: Boredom strikes on Sunday mornings.
76
56
  email: brandon@systemisdown.net
77
57
  executables:
@@ -82,12 +62,9 @@ extensions: []
82
62
  extra_rdoc_files:
83
63
  - README
84
64
  files:
85
- - .gitignore
86
- - README
87
65
  - Rakefile
88
66
  - VERSION.yml
89
67
  - bin/botbckt
90
- - botbckt.gemspec
91
68
  - lib/botbckt.rb
92
69
  - lib/botbckt/bot.rb
93
70
  - lib/botbckt/cmd.rb
@@ -104,6 +81,7 @@ files:
104
81
  - lib/botbckt/irc.rb
105
82
  - lib/botbckt/store.rb
106
83
  - lib/botbckt/utilities.rb
84
+ - README
107
85
  has_rdoc: true
108
86
  homepage: http://github.com/bitbckt/botbckt
109
87
  post_install_message:
@@ -128,7 +106,7 @@ requirements: []
128
106
  rubyforge_project:
129
107
  rubygems_version: 1.2.0
130
108
  signing_key:
131
- specification_version: 2
109
+ specification_version: 3
132
110
  summary: Boredom strikes on Sunday mornings.
133
111
  test_files: []
134
112
 
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- doc
data/botbckt.gemspec DELETED
@@ -1,74 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{botbckt}
5
- s.version = "0.4.3"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Brandon Mitchell"]
9
- s.date = %q{2009-06-24}
10
- s.description = %q{Boredom strikes on Sunday mornings.}
11
- s.email = %q{brandon@systemisdown.net}
12
- s.executables = ["botbckt", "botbckt"]
13
- s.extra_rdoc_files = [
14
- "README"
15
- ]
16
- s.files = [
17
- ".gitignore",
18
- "README",
19
- "Rakefile",
20
- "VERSION.yml",
21
- "bin/botbckt",
22
- "botbckt.gemspec",
23
- "lib/botbckt.rb",
24
- "lib/botbckt/bot.rb",
25
- "lib/botbckt/cmd.rb",
26
- "lib/botbckt/command.rb",
27
- "lib/botbckt/commands/gooble.rb",
28
- "lib/botbckt/commands/google.rb",
29
- "lib/botbckt/commands/meme.rb",
30
- "lib/botbckt/commands/ping.rb",
31
- "lib/botbckt/commands/remind.rb",
32
- "lib/botbckt/commands/snack.rb",
33
- "lib/botbckt/commands/star_jar.rb",
34
- "lib/botbckt/commands/ticker.rb",
35
- "lib/botbckt/commands/weather.rb",
36
- "lib/botbckt/irc.rb",
37
- "lib/botbckt/store.rb",
38
- "lib/botbckt/utilities.rb"
39
- ]
40
- s.has_rdoc = true
41
- s.homepage = %q{http://github.com/bitbckt/botbckt}
42
- s.rdoc_options = ["--charset=UTF-8"]
43
- s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.1}
45
- s.summary = %q{Boredom strikes on Sunday mornings.}
46
-
47
- if s.respond_to? :specification_version then
48
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
- s.specification_version = 2
50
-
51
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
- s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.0"])
53
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
54
- s.add_runtime_dependency(%q<json>, [">= 1.1.2"])
55
- s.add_runtime_dependency(%q<hpricot>, [">= 0.6"])
56
- s.add_runtime_dependency(%q<em-redis>, [">= 0.1.1"])
57
- s.add_runtime_dependency(%q<em-http>, [">= 0.1.6"])
58
- else
59
- s.add_dependency(%q<eventmachine>, [">= 0.12.0"])
60
- s.add_dependency(%q<activesupport>, [">= 0"])
61
- s.add_dependency(%q<json>, [">= 1.1.2"])
62
- s.add_dependency(%q<hpricot>, [">= 0.6"])
63
- s.add_dependency(%q<em-redis>, [">= 0.1.1"])
64
- s.add_dependency(%q<em-http>, [">= 0.1.6"])
65
- end
66
- else
67
- s.add_dependency(%q<eventmachine>, [">= 0.12.0"])
68
- s.add_dependency(%q<activesupport>, [">= 0"])
69
- s.add_dependency(%q<json>, [">= 1.1.2"])
70
- s.add_dependency(%q<hpricot>, [">= 0.6"])
71
- s.add_dependency(%q<em-redis>, [">= 0.1.1"])
72
- s.add_dependency(%q<em-http>, [">= 0.1.6"])
73
- end
74
- end