campfire_bot 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +23 -2
- data/examples/basic.rb +5 -2
- data/lib/campfire_bot.rb +3 -7
- data/lib/campfire_bot/version.rb +1 -1
- data/spec/campfire_bot_spec.rb +23 -8
- metadata +3 -4
- data/.bundle/config +0 -2
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -25,11 +25,32 @@ This is a Campfire bot heavily inspired by http://github.com/ichverstehe/isaac
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# Events
|
28
|
-
bot.on(/^How are you?/) do |
|
29
|
-
|
28
|
+
bot.on(/^How are you?/) do |room, message|
|
29
|
+
room.speak("Im very sad thank-you")
|
30
|
+
room.play("trombone")
|
31
|
+
room.paste("This is a paste")
|
32
|
+
room.upload("/path/to/file.jpg")
|
30
33
|
end
|
31
34
|
end.start
|
32
35
|
|
36
|
+
Message object gives you a hash of details about the message
|
37
|
+
|
38
|
+
{
|
39
|
+
"room_id" => 123456,
|
40
|
+
"created_at" => Wed Nov 17 20:06:44 +0000 2010,
|
41
|
+
"body" => "!go",
|
42
|
+
"id" => 12345,
|
43
|
+
"type" => "TextMessage",
|
44
|
+
"user" => {
|
45
|
+
"name" => "Red",
|
46
|
+
"created_at" => Tue Nov 16 13:48:19 +0000 2010,
|
47
|
+
"admin" => true,
|
48
|
+
"id" => 1111,
|
49
|
+
"type" => "Member",
|
50
|
+
"email_address" => "red@railslove.com"
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
33
54
|
## Note on Patches/Pull Requests
|
34
55
|
|
35
56
|
* Fork the project.
|
data/examples/basic.rb
CHANGED
@@ -11,7 +11,10 @@ Campfire::Bot.config do |bot|
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# Events
|
14
|
-
bot.on(/^How are you?/) do |
|
15
|
-
|
14
|
+
bot.on(/^How are you?/) do |room, message|
|
15
|
+
room.speak("Im very sad thank-you")
|
16
|
+
room.play("trombone")
|
17
|
+
room.paste("This is a paste")
|
18
|
+
room.upload("/path/to/file.jpg")
|
16
19
|
end
|
17
20
|
end.start
|
data/lib/campfire_bot.rb
CHANGED
@@ -25,21 +25,17 @@ module Campfire
|
|
25
25
|
raise "You need to configure me" unless @campfire
|
26
26
|
|
27
27
|
@campfire.listen do |line|
|
28
|
-
evaluate(line
|
28
|
+
evaluate(line) if line[:body]
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def msg(text)
|
33
|
-
@campfire.speak(text)
|
34
|
-
end
|
35
|
-
|
36
32
|
def on(regex, &block)
|
37
33
|
@events << Event.new(regex, block)
|
38
34
|
end
|
39
35
|
|
40
36
|
def evaluate(message)
|
41
|
-
if event = find_event(message)
|
42
|
-
event.action.call(
|
37
|
+
if event = find_event(message[:body])
|
38
|
+
event.action.call(@campfire, message)
|
43
39
|
end
|
44
40
|
end
|
45
41
|
|
data/lib/campfire_bot/version.rb
CHANGED
data/spec/campfire_bot_spec.rb
CHANGED
@@ -1,20 +1,29 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "CampfireBot" do
|
4
|
+
let(:room) { mock("room") }
|
5
|
+
|
6
|
+
let(:bot) do
|
7
|
+
@bot = Campfire::Bot.new
|
8
|
+
@bot.login { }
|
9
|
+
@bot
|
10
|
+
end
|
11
|
+
|
4
12
|
before do
|
5
|
-
@room = mock("room")
|
6
13
|
campfire = mock("campfire")
|
7
|
-
campfire.stub!(:find_room_by_name).and_return(
|
14
|
+
campfire.stub!(:find_room_by_name).and_return(room)
|
8
15
|
@campfire = Tinder::Campfire.stub!(:new).and_return(campfire)
|
9
|
-
@bot = Campfire::Bot.new
|
10
|
-
@bot.login {}
|
11
16
|
end
|
12
17
|
|
13
|
-
describe "
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
describe "Check that methods get called on the room object" do
|
19
|
+
before do
|
20
|
+
bot.on(/hey/) {|room, message| room.speak("test") }
|
21
|
+
room.stub!(:speak)
|
17
22
|
end
|
23
|
+
|
24
|
+
after { bot.evaluate(message) }
|
25
|
+
|
26
|
+
specify { room.should_receive(:speak) }
|
18
27
|
end
|
19
28
|
|
20
29
|
describe "Starting without configuring" do
|
@@ -24,4 +33,10 @@ describe "CampfireBot" do
|
|
24
33
|
end.should raise_error(RuntimeError)
|
25
34
|
end
|
26
35
|
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def message
|
40
|
+
{ :body => "hey" }
|
41
|
+
end
|
27
42
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: campfire_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- reddavis
|
@@ -105,7 +105,6 @@ extensions: []
|
|
105
105
|
extra_rdoc_files: []
|
106
106
|
|
107
107
|
files:
|
108
|
-
- .bundle/config
|
109
108
|
- .document
|
110
109
|
- .gitignore
|
111
110
|
- .rspec
|
data/.bundle/config
DELETED