jabbot 0.1.2 → 0.2.0

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.
@@ -1,7 +1,7 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper')) unless defined?(Jabbot)
1
+ require 'helper'
2
2
 
3
- class TestHash < Test::Unit::TestCase
4
- should "convert string keys to symbols" do
3
+ context "Hash" do
4
+ test "convert string keys to symbols" do
5
5
  hash = { "one" => 1, "two" => 2 }
6
6
  hash.symbolize_keys!
7
7
 
@@ -11,7 +11,7 @@ class TestHash < Test::Unit::TestCase
11
11
  assert_nil hash["two"]
12
12
  end
13
13
 
14
- should "convert string keys and preserve symbol keys" do
14
+ test "convert string keys and preserve symbol keys" do
15
15
  hash = { "one" => 1, :two => 2 }
16
16
  hash.symbolize_keys!
17
17
 
@@ -21,7 +21,7 @@ class TestHash < Test::Unit::TestCase
21
21
  assert_nil hash["two"]
22
22
  end
23
23
 
24
- should "convert hashes recursively" do
24
+ test "convert hashes recursively" do
25
25
  hash = { "one" => 1, :two => { "three" => 3, "four" => 4 } }
26
26
  hash.symbolize_keys!
27
27
 
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ context "Macros" do
4
+ test "provide configure macro" do
5
+ assert respond_to?(:configure)
6
+ end
7
+
8
+ test "yield configuration" do
9
+ Jabbot::Macros.bot = Jabbot::Bot.new Jabbot::Config.default
10
+
11
+ conf = nil
12
+ assert_nothing_raised { configure { |c| conf = c } }
13
+ assert conf.is_a?(Jabbot::Config)
14
+ end
15
+
16
+ test "add handler" do
17
+ Jabbot::Macros.bot = Jabbot::Bot.new Jabbot::Config.default
18
+
19
+ handler = add_handler(:message, ":command", :from => :cjno)
20
+ assert handler.is_a?(Jabbot::Handler)
21
+ end
22
+
23
+ test "provide client macro" do
24
+ assert respond_to?(:client)
25
+ end
26
+
27
+ test "provide users macro" do
28
+ assert respond_to?(:users)
29
+ assert_equal users, []
30
+ end
31
+ end
metadata CHANGED
@@ -1,102 +1,108 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jabbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
5
10
  platform: ruby
6
11
  authors:
7
- - BadBoy_
12
+ - badboy
8
13
  autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-04-27 00:00:00 +02:00
17
+ date: 2010-10-03 00:00:00 +02:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: xmpp4r
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 4
23
31
  version: "0.4"
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
- name: thoughtbot-shoulda
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
35
+ name: shoulda
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
30
39
  requirements:
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
42
+ segments:
43
+ - 2
44
+ - 10
45
+ - 1
33
46
  version: 2.10.1
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: jeweler
37
47
  type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 0.10.2
44
- version:
45
- description:
48
+ version_requirements: *id002
49
+ description: " Jabbot is a Ruby micro-framework for creating Jabber/MUC bots,\n heavily inspired by Sinatra and Twibot.\n\n I modified the code of Twibot to fit my needs.\n The original Twibot code is located at:\n http://github.com/cjohansen/twibot/tree/master\n\n A big thank you to Christian Johansen, who wrote the code for Twibot.\n Jabbot is heavily based on his code.\n\n It's as easy as definig a small message handler:\n message do |message, params|\n post message.text\n end\n"
46
50
  email: badboy@archlinux.us
47
51
  executables: []
48
52
 
49
53
  extensions: []
50
54
 
51
- extra_rdoc_files:
52
- - README.rdoc
55
+ extra_rdoc_files: []
56
+
53
57
  files:
54
- - README.rdoc
58
+ - README.md
55
59
  - Rakefile
56
- - VERSION.yml
60
+ - LICENSE
57
61
  - lib/hash.rb
58
62
  - lib/jabbot.rb
59
- - lib/jabbot/bot.rb
63
+ - lib/jabbot/macros.rb
60
64
  - lib/jabbot/config.rb
61
65
  - lib/jabbot/handlers.rb
62
- - lib/jabbot/macros.rb
66
+ - lib/jabbot/bot.rb
67
+ - lib/jabbot/version.rb
63
68
  - lib/jabbot/message.rb
64
- - test/test_bot.rb
65
69
  - test/test_config.rb
70
+ - test/test_macros.rb
71
+ - test/test_bot.rb
72
+ - test/helper.rb
66
73
  - test/test_handler.rb
67
74
  - test/test_hash.rb
68
- - test/test_helper.rb
69
75
  has_rdoc: true
70
76
  homepage: http://github.com/badboy/jabbot
71
77
  licenses: []
72
78
 
73
79
  post_install_message:
74
- rdoc_options:
75
- - --charset=UTF-8
80
+ rdoc_options: []
81
+
76
82
  require_paths:
77
83
  - lib
78
84
  required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
79
86
  requirements:
80
87
  - - ">="
81
88
  - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
82
91
  version: "0"
83
- version:
84
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
85
94
  requirements:
86
95
  - - ">="
87
96
  - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
88
99
  version: "0"
89
- version:
90
100
  requirements: []
91
101
 
92
- rubyforge_project: jabbot
93
- rubygems_version: 1.3.2
102
+ rubyforge_project:
103
+ rubygems_version: 1.3.7
94
104
  signing_key:
95
105
  specification_version: 3
96
106
  summary: Simple framework for creating Jabber/MUC bots, inspired by Sinatra and Twibot
97
- test_files:
98
- - test/test_helper.rb
99
- - test/test_bot.rb
100
- - test/test_hash.rb
101
- - test/test_config.rb
102
- - test/test_handler.rb
107
+ test_files: []
108
+
@@ -1,141 +0,0 @@
1
- = Jabbot
2
- Official URL: http://github.com/badboy/jabbot/tree/master
3
- Jan-Erik Rediger (BadBoy_) (http://badboy.pytalhost.de)
4
-
5
- == Description
6
-
7
- Jabbot is a Ruby microframework for creating Jabber/MUC
8
- bots, heavily inspired by Sinatra and Twibot.
9
- I modified the code of Twibot to fit my needs.
10
- The original Twibot code is located at:
11
- http://github.com/cjohansen/twibot/tree/master
12
-
13
- A big thank you to Christian Johansen, who wrote the code for Twibot.
14
- Jabbot is heavily based on his code.
15
-
16
- == Usage
17
-
18
- === Simple example
19
-
20
- require 'jabbot'
21
-
22
- # Receive messages, and post them publicly
23
- #
24
- message do |message, params|
25
- post message.text
26
- end
27
-
28
- # Respond to query if they come from the right crowd
29
- # post "message" => "user" is just some syntax sugar
30
- # post "message", "user" will work to
31
- query :from => [:cjno, :irbno] do |message, params|
32
- post "#{message.user} I agree" => message.user
33
- end
34
-
35
- # Listen in and log tweets
36
- # (you can use "message :all" too ;)
37
- message do |message, params|
38
- MyApp.log_message(message)
39
- end
40
-
41
- === Running the bot
42
-
43
- To run the bot, simply do:
44
-
45
- ruby bot.rb
46
-
47
- === Configuration
48
-
49
- Jabbot looks for a configuration file in ./config/bot.yml. It should contain
50
- atleast:
51
-
52
- login: jabber_login
53
- password: jabber_password
54
- channel: channel_to_join
55
- server: server_to_connect_to
56
- nick: mybot
57
-
58
- You can also configure with Ruby:
59
-
60
- configure do |conf|
61
- conf.login = "my_account"
62
- conf.nick = "mybot"
63
- do
64
-
65
- If you don't specify login and/or password in any of these ways, Jabbot will fail
66
- Nick is automatically set to "jabbot" unless something different is defined
67
- If you want you can set the Jabber Resource:
68
- conf.resource ="mybot_resource"
69
- Otherwise it is set to "jabbot", too
70
-
71
- === "Routes"
72
-
73
- Like Sinatra, and other web app frameworks, Jabbot supports "routes": patterns
74
- to match incoming tweets and messages:
75
-
76
- require 'jabbot'
77
-
78
- message "time :country :city" do |message,params|
79
- time = MyTimeService.lookup(params[:country], params[:city])
80
- post "Time is #{time} in #{params[:city]}, #{params[:country]}"
81
- end
82
-
83
- You can have several "message" blocks (or "join", "leave", "query" or "subject").
84
- Every matching block will be called.
85
-
86
- Jabbot also supports regular expressions as routes:
87
-
88
- require 'jabbot'
89
-
90
- message /^time ([^\s]*) ([^\s]*)/ do |message, params|
91
- # params is an array of matches when using regexp routes
92
- time = MyTimeService.lookup(params[0], params[1])
93
- post "Time is #{time} in #{params[:city]}, #{params[:country]}"
94
- end
95
-
96
- == Requirements
97
-
98
- xmpp4r. You'll need atleast 0.4.
99
- You can get it via rubygems:
100
- gem install xmpp4r
101
- or download it from:
102
- http://home.gna.org/xmpp4r/
103
-
104
- == Installation
105
-
106
- gem sources -a http://gems.github.com # you only have to do this once
107
- gem install badboy-jabbot
108
-
109
- == Is it Ruby 1.9?
110
-
111
- All tests passes even on Ruby 1.9.
112
- Seems like it works :)
113
-
114
- == Contributors
115
-
116
- * Christian Johansen (cjohansen) (author of Twibot) - http://www.cjohansen.no
117
-
118
- == License
119
-
120
- (The MIT License)
121
-
122
- Copyright (c) 2009 Jan-Erik Rediger (Badboy_)
123
-
124
- Permission is hereby granted, free of charge, to any person obtaining
125
- a copy of this software and associated documentation files (the
126
- 'Software'), to deal in the Software without restriction, including
127
- without limitation the rights to use, copy, modify, merge, publish,
128
- distribute, sublicense, and/or sell copies of the Software, and to
129
- permit persons to whom the Software is furnished to do so, subject to
130
- the following conditions:
131
-
132
- The above copyright notice and this permission notice shall be
133
- included in all copies or substantial portions of the Software.
134
-
135
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
136
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
137
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
138
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
139
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
140
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
141
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,4 +0,0 @@
1
- ---
2
- :major: 0
3
- :minor: 1
4
- :patch: 2
@@ -1,38 +0,0 @@
1
- require 'rubygems'
2
- if RUBY_VERSION =~ /1\.9/
3
- Gem.all_load_paths
4
- gem "thoughtbot-shoulda"
5
- gem "xmpp4r"
6
- end
7
- require 'test/unit'
8
- require 'shoulda'
9
- require File.join(File.dirname(__FILE__), '../lib/jabbot')
10
-
11
- module Test::Unit::Assertions
12
- def assert_hashes_equal(expected, actual, message = nil)
13
- full_message = build_message(message, <<EOT, expected.inspect, actual.inspect)
14
- <?> expected but was
15
- <?>.
16
- EOT
17
- assert_block(full_message) do
18
- break false if expected.keys.length != actual.keys.length
19
- expected.keys.all? { |k| expected[k] == actual[k] }
20
- end
21
- end
22
-
23
- def assert_hashes_not_equal(expected, actual, message = nil)
24
- full_message = build_message(message, <<EOT, expected.inspect, actual.inspect)
25
- <?> expected but was
26
- <?>.
27
- EOT
28
- assert_block(full_message) do
29
- break false if expected.keys.length != actual.keys.length
30
- expected.keys.any? { |k| expected[k] != actual[k] }
31
- end
32
- end
33
- end
34
-
35
- Message = Struct.new(:user, :text, :time)
36
- def message(user, text)
37
- Message.new(user, text, Time.now)
38
- end