dog-bot 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dog-bot (0.0.1)
4
+ dog-bot (0.1.0)
5
5
  blather (~> 0.8.0)
6
6
  google_image_api (~> 0.0.1)
7
7
  rufus-scheduler (~> 2.0.17)
@@ -24,7 +24,7 @@ GEM
24
24
  connection_pool (~> 0.9.0)
25
25
  google_image_api (0.0.1)
26
26
  i18n (0.6.1)
27
- multi_json (1.3.6)
27
+ multi_json (1.3.7)
28
28
  niceogiri (1.0.2)
29
29
  nokogiri (~> 1.4)
30
30
  nokogiri (1.5.5)
data/dog.gemspec CHANGED
@@ -12,7 +12,7 @@
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.name = "dog-bot"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "0.0.3"
15
+ gem.version = "0.1.0"
16
16
 
17
17
  gem.add_dependency "blather", "~> 0.8.0"
18
18
  gem.add_dependency "google_image_api", "~> 0.0.1"
@@ -1,8 +1,8 @@
1
1
  chat_rooms "dog_test", "dog_test2"
2
2
 
3
- command "get body of tweet" do |c|
4
- c.matches /twitter\.com/
5
- c.action do |message|
3
+ command "get body of tweet" do
4
+ matches /twitter\.com/
5
+ action do |message|
6
6
  id = message.split("/").last
7
7
  uri = URI.parse "https://api.twitter.com/1/statuses/show.json?id=#{id}"
8
8
  tweet = JSON.parse uri.open.read
@@ -11,30 +11,30 @@ command "get body of tweet" do |c|
11
11
  end
12
12
  end
13
13
 
14
- command "dog" do |c|
15
- c.matches "dog"
16
- c.action { "bark!" }
14
+ command "dog" do
15
+ matches "dog"
16
+ action { "bark!" }
17
17
 
18
- c.subcommand "xkcd" do |sc|
19
- sc.matches "xkcd"
20
- sc.action do
18
+ subcommand "xkcd" do
19
+ matches "xkcd"
20
+ action do
21
21
  uri = URI.parse "http://xkcd.com/info.0.json"
22
22
  comic = JSON.parse uri.open.read
23
23
  "#{comic["img"]}\n#{comic["alt"]}"
24
24
  end
25
25
  end
26
26
 
27
- c.subcommand "fetch image" do |sc|
28
- sc.matches "fetch", "image"
29
- sc.action do |message|
27
+ subcommand "fetch image" do
28
+ matches "fetch", "image"
29
+ action do |message|
30
30
  query = message.split(" ")[2..-1].join(" ")
31
31
  GoogleImageApi.find(query).images.first["url"]
32
32
  end
33
33
  end
34
34
 
35
- c.subcommand "ruby gems" do |sc|
36
- sc.matches "gem"
37
- sc.action do |message|
35
+ subcommand "ruby gems" do
36
+ matches "gem"
37
+ action do |message|
38
38
  begin
39
39
  gem_name = message.split(" ").last
40
40
  uri = URI.parse "http://rubygems.org/api/v1/gems/#{gem_name}.json"
@@ -47,13 +47,13 @@ command "dog" do |c|
47
47
  end
48
48
  end
49
49
 
50
- c.subcommand "join channel" do |sc|
51
- sc.matches "join"
52
- sc.action { :join }
50
+ subcommand "join channel" do
51
+ matches "join"
52
+ action { :join }
53
53
  end
54
54
 
55
- c.subcommand "reload config" do |sc|
56
- sc.matches "reload"
57
- sc.action { :reload }
55
+ subcommand "reload config" do
56
+ matches "reload"
57
+ action { :reload }
58
58
  end
59
59
  end
data/lib/dog/command.rb CHANGED
@@ -25,9 +25,9 @@ module Dog
25
25
  end
26
26
  end
27
27
 
28
- def subcommand title
28
+ def subcommand title, &block
29
29
  subcommand = Command.new title
30
- yield subcommand
30
+ subcommand.instance_eval &block
31
31
  @subcommands << subcommand
32
32
  end
33
33
 
data/lib/dog/configure.rb CHANGED
@@ -17,9 +17,9 @@ module Dog
17
17
  @chat_rooms = []
18
18
  end
19
19
 
20
- def command title
20
+ def command title, &block
21
21
  command = Command.new title
22
- yield command
22
+ command.instance_eval &block
23
23
  @commands << command
24
24
  end
25
25
 
data/spec/dog/bot_spec.rb CHANGED
@@ -3,6 +3,7 @@ require "minitest/spec"
3
3
  require "minitest/autorun"
4
4
 
5
5
  require_relative "../../lib/dog/bot"
6
+ require_relative "../../lib/dog/brain"
6
7
  require_relative "../../lib/dog/command"
7
8
 
8
9
  class FakeConnection
@@ -5,13 +5,13 @@ require_relative "../../lib/dog/configure.rb"
5
5
  describe Dog::Configure do
6
6
  let :config_string do
7
7
  <<CONFIG
8
- command "greet" do |c|
9
- c.matches "hello", "hi", "whats up"
10
- c.action { "hello!" }
8
+ command "greet" do
9
+ matches "hello", "hi", "whats up"
10
+ action { "hello!" }
11
11
 
12
- c.subcommand "cool greet" do |subcommand|
13
- subcommand.matches "yo"
14
- subcommand.action { "yo yo yo, hello!" }
12
+ subcommand "cool greet" do
13
+ matches "yo"
14
+ action { "yo yo yo, hello!" }
15
15
  end
16
16
  end
17
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dog-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-11 00:00:00.000000000 Z
12
+ date: 2012-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blather
16
- requirement: &12497640 !ruby/object:Gem::Requirement
16
+ requirement: &11215480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.8.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12497640
24
+ version_requirements: *11215480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: google_image_api
27
- requirement: &12496820 !ruby/object:Gem::Requirement
27
+ requirement: &11214640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.0.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *12496820
35
+ version_requirements: *11214640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rufus-scheduler
38
- requirement: &12496160 !ruby/object:Gem::Requirement
38
+ requirement: &11212500 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.0.17
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *12496160
46
+ version_requirements: *11212500
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &12495680 !ruby/object:Gem::Requirement
49
+ requirement: &11211640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.9.2.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *12495680
57
+ version_requirements: *11211640
58
58
  description: Chatbot
59
59
  email:
60
60
  - ben@bmdev.org