dog-bot 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +15 -9
- data/README.md +2 -0
- data/dog.gemspec +22 -0
- data/dog_config_example.rb +1 -4
- data/lib/dog/bot.rb +2 -10
- data/lib/dog/brain.rb +15 -0
- data/lib/dog/configure.rb +6 -1
- data/spec/dog/brain_spec.rb +35 -0
- data/spec/dog/configure_spec.rb +18 -8
- metadata +15 -11
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dog-bot (0.0.1)
|
5
|
+
blather (~> 0.8.0)
|
6
|
+
google_image_api (~> 0.0.1)
|
7
|
+
rufus-scheduler (~> 2.0.17)
|
8
|
+
|
1
9
|
GEM
|
2
10
|
remote: https://rubygems.org/
|
3
11
|
specs:
|
4
|
-
activesupport (3.2.
|
12
|
+
activesupport (3.2.8)
|
5
13
|
i18n (~> 0.6)
|
6
14
|
multi_json (~> 1.0)
|
7
15
|
blather (0.8.0)
|
@@ -10,12 +18,12 @@ GEM
|
|
10
18
|
girl_friday
|
11
19
|
niceogiri (~> 1.0)
|
12
20
|
nokogiri (~> 1.5.5)
|
13
|
-
connection_pool (0.
|
21
|
+
connection_pool (0.9.2)
|
14
22
|
eventmachine (0.12.10)
|
15
|
-
girl_friday (0.
|
16
|
-
connection_pool (~> 0.
|
23
|
+
girl_friday (0.10.0)
|
24
|
+
connection_pool (~> 0.9.0)
|
17
25
|
google_image_api (0.0.1)
|
18
|
-
i18n (0.6.
|
26
|
+
i18n (0.6.1)
|
19
27
|
multi_json (1.3.6)
|
20
28
|
niceogiri (1.0.2)
|
21
29
|
nokogiri (~> 1.4)
|
@@ -29,7 +37,5 @@ PLATFORMS
|
|
29
37
|
ruby
|
30
38
|
|
31
39
|
DEPENDENCIES
|
32
|
-
|
33
|
-
|
34
|
-
rake
|
35
|
-
rufus-scheduler
|
40
|
+
dog-bot!
|
41
|
+
rake (~> 0.9.2.2)
|
data/README.md
CHANGED
data/dog.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Ben Mills"]
|
5
|
+
gem.email = ["ben@bmdev.org"]
|
6
|
+
gem.description = %q{Chatbot}
|
7
|
+
gem.summary = %q{Extensible XMPP chatbot}
|
8
|
+
gem.homepage = "https://github.com/benmills/dog"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = ["dog"]
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "dog-bot"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = "0.0.2"
|
16
|
+
|
17
|
+
gem.add_dependency "blather", "~> 0.8.0"
|
18
|
+
gem.add_dependency "google_image_api", "~> 0.0.1"
|
19
|
+
gem.add_dependency "rufus-scheduler", "~> 2.0.17"
|
20
|
+
|
21
|
+
gem.add_development_dependency "rake", "~> 0.9.2.2"
|
22
|
+
end
|
data/dog_config_example.rb
CHANGED
data/lib/dog/bot.rb
CHANGED
@@ -8,8 +8,7 @@ module Dog
|
|
8
8
|
@connection = connection
|
9
9
|
@commands = []
|
10
10
|
@rooms = []
|
11
|
-
@
|
12
|
-
@data.default = {}
|
11
|
+
@brain = Brain.new
|
13
12
|
end
|
14
13
|
|
15
14
|
def process_chat_message message
|
@@ -68,6 +67,7 @@ module Dog
|
|
68
67
|
@commands = config.commands
|
69
68
|
@scheduled_tasks = config.scheduled_tasks
|
70
69
|
|
70
|
+
config.chat_rooms.each { |chat_room| join chat_room }
|
71
71
|
schedule_tasks
|
72
72
|
end
|
73
73
|
|
@@ -88,14 +88,6 @@ module Dog
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
def save_data key, val
|
92
|
-
@data[key] = val
|
93
|
-
end
|
94
|
-
|
95
|
-
def get_data key
|
96
|
-
@data[key]
|
97
|
-
end
|
98
|
-
|
99
91
|
def _from_self message
|
100
92
|
@rooms.each do |room|
|
101
93
|
return true if "#{room}@conference.#{@connection.jid.domain}/#{@connection.jid.node}" == message.from
|
data/lib/dog/brain.rb
ADDED
data/lib/dog/configure.rb
CHANGED
@@ -9,11 +9,12 @@ module Dog
|
|
9
9
|
config
|
10
10
|
end
|
11
11
|
|
12
|
-
attr_reader :commands, :scheduled_tasks
|
12
|
+
attr_reader :commands, :scheduled_tasks, :chat_rooms
|
13
13
|
|
14
14
|
def initialize
|
15
15
|
@commands = []
|
16
16
|
@scheduled_tasks = []
|
17
|
+
@chat_rooms = []
|
17
18
|
end
|
18
19
|
|
19
20
|
def command title
|
@@ -27,5 +28,9 @@ module Dog
|
|
27
28
|
yield task
|
28
29
|
@scheduled_tasks << task
|
29
30
|
end
|
31
|
+
|
32
|
+
def chat_rooms *chat_rooms
|
33
|
+
@chat_rooms += chat_rooms
|
34
|
+
end
|
30
35
|
end
|
31
36
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "minitest/spec"
|
2
|
+
require "minitest/autorun"
|
3
|
+
|
4
|
+
require_relative "../../lib/dog/brain"
|
5
|
+
|
6
|
+
describe Dog::Brain do
|
7
|
+
subject { Dog::Brain.new :foo => :bar }
|
8
|
+
|
9
|
+
it "can be created without inital data" do
|
10
|
+
brain = Dog::Brain.new
|
11
|
+
brain.get(:foo).must_be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "get" do
|
15
|
+
it "gets a value for a key" do
|
16
|
+
subject.get(:foo).must_equal :bar
|
17
|
+
end
|
18
|
+
|
19
|
+
it "gets nil for an unknown key" do
|
20
|
+
subject.get(:bad_key).must_be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "set" do
|
25
|
+
it "sets a key to a value" do
|
26
|
+
subject.set(:baz, :foz)
|
27
|
+
subject.get(:baz).must_equal :foz
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can overwrite existing values" do
|
31
|
+
subject.set(:foo, :baz)
|
32
|
+
subject.get(:foo).must_equal :baz
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/dog/configure_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require "minitest/autorun"
|
|
3
3
|
require_relative "../../lib/dog/configure.rb"
|
4
4
|
|
5
5
|
describe Dog::Configure do
|
6
|
-
let :
|
6
|
+
let :config_string do
|
7
7
|
<<CONFIG
|
8
8
|
command "greet" do |c|
|
9
9
|
c.matches "hello", "hi", "whats up"
|
@@ -14,21 +14,19 @@ command "greet" do |c|
|
|
14
14
|
subcommand.action { "yo yo yo, hello!" }
|
15
15
|
end
|
16
16
|
end
|
17
|
-
CONFIG
|
18
|
-
end
|
19
17
|
|
20
|
-
let :task_config_string do
|
21
|
-
<<CONFIG
|
22
18
|
task "say hi" do |t|
|
23
19
|
t.every "1m"
|
24
20
|
t.action { "hello!" }
|
25
21
|
end
|
22
|
+
|
23
|
+
chat_rooms "test_room", "test_room2"
|
26
24
|
CONFIG
|
27
25
|
end
|
28
26
|
|
29
27
|
describe "#parse" do
|
30
28
|
it "parses a string into an array of commands" do
|
31
|
-
config = Dog::Configure.parse
|
29
|
+
config = Dog::Configure.parse config_string
|
32
30
|
command = config.commands.first
|
33
31
|
|
34
32
|
command.respond_to("hi").must_equal "hello!"
|
@@ -37,18 +35,30 @@ CONFIG
|
|
37
35
|
end
|
38
36
|
|
39
37
|
it "parses subcommands" do
|
40
|
-
config = Dog::Configure.parse
|
38
|
+
config = Dog::Configure.parse config_string
|
41
39
|
command = config.commands.first
|
42
40
|
|
43
41
|
command.respond_to("hi yo").must_equal "yo yo yo, hello!"
|
44
42
|
end
|
45
43
|
|
46
44
|
it "parses a string into an array of scheduled tasks" do
|
47
|
-
config = Dog::Configure.parse
|
45
|
+
config = Dog::Configure.parse config_string
|
48
46
|
task = config.scheduled_tasks.first
|
49
47
|
|
50
48
|
task.run({}).must_equal "hello!"
|
51
49
|
task.frequency.must_equal "1m"
|
52
50
|
end
|
51
|
+
|
52
|
+
it "parses default chat rooms from a config string" do
|
53
|
+
config = Dog::Configure.parse config_string
|
54
|
+
|
55
|
+
config.chat_rooms.first.must_equal "test_room"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "parses multiple chat rooms from a config string" do
|
59
|
+
config = Dog::Configure.parse config_string
|
60
|
+
|
61
|
+
config.chat_rooms.must_equal ["test_room", "test_room2"]
|
62
|
+
end
|
53
63
|
end
|
54
64
|
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.0.
|
4
|
+
version: 0.0.2
|
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-
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: blather
|
16
|
-
requirement: &
|
16
|
+
requirement: &20579000 !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: *
|
24
|
+
version_requirements: *20579000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: google_image_api
|
27
|
-
requirement: &
|
27
|
+
requirement: &20578180 !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: *
|
35
|
+
version_requirements: *20578180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rufus-scheduler
|
38
|
-
requirement: &
|
38
|
+
requirement: &20577520 !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: *
|
46
|
+
version_requirements: *20577520
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &20577040 !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: *
|
57
|
+
version_requirements: *20577040
|
58
58
|
description: Chatbot
|
59
59
|
email:
|
60
60
|
- ben@bmdev.org
|
@@ -69,18 +69,21 @@ files:
|
|
69
69
|
- Gemfile.lock
|
70
70
|
- README.md
|
71
71
|
- Rakefile
|
72
|
+
- bin/dog
|
73
|
+
- dog.gemspec
|
72
74
|
- dog_config_example.rb
|
73
75
|
- lib/dog.rb
|
74
76
|
- lib/dog/bot.rb
|
77
|
+
- lib/dog/brain.rb
|
75
78
|
- lib/dog/command.rb
|
76
79
|
- lib/dog/configure.rb
|
77
80
|
- lib/dog/connection.rb
|
78
81
|
- lib/dog/scheduled_task.rb
|
79
82
|
- spec/dog/bot_spec.rb
|
83
|
+
- spec/dog/brain_spec.rb
|
80
84
|
- spec/dog/command_spec.rb
|
81
85
|
- spec/dog/configure_spec.rb
|
82
86
|
- spec/dog/scheduled_task_spec.rb
|
83
|
-
- bin/dog
|
84
87
|
homepage: https://github.com/benmills/dog
|
85
88
|
licenses: []
|
86
89
|
post_install_message:
|
@@ -107,6 +110,7 @@ specification_version: 3
|
|
107
110
|
summary: Extensible XMPP chatbot
|
108
111
|
test_files:
|
109
112
|
- spec/dog/bot_spec.rb
|
113
|
+
- spec/dog/brain_spec.rb
|
110
114
|
- spec/dog/command_spec.rb
|
111
115
|
- spec/dog/configure_spec.rb
|
112
116
|
- spec/dog/scheduled_task_spec.rb
|