bitbckt-botbckt 0.4.2 → 0.4.3
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/.gitignore +1 -0
- data/Rakefile +1 -0
- data/VERSION.yml +1 -1
- data/botbckt.gemspec +74 -0
- data/lib/botbckt/bot.rb +4 -4
- data/lib/botbckt/commands/gooble.rb +10 -8
- data/lib/botbckt/commands/google.rb +13 -11
- data/lib/botbckt/commands/meme.rb +7 -3
- data/lib/botbckt/commands/ticker.rb +9 -6
- data/lib/botbckt/commands/weather.rb +22 -13
- data/lib/botbckt.rb +21 -1
- metadata +15 -3
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
doc
|
data/Rakefile
CHANGED
@@ -21,6 +21,7 @@ begin
|
|
21
21
|
g.add_dependency('json', '>= 1.1.2')
|
22
22
|
g.add_dependency('hpricot', '>= 0.6')
|
23
23
|
g.add_dependency('em-redis', '>= 0.1.1')
|
24
|
+
g.add_dependency('em-http', '>= 0.1.6')
|
24
25
|
end
|
25
26
|
rescue LoadError
|
26
27
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION.yml
CHANGED
data/botbckt.gemspec
ADDED
@@ -0,0 +1,74 @@
|
|
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
|
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", "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."]
|
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?"]
|
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!
|
38
|
+
start! options
|
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! }
|
47
|
+
EventMachine::run { start! options }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -89,8 +89,9 @@ 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
|
-
|
93
|
-
|
92
|
+
gooble(text, languages.flatten) do |result|
|
93
|
+
say result, channel
|
94
|
+
end
|
94
95
|
end
|
95
96
|
|
96
97
|
private
|
@@ -98,15 +99,16 @@ module Botbckt #:nodoc:
|
|
98
99
|
# args
|
99
100
|
# text<String>: text to translate
|
100
101
|
# langs<Array>: languages to translate from/to
|
101
|
-
def self.gooble(text, languages) #:nodoc:
|
102
|
+
def self.gooble(text, languages, &block) #:nodoc:
|
102
103
|
if languages.length >= 2
|
103
104
|
pair = "#{languages[0]}|#{languages[1]}"
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
108
110
|
else
|
109
|
-
text
|
111
|
+
yield text
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
@@ -14,22 +14,24 @@ module Botbckt #:nodoc:
|
|
14
14
|
trigger :google
|
15
15
|
|
16
16
|
def call(sender, channel, query)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
21
22
|
end
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
|
-
def google(term) #:nodoc:
|
26
|
-
|
27
|
-
|
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)
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
yield [
|
31
|
+
response['responseData']['cursor']['estimatedResultCount'],
|
32
|
+
response['responseData']['results'].first
|
33
|
+
]
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
37
|
end
|
@@ -10,13 +10,17 @@ module Botbckt #:nodoc:
|
|
10
10
|
trigger :meme
|
11
11
|
|
12
12
|
def call(sender, channel, *args)
|
13
|
-
|
13
|
+
meme do |msg|
|
14
|
+
say msg, channel
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
18
|
private
|
17
19
|
|
18
|
-
def meme #:nodoc:
|
19
|
-
open("http://meme.boxofjunk.ws/moar.txt?lines=1")
|
20
|
+
def meme(&block) #:nodoc:
|
21
|
+
open("http://meme.boxofjunk.ws/moar.txt?lines=1") do |response|
|
22
|
+
yield response.chomp
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
end
|
@@ -12,7 +12,9 @@ module Botbckt #:nodoc:
|
|
12
12
|
|
13
13
|
def call(sender, channel, symbol)
|
14
14
|
begin
|
15
|
-
|
15
|
+
stock_price(symbol.split(' ').first) do |ticker|
|
16
|
+
say ticker, channel
|
17
|
+
end
|
16
18
|
# TODO: Log me.
|
17
19
|
rescue OpenURI::HTTPError => e
|
18
20
|
say Botbckt::Bot.befuddled, channel
|
@@ -21,13 +23,14 @@ module Botbckt #:nodoc:
|
|
21
23
|
|
22
24
|
private
|
23
25
|
|
24
|
-
def stock_price(symbol) #:nodoc:
|
25
|
-
|
26
|
-
|
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
|
27
29
|
|
28
|
-
|
30
|
+
ticker, price, change = response['t'], response['l'], response['c']
|
29
31
|
|
30
|
-
|
32
|
+
yield "#{ticker} - $#{price} (#{change})"
|
33
|
+
end
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
@@ -13,7 +13,9 @@ module Botbckt #:nodoc:
|
|
13
13
|
|
14
14
|
trigger :forecast do |sender, channel, query|
|
15
15
|
begin
|
16
|
-
|
16
|
+
forecast(query) do |msg|
|
17
|
+
say msg, channel
|
18
|
+
end
|
17
19
|
# TODO: Log me.
|
18
20
|
rescue OpenURI::HTTPError => e
|
19
21
|
say Botbckt::Bot.befuddled, channel
|
@@ -22,7 +24,9 @@ module Botbckt #:nodoc:
|
|
22
24
|
|
23
25
|
trigger :conditions do |sender, channel, query|
|
24
26
|
begin
|
25
|
-
|
27
|
+
conditions(query) do |msg|
|
28
|
+
say msg, channel
|
29
|
+
end
|
26
30
|
# TODO: Log me.
|
27
31
|
rescue OpenURI::HTTPError => e
|
28
32
|
say Botbckt::Bot.befuddled, channel
|
@@ -31,23 +35,28 @@ module Botbckt #:nodoc:
|
|
31
35
|
|
32
36
|
private
|
33
37
|
|
34
|
-
def self.conditions(query) #:nodoc:
|
35
|
-
|
36
|
-
|
37
|
-
|
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]')
|
38
43
|
|
39
|
-
|
44
|
+
yield "Today: #{(daytime/'fcttext').inner_html}\nTonight: #{(evening/'fcttext').inner_html}"
|
45
|
+
end
|
40
46
|
end
|
41
47
|
|
42
|
-
def self.forecast(query) #:nodoc:
|
43
|
-
|
48
|
+
def self.forecast(query, &block) #:nodoc:
|
49
|
+
search(query) do |response|
|
50
|
+
xml = (response/'simpleforecast/forecastday[1]')
|
44
51
|
|
45
|
-
|
52
|
+
yield "Today's Forecast: #{(xml/'high/fahrenheit').inner_html}F/#{(xml/'low/fahrenheit').inner_html}F (#{(xml/'conditions').inner_html})"
|
53
|
+
end
|
46
54
|
end
|
47
55
|
|
48
|
-
def self.search(query) #:nodoc:
|
49
|
-
|
50
|
-
|
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
|
51
60
|
end
|
52
61
|
|
53
62
|
end
|
data/lib/botbckt.rb
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
-
%w{ rubygems eventmachine activesupport ostruct json
|
1
|
+
%w{ rubygems eventmachine activesupport ostruct json cgi hpricot singleton optparse em-redis em-http }.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
|
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.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mitchell
|
@@ -62,6 +62,16 @@ dependencies:
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: 0.1.1
|
64
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:
|
65
75
|
description: Boredom strikes on Sunday mornings.
|
66
76
|
email: brandon@systemisdown.net
|
67
77
|
executables:
|
@@ -72,9 +82,12 @@ extensions: []
|
|
72
82
|
extra_rdoc_files:
|
73
83
|
- README
|
74
84
|
files:
|
85
|
+
- .gitignore
|
86
|
+
- README
|
75
87
|
- Rakefile
|
76
88
|
- VERSION.yml
|
77
89
|
- bin/botbckt
|
90
|
+
- botbckt.gemspec
|
78
91
|
- lib/botbckt.rb
|
79
92
|
- lib/botbckt/bot.rb
|
80
93
|
- lib/botbckt/cmd.rb
|
@@ -91,7 +104,6 @@ files:
|
|
91
104
|
- lib/botbckt/irc.rb
|
92
105
|
- lib/botbckt/store.rb
|
93
106
|
- lib/botbckt/utilities.rb
|
94
|
-
- README
|
95
107
|
has_rdoc: true
|
96
108
|
homepage: http://github.com/bitbckt/botbckt
|
97
109
|
post_install_message:
|
@@ -116,7 +128,7 @@ requirements: []
|
|
116
128
|
rubyforge_project:
|
117
129
|
rubygems_version: 1.2.0
|
118
130
|
signing_key:
|
119
|
-
specification_version:
|
131
|
+
specification_version: 2
|
120
132
|
summary: Boredom strikes on Sunday mornings.
|
121
133
|
test_files: []
|
122
134
|
|