scamp 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -83,7 +83,7 @@ Matchers are tested in order and all that satisfy the match and conditions will
83
83
  end
84
84
 
85
85
  #
86
- # Named captures become avaiable in your match block
86
+ # Named captures become available in your match block
87
87
  #
88
88
  match /^say (?<yousaid>.+)$/ do
89
89
  say "You said #{yousaid}"
@@ -129,7 +129,11 @@ In the room/user conditions and say/play commands you can use the name or ID of
129
129
  say "#{user} said something in room #{room}", 237872
130
130
  say "#{user} said something in room #{room}", "System Administration"
131
131
 
132
- By default Scamp listens to itself. This could either be fun, or dangerous, you decide. You can turn this off by passing :first\_match\_only => true in the initialisation options
132
+ By default Scamp listens to itself. This could either be fun, or dangerous, you decide. You can turn this off by passing :ignore\_self => true in the initialisation options:
133
+
134
+ scamp = Scamp.new(:api_key => "YOUR API KEY", :subdomain => "yoursubdomain", :ignore_self => true)
135
+
136
+ Scamp will also run _all_ match blocks that an input string matches, you can make Scamp only run the first block it matches by passing in :first\_match\_only => true:
133
137
 
134
138
  scamp = Scamp.new(:api_key => "YOUR API KEY", :subdomain => "yoursubdomain", :first_match_only => true)
135
139
 
data/lib/scamp.rb CHANGED
@@ -18,7 +18,8 @@ class Scamp
18
18
  include Messages
19
19
 
20
20
  attr_accessor :rooms, :user_cache, :room_cache, :matchers, :api_key, :subdomain,
21
- :logger, :verbose, :first_match_only, :required_prefix, :rooms_to_join
21
+ :logger, :verbose, :first_match_only, :ignore_self, :required_prefix,
22
+ :rooms_to_join
22
23
 
23
24
  def initialize(options = {})
24
25
  options ||= {}
@@ -81,6 +82,7 @@ class Scamp
81
82
 
82
83
  def process_message(msg)
83
84
  logger.debug "Received message #{msg.inspect}"
85
+ return false if ignore_self && is_me?(msg[:user_id])
84
86
  matchers.each do |matcher|
85
87
  break if first_match_only & matcher.attempt(msg)
86
88
  end
@@ -17,6 +17,9 @@ class Scamp
17
17
  @rooms_to_join = room_list.map{|c| room_id(c) }
18
18
  end
19
19
 
20
+ # populate bot data separately, in case we are ignoring ourselves
21
+ fetch_data_for('me')
22
+
20
23
  end
21
24
  end
22
25
 
data/lib/scamp/users.rb CHANGED
@@ -8,6 +8,15 @@ class Scamp
8
8
  return user_id.to_s
9
9
  end
10
10
 
11
+ def is_me?(user_id)
12
+ if user_cache['me']
13
+ return user_cache['me']['id'] == user_id
14
+ else
15
+ fetch_data_for('me')
16
+ return false
17
+ end
18
+ end
19
+
11
20
  private
12
21
 
13
22
  def fetch_data_for(user_id)
data/lib/scamp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Scamp
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -3,7 +3,7 @@ require "spec_helper"
3
3
  describe Scamp do
4
4
  before do
5
5
  @valid_params = {:api_key => "6124d98749365e3db2c9e5b27ca04db6", :subdomain => "oxygen"}
6
- @valid_user_cache_data = {123 => {"name" => "foo"}, 456 => {"name" => "bar"}}
6
+ @valid_user_cache_data = {123 => {"name" => "foo"}, 456 => {"name" => "bar"}, 'me' => {"name" => "bot", "id" => 123}}
7
7
 
8
8
  # Stub fetch for room data
9
9
  @valid_room_cache_data = {
@@ -183,6 +183,21 @@ describe Scamp do
183
183
  bot.send(:process_message, {:room_id => 123, :user_id => 456, :body => "a string"})
184
184
  bot.send(:process_message, {:room_id => 456, :user_id => 123, :body => "a string"})
185
185
  end
186
+
187
+ it "should ignore itself if so requested" do
188
+ canary = mock
189
+ canary.expects(:bang).never
190
+
191
+ bot = a Scamp
192
+ bot.user_cache = @valid_user_cache_data
193
+ bot.ignore_self = true
194
+ bot.ignore_self.should be_true
195
+ bot.behaviour do
196
+ match("a string") {canary.bang}
197
+ end
198
+
199
+ bot.send(:process_message, {:user_id => 123, :body => "a string"})
200
+ end
186
201
  end
187
202
 
188
203
  describe "strings" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.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: 2011-09-24 00:00:00.000000000Z
12
+ date: 2011-09-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &70295424002980 !ruby/object:Gem::Requirement
16
+ requirement: &2152286680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0.beta.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70295424002980
24
+ version_requirements: *2152286680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yajl-ruby
27
- requirement: &70295424002200 !ruby/object:Gem::Requirement
27
+ requirement: &2152286140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.8.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70295424002200
35
+ version_requirements: *2152286140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: em-http-request
38
- requirement: &70295424001540 !ruby/object:Gem::Requirement
38
+ requirement: &2152285600 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0.beta.4
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70295424001540
46
+ version_requirements: *2152285600
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70295424000840 !ruby/object:Gem::Requirement
49
+ requirement: &2152285080 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.6.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70295424000840
57
+ version_requirements: *2152285080
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mocha
60
- requirement: &70295424000160 !ruby/object:Gem::Requirement
60
+ requirement: &2152284560 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.10.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70295424000160
68
+ version_requirements: *2152284560
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
- requirement: &70295423999460 !ruby/object:Gem::Requirement
71
+ requirement: &2152284020 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 1.7.6
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70295423999460
79
+ version_requirements: *2152284020
80
80
  description: Eventmachine based Campfire bot framework
81
81
  email:
82
82
  - will@willj.net