jabber-bot 1.1.1 → 1.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.
- data/HISTORY +4 -0
- data/LICENSE +1 -1
- data/{README → README.rdoc} +20 -19
- data/lib/jabber/bot.rb +23 -24
- metadata +75 -48
data/HISTORY
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
Jabber::Bot Release History
|
2
2
|
|
3
|
+
Version 1.2.0 (23 April 2011)
|
4
|
+
* Optionally specify a startup message. (nstielau)
|
5
|
+
* Optionally disable the misunderstood command reply. (nstielau)
|
6
|
+
|
3
7
|
Version 1.1.1 (26 May 2007)
|
4
8
|
* Minor change to the listener thread that should improve CPU usage.
|
5
9
|
|
data/LICENSE
CHANGED
data/{README → README.rdoc}
RENAMED
@@ -1,30 +1,31 @@
|
|
1
1
|
= Jabber::Bot
|
2
2
|
|
3
|
-
Easily create
|
3
|
+
Easily create simple regex powered Jabber bots.
|
4
4
|
|
5
|
-
Jabber::Bot makes it simple to create and command your own Jabber bot
|
6
|
-
|
7
|
-
bot's repertoire, you and your new bot will be able to accomplish nearly
|
8
|
-
anything.
|
5
|
+
Jabber::Bot makes it simple to create and command your own Jabber bot. Bots
|
6
|
+
are created by defining commands powered by regular expressions and Ruby.
|
9
7
|
|
10
|
-
Author
|
11
|
-
Version
|
12
|
-
Copyright
|
13
|
-
License
|
14
|
-
Website
|
8
|
+
*Author*:: Brett Stimmerman (mailto:brettstimmerman@gmail.com)
|
9
|
+
*Version*:: 1.2.0 (2011-04-23)
|
10
|
+
*Copyright*:: Copyright (c) 2011 Brett Stimmerman. All rights reserved.
|
11
|
+
*License*:: New BSD License (http://opensource.org/licenses/bsd-license.php)
|
12
|
+
*Website*:: http://github.com/brettstimmerman/jabber-bot
|
15
13
|
|
16
|
-
==
|
14
|
+
== Requires
|
17
15
|
|
18
|
-
|
19
|
-
|
16
|
+
* RubyGems
|
17
|
+
* Jabber::Simple 0.8.7+
|
20
18
|
|
21
|
-
==
|
19
|
+
== Usage
|
22
20
|
|
23
|
-
|
21
|
+
require 'rubygems'
|
22
|
+
require 'jabber/bot'
|
23
|
+
|
24
|
+
# Create a public Jabber::Bot
|
24
25
|
config = {
|
25
|
-
:name => 'SampleBot'
|
26
|
+
:name => 'SampleBot',
|
26
27
|
:jabber_id => 'bot@example.com',
|
27
|
-
:password => '
|
28
|
+
:password => 'secret',
|
28
29
|
:master => 'master@example.com',
|
29
30
|
:is_public => true
|
30
31
|
}
|
@@ -46,9 +47,9 @@ Website:: http://socket7.net/software/jabber-bot
|
|
46
47
|
:alias => [ :alias => 'p <string>', :regex => /^p\s+.+$/ ],
|
47
48
|
:is_public => true
|
48
49
|
) do |sender, message|
|
49
|
-
puts "#{sender} says '#{message'"
|
50
|
+
puts "#{sender} says '#{message}'"
|
50
51
|
"'#{message}' written to $stdout"
|
51
52
|
end
|
52
53
|
|
53
54
|
# Bring your new bot to life
|
54
|
-
bot.connect
|
55
|
+
bot.connect
|
data/lib/jabber/bot.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2009 Brett Stimmerman <brettstimmerman@gmail.com>
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
@@ -31,22 +31,9 @@ require 'xmpp4r-simple'
|
|
31
31
|
|
32
32
|
module Jabber
|
33
33
|
|
34
|
-
# = Jabber::Bot
|
35
|
-
#
|
36
|
-
# Jabber::Bot makes it simple to create and command a Jabber bot with little
|
37
|
-
# fuss. By adding custom commands powered by regular expressions to your bot's
|
38
|
-
# repertoire, you and your new bot will be able to accomplish nearly anything.
|
39
|
-
#
|
40
|
-
# Author:: Brett Stimmerman (mailto:brettstimmerman@gmail.com)
|
41
|
-
# Version:: 1.1.1
|
42
|
-
# Copyright:: Copyright (c) 2007 Brett Stimmerman. All rights reserved.
|
43
|
-
# License:: New BSD License (http://opensource.org/licenses/bsd-license.php)
|
44
|
-
# Website:: http://socket7.net/software/jabber-bot
|
45
|
-
#
|
46
34
|
class Bot
|
47
35
|
|
48
|
-
# Direct access to the underlying
|
49
|
-
# Jabber::Simple[http://xmpp4r-simple.rubyforge.org/] object.
|
36
|
+
# Direct access to the underlying Jabber::Simple object.
|
50
37
|
attr_reader :jabber
|
51
38
|
|
52
39
|
# Creates a new Jabber::Bot object with the specified +config+ Hash, which
|
@@ -71,7 +58,7 @@ module Jabber
|
|
71
58
|
# # A minimally confiugured private bot with a single master.
|
72
59
|
# bot = Jabber::Bot.new(
|
73
60
|
# :jabber_id => 'bot@example.com',
|
74
|
-
# :password => '
|
61
|
+
# :password => 'secret',
|
75
62
|
# :master => 'master@example.com'
|
76
63
|
# )
|
77
64
|
#
|
@@ -82,7 +69,7 @@ module Jabber
|
|
82
69
|
# bot = Jabber::Bot.new(
|
83
70
|
# :name => 'PublicBot',
|
84
71
|
# :jabber_id => 'bot@example.com',
|
85
|
-
# :password => '
|
72
|
+
# :password => 'secret',
|
86
73
|
# :master => masters,
|
87
74
|
# :is_public => true,
|
88
75
|
# :presence => :chat,
|
@@ -105,6 +92,10 @@ module Jabber
|
|
105
92
|
|
106
93
|
@commands = { :spec => [], :meta => {} }
|
107
94
|
|
95
|
+
# Default to asking about unknown commands.
|
96
|
+
@config[:misunderstood_message] = @config[:misunderstood_message].nil? ? true : @config[:misunderstood_message]
|
97
|
+
|
98
|
+
# Add the help command
|
108
99
|
add_command(
|
109
100
|
:syntax => 'help [<command>]',
|
110
101
|
:description => 'Display help for the given command, or all commands' +
|
@@ -136,7 +127,7 @@ module Jabber
|
|
136
127
|
# The specified callback block will be triggered when the bot receives a
|
137
128
|
# message that matches the given command regex (or an alias regex). The
|
138
129
|
# callback block will have access to the sender and the message text (not
|
139
|
-
# including the command itsef), and should either return a String response
|
130
|
+
# including the command itsef), and should either return a String response
|
140
131
|
# or +nil+. If a callback block returns a String response, the response will
|
141
132
|
# be delivered to the Jabber id that issued the command.
|
142
133
|
#
|
@@ -160,7 +151,7 @@ module Jabber
|
|
160
151
|
# :syntax => 'puts! <string>',
|
161
152
|
# :description => 'Write something to $stdout (without response)',
|
162
153
|
# :regex => /^puts!\s+.+$/,
|
163
|
-
# :alias => [
|
154
|
+
# :alias => [
|
164
155
|
# { :syntax => 'p! <string>', :regex => /^p!\s+.+$/ },
|
165
156
|
# { :syntax => '! <string>', :regex => /^!\s+/.+$/ }
|
166
157
|
# ]
|
@@ -193,12 +184,14 @@ module Jabber
|
|
193
184
|
end
|
194
185
|
|
195
186
|
# Connect the bot, making it available to accept commands.
|
187
|
+
# You can specify a custom startup message with the ':startup_message'
|
188
|
+
# configuration setting.
|
196
189
|
def connect
|
197
190
|
@jabber = Jabber::Simple.new(@config[:jabber_id], @config[:password])
|
198
191
|
|
199
192
|
presence(@config[:presence], @config[:status], @config[:priority])
|
200
193
|
|
201
|
-
deliver(@config[:master],
|
194
|
+
deliver(@config[:master], (@config[:startup_message] || "NAME reporting for duty.").gsub("NAME", @config[:name]))
|
202
195
|
|
203
196
|
start_listener_thread
|
204
197
|
end
|
@@ -355,6 +348,10 @@ module Jabber
|
|
355
348
|
# the command trigger. If a String result is present it is delivered to the
|
356
349
|
# sender.
|
357
350
|
#
|
351
|
+
# If an unkown command is found, the bot will default to displaying the
|
352
|
+
# help message. You can disable this by setting the configuration
|
353
|
+
# setting ':misunderstood_message' to false.
|
354
|
+
#
|
358
355
|
# If the bot has not been made public, commands from anyone other than the
|
359
356
|
# bot master(s) will be silently ignored.
|
360
357
|
def parse_command(sender, message) #:nodoc:
|
@@ -372,15 +369,17 @@ module Jabber
|
|
372
369
|
|
373
370
|
response = command[:callback].call(sender, params)
|
374
371
|
deliver(sender, response) unless response.nil?
|
375
|
-
|
372
|
+
|
376
373
|
return
|
377
374
|
end
|
378
375
|
end
|
379
376
|
end
|
380
377
|
|
381
|
-
|
382
|
-
|
383
|
-
|
378
|
+
if @config[:misunderstood_message]
|
379
|
+
response = "I don't understand '#{message.strip}' Try saying 'help' " +
|
380
|
+
"to see what commands I understand."
|
381
|
+
deliver(sender, response)
|
382
|
+
end
|
384
383
|
end
|
385
384
|
end
|
386
385
|
|
metadata
CHANGED
@@ -1,64 +1,91 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.2
|
3
|
-
specification_version: 1
|
4
2
|
name: jabber-bot
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
-
|
11
|
-
|
12
|
-
|
13
|
-
rubyforge_project: jabber-bot
|
14
|
-
description:
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.8.4
|
24
|
-
version:
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
25
11
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
12
|
authors:
|
30
13
|
- Brett Stimmerman
|
31
|
-
|
32
|
-
|
33
|
-
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-23 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: xmpp4r-simple
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 49
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 8
|
32
|
+
- 7
|
33
|
+
version: 0.8.7
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description:
|
37
|
+
email: brettstimmerman@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- README.rdoc
|
34
44
|
- LICENSE
|
35
|
-
- README
|
36
45
|
- HISTORY
|
37
|
-
|
46
|
+
files:
|
47
|
+
- HISTORY
|
48
|
+
- LICENSE
|
49
|
+
- README.rdoc
|
50
|
+
- lib/jabber/bot.rb
|
51
|
+
homepage: http://github.com/brettstimmerman/jabber-bot
|
52
|
+
licenses: []
|
38
53
|
|
54
|
+
post_install_message:
|
39
55
|
rdoc_options:
|
40
56
|
- --title
|
41
57
|
- Jabber::Bot Documentation
|
42
58
|
- --main
|
43
|
-
- README
|
59
|
+
- README.rdoc
|
44
60
|
- --line-numbers
|
45
|
-
|
46
|
-
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 63
|
69
|
+
segments:
|
70
|
+
- 1
|
71
|
+
- 8
|
72
|
+
- 4
|
73
|
+
version: 1.8.4
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
53
83
|
requirements: []
|
54
84
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: 0.8.7
|
64
|
-
version:
|
85
|
+
rubyforge_project: jabber-bot
|
86
|
+
rubygems_version: 1.7.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Easily create simple regex powered Jabber bots.
|
90
|
+
test_files: []
|
91
|
+
|