happy_fun_time_bot 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
@@ -1,6 +1,6 @@
1
1
  # Happy fun time bot
2
2
 
3
- Have happy fun times with this configurable XMPP bot! It is SO easy to use!
3
+ Have happy fun times with this configurable XMPP bot! It is SO easy to use, especially for Hipchat!
4
4
 
5
5
  Lets take a look!
6
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'happy_fun_time_bot'
5
+
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")
9
+
10
+ # calling !heybot will return a simple response.
11
+ @bot.add_responder('heybot') do |from, args|
12
+ "Hai, #{from}!!"
13
+ end
14
+
15
+ # endless loop. Use bluepill or something else to daemonize it.
16
+ @bot.run!
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ %w(rubygems happy_fun_time_bot httparty).each {|r| require r }
3
+
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")
7
+
8
+ # Let's create a simple image getter from google.
9
+ class Google
10
+ include HTTParty
11
+ format :json
12
+
13
+ def self.get_image_url(search, options = {:start => 0})
14
+ if options[:random]
15
+ options[:start] = rand(12)
16
+ end
17
+
18
+ res = Google.get("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&safe=active&start=#{options[:start]}&rsz=8&q=#{URI.escape(search)}")
19
+ res["responseData"]["results"][0]["url"]
20
+ end
21
+
22
+ def self.get_youtube_url(search)
23
+ res = Google.get("http://gdata.youtube.com/feeds/api/videos?q=#{URI.escape(args)}&alt=json")
24
+ res["feed"]["entry"][0]["link"][0]['href']
25
+ end
26
+ end
27
+
28
+
29
+ # let's find some images!
30
+ @bot.add_responder('findimage') do |from, args|
31
+ $stdout << "args are #{args}\n"
32
+ url = Google.get_image_url(args)
33
+ "Look! #{url}"
34
+ end
35
+
36
+ @bot.run!
@@ -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.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Grant Ammons"]
12
- s.date = %q{2011-06-10}
12
+ s.date = %q{2011-06-12}
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 = [
@@ -25,6 +25,8 @@ Gem::Specification.new do |s|
25
25
  "README.md",
26
26
  "Rakefile",
27
27
  "VERSION",
28
+ "examples/example.rb",
29
+ "examples/find_image.rb",
28
30
  "happy_fun_time_bot.gemspec",
29
31
  "lib/bot/muc_client.rb",
30
32
  "lib/happy_fun_time_bot.rb",
@@ -53,7 +53,9 @@ class HappyFunTimeBot
53
53
  def process(from, command)
54
54
  return [] unless command =~ self.config[:command_regex]
55
55
  responders.select {|r| r.responds_to?($1) }.map do |responder|
56
- ret = responder.block.call(from, command.split.shift)
56
+ args = command.split
57
+ args.shift
58
+ ret = responder.block.call(from, args.join(' '))
57
59
  send_response(ret)
58
60
  ret
59
61
  end
@@ -34,5 +34,10 @@ describe "HappyFunTimeBot" do
34
34
  @bot.send(:process, "bob", "!findimage monkey").should == ["finding an image"]
35
35
  @bot.send(:process, "bob", "!google monkey").should == ["googling for you, bob."]
36
36
  end
37
+
38
+ it "should contain the args in the args arg" do
39
+ @bot.add_responder("argarg") { |from, args| "your args are #{args}" }
40
+ @bot.send(:process, "bob", "!argarg monkey costume").should == ["your args are monkey costume"]
41
+ end
37
42
  end
38
43
  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: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Grant Ammons
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-10 00:00:00 -04:00
18
+ date: 2011-06-12 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -170,6 +170,8 @@ files:
170
170
  - README.md
171
171
  - Rakefile
172
172
  - VERSION
173
+ - examples/example.rb
174
+ - examples/find_image.rb
173
175
  - happy_fun_time_bot.gemspec
174
176
  - lib/bot/muc_client.rb
175
177
  - lib/happy_fun_time_bot.rb