campfire_bot 0.0.4 → 0.0.5

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 CHANGED
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ .bundle/**
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- campfire_bot (0.0.3)
4
+ campfire_bot (0.0.5)
5
5
  i18n (~> 0.4.2)
6
6
  json
7
7
  tinder (~> 1.4.2)
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 |x|
29
- x.msg("Im very well thank-you")
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.
@@ -11,7 +11,10 @@ Campfire::Bot.config do |bot|
11
11
  end
12
12
 
13
13
  # Events
14
- bot.on(/^How are you?/) do |x|
15
- x.bot.msg("Im very well thank-you")
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
@@ -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[:body]) if line[:body]
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(self)
37
+ if event = find_event(message[:body])
38
+ event.action.call(@campfire, message)
43
39
  end
44
40
  end
45
41
 
@@ -1,5 +1,5 @@
1
1
  module Campfire
2
2
  class Bot
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -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(@room)
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 "Sending a message" do
14
- it "should send a message" do
15
- @room.should_receive(:speak)
16
- @bot.msg("hello")
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
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
@@ -1,2 +0,0 @@
1
- ---
2
- BUNDLE_DISABLE_SHARED_GEMS: "1"