happy_fun_time_bot 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/examples/example.rb CHANGED
@@ -4,8 +4,7 @@ require 'rubygems'
4
4
  require 'happy_fun_time_bot'
5
5
 
6
6
  # For hipchat, your :jid, :room and :password are available at https://www.hipchat.com/account/xmpp
7
- #@bot = HappyFunTimeBot.new(:jid => "xxxxx@chat.hipchat.com", :nick => "ImageBot", :room => "your_room@conf.hipchat.com", :password => "xxx")
8
- @bot = HappyFunTimeBot.new(:jid => "514_23995@chat.hipchat.com", :nick => "HappyFunTime Bot", :room => "514_dev_talk@conf.hipchat.com", :password => "kwanzaa")
7
+ @bot = HappyFunTimeBot.new(:jid => "xxxxx@chat.hipchat.com", :nick => "ImageBot", :room => "your_room@conf.hipchat.com", :password => "xxx")
9
8
 
10
9
  # calling !heybot will return a simple response.
11
10
  @bot.add_responder('heybot') do |from, args|
@@ -2,8 +2,7 @@
2
2
  %w(rubygems happy_fun_time_bot httparty).each {|r| require r }
3
3
 
4
4
  # For hipchat, your :jid, :room and :password are available at https://www.hipchat.com/account/xmpp
5
- #@bot = HappyFunTimeBot.new(:jid => "xxxxx@chat.hipchat.com", :nick => "ImageBot", :room => "your_room@conf.hipchat.com", :password => "xxx")
6
- @bot = HappyFunTimeBot.new(:jid => "514_23995@chat.hipchat.com", :nick => "HappyFunTime Bot", :room => "514_dev_talk@conf.hipchat.com", :password => "kwanzaa")
5
+ @bot = HappyFunTimeBot.new(:jid => "xxxxx@chat.hipchat.com", :nick => "ImageBot", :room => "your_room@conf.hipchat.com", :password => "xxx")
7
6
 
8
7
  # Let's create a simple image getter from google.
9
8
  class Google
@@ -28,7 +27,6 @@ end
28
27
 
29
28
  # let's find some images!
30
29
  @bot.add_responder('findimage') do |from, args|
31
- $stdout << "args are #{args}\n"
32
30
  url = Google.get_image_url(args)
33
31
  "Look! #{url}"
34
32
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{happy_fun_time_bot}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Grant Ammons"]
12
- s.date = %q{2011-06-12}
11
+ s.authors = [%q{Grant Ammons}]
12
+ s.date = %q{2011-09-13}
13
13
  s.description = %q{Easily create bots that can respond to anything!}
14
14
  s.email = %q{grant@pipelinedealsco.com}
15
15
  s.extra_rdoc_files = [
@@ -35,9 +35,9 @@ Gem::Specification.new do |s|
35
35
  "spec/spec_helper.rb"
36
36
  ]
37
37
  s.homepage = %q{http://github.com/gammons/happy_fun_time_bot}
38
- s.licenses = ["MIT"]
39
- s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.4.2}
38
+ s.licenses = [%q{MIT}]
39
+ s.require_paths = [%q{lib}]
40
+ s.rubygems_version = %q{1.8.6}
41
41
  s.summary = %q{Simple XMPP bot framework}
42
42
 
43
43
  if s.respond_to? :specification_version then
@@ -4,15 +4,15 @@
4
4
  module Jabber
5
5
  module MUC
6
6
  class MUCClient
7
-
7
+
8
8
  def join(jid, password=nil)
9
9
  if active?
10
10
  raise "MUCClient already active"
11
11
  end
12
-
12
+
13
13
  @jid = (jid.kind_of?(JID) ? jid : JID.new(jid))
14
14
  activate
15
-
15
+
16
16
  # Joining
17
17
  pres = Presence.new
18
18
  pres.to = @jid
@@ -20,13 +20,13 @@ module Jabber
20
20
  xmuc = XMUC.new
21
21
  xmuc.password = password
22
22
  pres.add(xmuc)
23
-
23
+
24
24
  # NOTE: Adding 'maxstanzas="0"' to 'history' subelement of xmuc nixes
25
25
  # the history being sent to us when we join.
26
26
  history = XMPPElement.new('history')
27
27
  history.add_attributes({'maxstanzas' => '0'})
28
28
  xmuc.add(history)
29
-
29
+
30
30
  # We don't use Stream#send_with_id here as it's unknown
31
31
  # if the MUC component *always* uses our stanza id.
32
32
  error = nil
@@ -43,7 +43,7 @@ module Jabber
43
43
  @affiliation = i.affiliation # we're interested in if it's :owner
44
44
  @role = i.role # :moderator ?
45
45
  end
46
-
46
+
47
47
  handle_presence(r, false)
48
48
  true
49
49
  else
@@ -51,15 +51,15 @@ module Jabber
51
51
  false
52
52
  end
53
53
  }
54
-
54
+
55
55
  if error
56
56
  deactivate
57
57
  raise ServerError.new(error)
58
58
  end
59
-
59
+
60
60
  self
61
61
  end
62
-
62
+
63
63
  end
64
64
  end
65
65
  end
@@ -39,7 +39,7 @@ class HappyFunTimeBot
39
39
  self
40
40
  end
41
41
 
42
- def add_responder(command = '', &block)
42
+ def add_responder(command = nil, &block)
43
43
  responders << Responder.new(command, &block)
44
44
  end
45
45
 
@@ -51,7 +51,8 @@ class HappyFunTimeBot
51
51
  private
52
52
 
53
53
  def process(from, command)
54
- return [] unless command =~ self.config[:command_regex]
54
+ return [] if !responders.any? {|r| r.command.nil? } and !(command =~ self.config[:command_regex])
55
+
55
56
  responders.select {|r| r.responds_to?($1) }.map do |responder|
56
57
  args = command.split
57
58
  args.shift
data/lib/responder.rb CHANGED
@@ -7,6 +7,11 @@ class Responder
7
7
  end
8
8
 
9
9
  def responds_to?(command)
10
+ # respond to all if our command is nil.
11
+ return true if @command.nil?
12
+
13
+ # otherwise parse out the command and make sure it matches
14
+ # our command.
10
15
  @command == command.split.first
11
16
  end
12
17
  end
@@ -39,5 +39,10 @@ describe "HappyFunTimeBot" do
39
39
  @bot.add_responder("argarg") { |from, args| "your args are #{args}" }
40
40
  @bot.send(:process, "bob", "!argarg monkey costume").should == ["your args are monkey costume"]
41
41
  end
42
+
43
+ it "should respond to all messages if we did not specify a specific responder" do
44
+ @bot.add_responder { |from, args| "got it." }
45
+ @bot.send(:process, "jim", "sending some stuff").should == ["got it."]
46
+ end
42
47
  end
43
48
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happy_fun_time_bot
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Grant Ammons
@@ -15,13 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-12 00:00:00 -04:00
19
- default_executable:
18
+ date: 2011-09-13 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
21
  name: ruby-debug
24
22
  type: :runtime
23
+ prerelease: false
25
24
  version_requirements: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
@@ -33,9 +32,9 @@ dependencies:
33
32
  version: "0"
34
33
  requirement: *id001
35
34
  - !ruby/object:Gem::Dependency
36
- prerelease: false
37
35
  name: xmpp4r
38
36
  type: :runtime
37
+ prerelease: false
39
38
  version_requirements: &id002 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
@@ -47,9 +46,9 @@ dependencies:
47
46
  version: "0"
48
47
  requirement: *id002
49
48
  - !ruby/object:Gem::Dependency
50
- prerelease: false
51
49
  name: json
52
50
  type: :runtime
51
+ prerelease: false
53
52
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
53
  none: false
55
54
  requirements:
@@ -61,9 +60,9 @@ dependencies:
61
60
  version: "0"
62
61
  requirement: *id003
63
62
  - !ruby/object:Gem::Dependency
64
- prerelease: false
65
63
  name: httparty
66
64
  type: :runtime
65
+ prerelease: false
67
66
  version_requirements: &id004 !ruby/object:Gem::Requirement
68
67
  none: false
69
68
  requirements:
@@ -75,9 +74,9 @@ dependencies:
75
74
  version: "0"
76
75
  requirement: *id004
77
76
  - !ruby/object:Gem::Dependency
78
- prerelease: false
79
77
  name: rspec
80
78
  type: :development
79
+ prerelease: false
81
80
  version_requirements: &id005 !ruby/object:Gem::Requirement
82
81
  none: false
83
82
  requirements:
@@ -91,9 +90,9 @@ dependencies:
91
90
  version: 2.3.0
92
91
  requirement: *id005
93
92
  - !ruby/object:Gem::Dependency
94
- prerelease: false
95
93
  name: yard
96
94
  type: :development
95
+ prerelease: false
97
96
  version_requirements: &id006 !ruby/object:Gem::Requirement
98
97
  none: false
99
98
  requirements:
@@ -107,9 +106,9 @@ dependencies:
107
106
  version: 0.6.0
108
107
  requirement: *id006
109
108
  - !ruby/object:Gem::Dependency
110
- prerelease: false
111
109
  name: bundler
112
110
  type: :development
111
+ prerelease: false
113
112
  version_requirements: &id007 !ruby/object:Gem::Requirement
114
113
  none: false
115
114
  requirements:
@@ -123,9 +122,9 @@ dependencies:
123
122
  version: 1.0.0
124
123
  requirement: *id007
125
124
  - !ruby/object:Gem::Dependency
126
- prerelease: false
127
125
  name: jeweler
128
126
  type: :development
127
+ prerelease: false
129
128
  version_requirements: &id008 !ruby/object:Gem::Requirement
130
129
  none: false
131
130
  requirements:
@@ -139,9 +138,9 @@ dependencies:
139
138
  version: 1.6.0
140
139
  requirement: *id008
141
140
  - !ruby/object:Gem::Dependency
142
- prerelease: false
143
141
  name: rcov
144
142
  type: :development
143
+ prerelease: false
145
144
  version_requirements: &id009 !ruby/object:Gem::Requirement
146
145
  none: false
147
146
  requirements:
@@ -178,7 +177,6 @@ files:
178
177
  - lib/responder.rb
179
178
  - spec/happy_fun_time_bot_spec.rb
180
179
  - spec/spec_helper.rb
181
- has_rdoc: true
182
180
  homepage: http://github.com/gammons/happy_fun_time_bot
183
181
  licenses:
184
182
  - MIT
@@ -208,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
206
  requirements: []
209
207
 
210
208
  rubyforge_project:
211
- rubygems_version: 1.4.2
209
+ rubygems_version: 1.8.6
212
210
  signing_key:
213
211
  specification_version: 3
214
212
  summary: Simple XMPP bot framework