dog-bot 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dog-bot (0.1.0)
4
+ dog-bot (0.1.2)
5
5
  blather (~> 0.8.0)
6
6
  google_image_api (~> 0.0.1)
7
7
  rufus-scheduler (~> 2.0.17)
@@ -9,29 +9,35 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (3.2.8)
13
- i18n (~> 0.6)
12
+ activesupport (3.2.13)
13
+ i18n (= 0.6.1)
14
14
  multi_json (~> 1.0)
15
- blather (0.8.0)
15
+ blather (0.8.5)
16
16
  activesupport (>= 2.3.11)
17
- eventmachine (>= 0.12.6)
17
+ eventmachine (>= 1.0.0)
18
18
  girl_friday
19
19
  niceogiri (~> 1.0)
20
- nokogiri (~> 1.5.5)
21
- connection_pool (0.9.2)
22
- eventmachine (0.12.10)
23
- girl_friday (0.10.0)
24
- connection_pool (~> 0.9.0)
20
+ nokogiri (~> 1.5, >= 1.5.6)
21
+ connection_pool (1.1.0)
22
+ eventmachine (1.0.3)
23
+ girl_friday (0.11.2)
24
+ connection_pool (~> 1.0)
25
+ rubinius-actor
25
26
  google_image_api (0.0.1)
26
27
  i18n (0.6.1)
27
- multi_json (1.3.7)
28
- niceogiri (1.0.2)
29
- nokogiri (~> 1.4)
30
- nokogiri (1.5.5)
28
+ mini_portile (0.5.0)
29
+ multi_json (1.7.7)
30
+ niceogiri (1.1.2)
31
+ nokogiri (~> 1.5)
32
+ nokogiri (1.6.0)
33
+ mini_portile (~> 0.5.0)
31
34
  rake (0.9.2.2)
32
- rufus-scheduler (2.0.17)
35
+ rubinius-actor (0.0.2)
36
+ rubinius-core-api
37
+ rubinius-core-api (0.0.1)
38
+ rufus-scheduler (2.0.19)
33
39
  tzinfo (>= 0.3.23)
34
- tzinfo (0.3.33)
40
+ tzinfo (1.0.1)
35
41
 
36
42
  PLATFORMS
37
43
  ruby
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ require "ostruct"
3
+ require "dog"
4
+ require "dog/test_connection"
5
+
6
+ unless ARGV.count >= 1
7
+ puts "Usage: dog [CONFIG PATH] [TEST MESSAGE]"
8
+ exit 1
9
+ end
10
+
11
+ config_path = ARGV.first
12
+ message = ARGV[1..-1].join(" ")
13
+
14
+ test_connection = Dog::TestConnection.new
15
+ bot = Dog::Bot.new(test_connection, config_path)
16
+ bot.config
17
+ output = bot.process(message)
18
+
19
+ if output.nil?
20
+ puts "no response for '#{message}'"
21
+ else
22
+ puts output
23
+ end
@@ -1 +1 @@
1
- chat_rooms "dog_test", "dog_test2"
1
+ chat_rooms "dog_test", "dog_test2", "test"
@@ -12,11 +12,10 @@
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.1.2"
15
+ gem.version = "0.1.3"
16
16
 
17
17
  gem.add_dependency "blather", "~> 0.8.0"
18
18
  gem.add_dependency "google_image_api", "~> 0.0.1"
19
- gem.add_dependency "rufus-scheduler", "~> 2.0.17"
20
19
 
21
20
  gem.add_development_dependency "rake", "~> 0.9.2.2"
22
21
  end
data/lib/dog.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "rubygems"
2
2
  require "blather/client/client"
3
- require "rufus/scheduler"
4
3
  require "uri"
5
4
  require "open-uri"
6
5
  require "openssl"
@@ -15,4 +14,3 @@ require "dog/bot"
15
14
  require "dog/configure"
16
15
  require "dog/connection"
17
16
  require "dog/command"
18
- require "dog/scheduler"
@@ -1,13 +1,12 @@
1
1
  module Dog
2
2
  class Bot
3
- attr_accessor :memory
3
+ attr_accessor :memory, :commands
4
4
 
5
5
  def initialize(connection, config_path)
6
6
  @config_path = config_path
7
7
  @connection = connection
8
8
  @commands = []
9
9
  @rooms = []
10
- @scheduler = Scheduler.new(self)
11
10
  @memory = {}
12
11
  end
13
12
 
@@ -87,7 +86,6 @@ module Dog
87
86
 
88
87
  @commands = config.commands
89
88
  @tasks = config.scheduled_tasks
90
- @scheduler.schedule_tasks(@tasks)
91
89
  join(*config.chat_rooms)
92
90
  end
93
91
 
@@ -19,7 +19,7 @@ module Dog
19
19
  end
20
20
 
21
21
  def say(to, text)
22
- @client.write Blather::Stanza::Message.new(to, text, :chat)
22
+ @client.write(Blather::Stanza::Message.new(to, text, :chat))
23
23
  end
24
24
 
25
25
  def say_to_chat(room_name, text)
@@ -0,0 +1,22 @@
1
+ module Dog
2
+ class TestConnection
3
+ attr_reader :joined_rooms, :sent_messages
4
+
5
+ def initialize(client=nil)
6
+ @joined_rooms = []
7
+ @sent_messages = []
8
+ end
9
+
10
+ def join(room_name)
11
+ @joined_rooms << room_name
12
+ end
13
+
14
+ def say(to, text)
15
+ @sent_messages << [to, text]
16
+ end
17
+
18
+ def say_to_chat(to, text)
19
+ @sent_messages << [to, text]
20
+ end
21
+ end
22
+ end
@@ -4,37 +4,8 @@ require "minitest/autorun"
4
4
 
5
5
  require_relative "../../lib/dog/bot"
6
6
  require_relative "../../lib/dog/command"
7
- require_relative "../../lib/dog/scheduler"
8
7
  require_relative "../../lib/dog/scheduled_task"
9
-
10
- class FakeConnection
11
- attr_reader :output, :chat_output, :rooms
12
-
13
- def initialize
14
- @output = []
15
- @chat_output = []
16
- @rooms = []
17
- end
18
-
19
- def say from, response
20
- @output << [from, response]
21
- end
22
-
23
- def say_to_chat from, response
24
- @chat_output << [from, response]
25
- end
26
-
27
- def join room_name
28
- @rooms << room_name
29
- end
30
-
31
- def jid
32
- OpenStruct.new(
33
- :jid => OpenStruct.new(:domain => "example.com"),
34
- :node => "dog"
35
- )
36
- end
37
- end
8
+ require_relative "../../lib/dog/test_connection"
38
9
 
39
10
  class Dog::Bot
40
11
  def config
@@ -51,7 +22,7 @@ class Dog::Bot
51
22
  end
52
23
 
53
24
  describe Dog::Bot do
54
- let(:connection) { FakeConnection.new }
25
+ let(:connection) { Dog::TestConnection.new }
55
26
  subject { Dog::Bot.new(connection, "config") }
56
27
 
57
28
  before(:each) { subject.config }
@@ -61,19 +32,19 @@ describe Dog::Bot do
61
32
  message = OpenStruct.new(:from => "bob", :body => "hi dog")
62
33
  subject.process_chat_message(message)
63
34
 
64
- connection.output.last.must_equal ["bob", "hello"]
35
+ connection.sent_messages.last.must_equal ["bob", "hello"]
65
36
  end
66
37
 
67
38
  it "doesn't process a non-matching message" do
68
39
  message = OpenStruct.new(:from => "bob", :body => "bad string")
69
40
  subject.process_chat_message(message)
70
41
 
71
- connection.output.must_be_empty
42
+ connection.sent_messages.must_be_empty
72
43
  end
73
44
  end
74
45
 
75
46
  describe ".process_group_chat_message" do
76
- it "processes a message that matches" do
47
+ it "processes a group message that matches" do
77
48
  message = OpenStruct.new(
78
49
  :from => OpenStruct.new(:node => "bob", :domain => "chat"),
79
50
  :body => "hi dog",
@@ -81,7 +52,7 @@ describe Dog::Bot do
81
52
  )
82
53
  subject.process_group_chat_message(message)
83
54
 
84
- connection.chat_output.last.must_equal ["bob", "hello"]
55
+ connection.sent_messages.last.must_equal ["bob", "hello"]
85
56
  end
86
57
 
87
58
  it "doesn't process a non-matching message" do
@@ -91,7 +62,7 @@ describe Dog::Bot do
91
62
  :delayed? => false
92
63
  )
93
64
  subject.process_group_chat_message(message)
94
- connection.chat_output.must_be_empty
65
+ connection.sent_messages.must_be_empty
95
66
  end
96
67
  end
97
68
 
@@ -100,7 +71,7 @@ describe Dog::Bot do
100
71
  output = subject.respond_to_action("dog join chatroom", :join)
101
72
 
102
73
  output.must_equal "joined chatroom"
103
- connection.rooms.last.must_equal "chatroom"
74
+ connection.joined_rooms.last.must_equal "chatroom"
104
75
  end
105
76
 
106
77
  it "reloads" do
@@ -117,13 +88,13 @@ describe Dog::Bot do
117
88
  describe ".join" do
118
89
  it "joins a room" do
119
90
  subject.join("my_room")
120
- connection.rooms.last.must_equal "my_room"
91
+ connection.joined_rooms.last.must_equal "my_room"
121
92
  end
122
93
 
123
94
  it "can join many rooms" do
124
95
  rooms = ["my_room", "my_other_room"]
125
96
  subject.join(*rooms)
126
- connection.rooms.must_equal rooms
97
+ connection.joined_rooms.must_equal rooms
127
98
  end
128
99
  end
129
100
  end
@@ -0,0 +1,33 @@
1
+ require "ostruct"
2
+
3
+ require "minitest/spec"
4
+ require "minitest/autorun"
5
+
6
+ require_relative "../../lib/dog/test_connection"
7
+
8
+ describe Dog::TestConnection do
9
+ subject do
10
+ Dog::TestConnection.new
11
+ end
12
+
13
+ describe ".join" do
14
+ it "adds the join stanza to a list of joined rooms" do
15
+ subject.join("my_room")
16
+ subject.joined_rooms.must_equal ["my_room"]
17
+ end
18
+ end
19
+
20
+ describe ".say" do
21
+ it "adds the message to the sent_messages array" do
22
+ subject.say("bob", "hello world")
23
+ subject.sent_messages.last.must_equal ["bob", "hello world"]
24
+ end
25
+ end
26
+
27
+ describe ".say_to_chat" do
28
+ it "adds the message to the sent_messages array" do
29
+ subject.say_to_chat("my_chat", "hello chat world")
30
+ subject.sent_messages.last.must_equal ["my_chat", "hello chat world"]
31
+ end
32
+ end
33
+ end
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.1.2
4
+ version: 0.1.3
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: 2013-03-08 00:00:00.000000000 Z
12
+ date: 2013-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blather
16
- requirement: &10916520 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.8.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *10916520
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: google_image_api
27
- requirement: &10915540 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,21 +37,15 @@ dependencies:
32
37
  version: 0.0.1
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *10915540
36
- - !ruby/object:Gem::Dependency
37
- name: rufus-scheduler
38
- requirement: &10915000 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
39
41
  none: false
40
42
  requirements:
41
43
  - - ~>
42
44
  - !ruby/object:Gem::Version
43
- version: 2.0.17
44
- type: :runtime
45
- prerelease: false
46
- version_requirements: *10915000
45
+ version: 0.0.1
47
46
  - !ruby/object:Gem::Dependency
48
47
  name: rake
49
- requirement: &10914240 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
50
49
  none: false
51
50
  requirements:
52
51
  - - ~>
@@ -54,7 +53,12 @@ dependencies:
54
53
  version: 0.9.2.2
55
54
  type: :development
56
55
  prerelease: false
57
- version_requirements: *10914240
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2.2
58
62
  description: Chatbot
59
63
  email:
60
64
  - ben@bmdev.org
@@ -70,6 +74,7 @@ files:
70
74
  - README.md
71
75
  - Rakefile
72
76
  - bin/dog
77
+ - bin/dog-test
73
78
  - config_examples/default_rooms.rb
74
79
  - config_examples/dog.rb
75
80
  - config_examples/google_image.rb
@@ -85,11 +90,12 @@ files:
85
90
  - lib/dog/configure.rb
86
91
  - lib/dog/connection.rb
87
92
  - lib/dog/scheduled_task.rb
88
- - lib/dog/scheduler.rb
93
+ - lib/dog/test_connection.rb
89
94
  - spec/dog/bot_spec.rb
90
95
  - spec/dog/command_spec.rb
91
96
  - spec/dog/configure_spec.rb
92
97
  - spec/dog/scheduled_task_spec.rb
98
+ - spec/dog/test_connection_spec.rb
93
99
  homepage: https://github.com/benmills/dog
94
100
  licenses: []
95
101
  post_install_message:
@@ -110,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
116
  version: '0'
111
117
  requirements: []
112
118
  rubyforge_project:
113
- rubygems_version: 1.8.11
119
+ rubygems_version: 1.8.23
114
120
  signing_key:
115
121
  specification_version: 3
116
122
  summary: Extensible XMPP chatbot
@@ -119,3 +125,4 @@ test_files:
119
125
  - spec/dog/command_spec.rb
120
126
  - spec/dog/configure_spec.rb
121
127
  - spec/dog/scheduled_task_spec.rb
128
+ - spec/dog/test_connection_spec.rb
@@ -1,32 +0,0 @@
1
- require 'rubygems'
2
- require 'rufus/scheduler'
3
-
4
- module Dog
5
- class Scheduler
6
- def initialize(bot)
7
- @bot = bot
8
- @scheduler = Rufus::Scheduler.start_new
9
- end
10
-
11
- def schedule_tasks(scheduled_tasks)
12
- restart
13
-
14
- scheduled_tasks.each do |task|
15
- @scheduler.every(task.frequency) do
16
- if response = task.run(@bot)
17
- @bot.say_to_all_chat_rooms(response)
18
- end
19
- end
20
- end
21
- end
22
-
23
- def restart
24
- @scheduler.all_jobs.each do |id, job|
25
- job.unschedule
26
- end
27
-
28
- @scheduler.stop unless @scheduler.nil?
29
- @scheduler = Rufus::Scheduler.start_new
30
- end
31
- end
32
- end