xmpp4r-robot 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/Rakefile +1 -1
- data/lib/xmpp4r/robot.rb +28 -14
- data/xmpp4r-robot.gemspec +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 195565e3a667fb773fa9077f35bc261002fe8f81
|
4
|
+
data.tar.gz: 2348c990da4f5f2109282c25a1f53feaf624c19e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0495733f172b0c49c8bfd2a9a5b32eb8d9a3a8027ea35d4bea5cdca061445bdb01f2faa5d78c37ff07adabb992195466e69f919c8d63bf1407faf4eddefd120
|
7
|
+
data.tar.gz: a08516fd324c7b9377acc0c710337e6c906a6cb2bd728974f0531a765ea6993e4c1a8f221f66fc8ef9381f9b2010c60a1494fdf3b31ad7e47a5a093cff4ca831
|
data/CHANGES.md
CHANGED
data/Rakefile
CHANGED
data/lib/xmpp4r/robot.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'set'
|
3
|
+
require 'thread'
|
3
4
|
|
4
5
|
require 'xmpp4r'
|
5
6
|
require 'xmpp4r/roster'
|
@@ -18,6 +19,9 @@ class Jabber::Robot
|
|
18
19
|
|
19
20
|
@retry_time = Float(opts[:retry_time] || 0)
|
20
21
|
@auto_accept_subscription = opts[:auto_accept_subscription]
|
22
|
+
|
23
|
+
@roster_mutex = Mutex.new
|
24
|
+
@helper_mutex = Mutex.new
|
21
25
|
end
|
22
26
|
|
23
27
|
def inspect
|
@@ -32,6 +36,9 @@ class Jabber::Robot
|
|
32
36
|
@helper ||= Jabber::Roster::Helper.new(client, false)
|
33
37
|
end
|
34
38
|
|
39
|
+
# Start the robot. This is not thread safe.
|
40
|
+
#
|
41
|
+
# @api public
|
35
42
|
def start
|
36
43
|
if @client # restart
|
37
44
|
stop
|
@@ -41,6 +48,7 @@ class Jabber::Robot
|
|
41
48
|
connect
|
42
49
|
login
|
43
50
|
available
|
51
|
+
roster
|
44
52
|
self
|
45
53
|
end
|
46
54
|
|
@@ -124,7 +132,7 @@ class Jabber::Robot
|
|
124
132
|
client.on_exception do |exp|
|
125
133
|
errback.call(exp) if errback
|
126
134
|
|
127
|
-
next
|
135
|
+
next if retry_time == 0.0
|
128
136
|
|
129
137
|
$stderr.puts "ERROR: #{exp}: #{exp.backtrace}" +
|
130
138
|
" We'll sleep for #{retry_time} seconds and retry."
|
@@ -140,13 +148,15 @@ class Jabber::Robot
|
|
140
148
|
end
|
141
149
|
|
142
150
|
notify_presence do |jid, status|
|
143
|
-
@
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
151
|
+
@roster_mutex.synchronize do
|
152
|
+
@roster[:unknown].delete(jid) if @roster[:unknown]
|
153
|
+
|
154
|
+
[:available, :away, :unavailable].each do |type|
|
155
|
+
if type == status
|
156
|
+
@roster[type].add(jid)
|
157
|
+
else
|
158
|
+
@roster[type].delete(jid)
|
159
|
+
end
|
150
160
|
end
|
151
161
|
end
|
152
162
|
end
|
@@ -163,12 +173,16 @@ class Jabber::Robot
|
|
163
173
|
end
|
164
174
|
|
165
175
|
def sync_roster
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
176
|
+
@helper_mutex.synchronize do
|
177
|
+
clear_roster_semaphore
|
178
|
+
helper.get_roster
|
179
|
+
helper.wait_for_roster
|
180
|
+
end
|
181
|
+
@roster_mutex.synchronize do
|
182
|
+
@roster[:unknown] =
|
183
|
+
Set.new(helper.items.keys.map(&method(:jid_to_username))) -
|
184
|
+
@roster[:available] - @roster[:away] - @roster[:unavailable]
|
185
|
+
end
|
172
186
|
end
|
173
187
|
|
174
188
|
# a hack to let us always get the latest roster
|
data/xmpp4r-robot.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: xmpp4r-robot 0.2.
|
2
|
+
# stub: xmpp4r-robot 0.2.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "xmpp4r-robot"
|
6
|
-
s.version = "0.2.
|
6
|
+
s.version = "0.2.1"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.authors = ["Lin Jen-Shin (godfat)"]
|
11
|
-
s.date = "2014-01-
|
11
|
+
s.date = "2014-01-25"
|
12
12
|
s.description = "Simple XMPP client built upon xmpp4r. Intended for building simple robots."
|
13
13
|
s.email = ["godfat (XD) godfat.org"]
|
14
14
|
s.files = [
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmpp4r-robot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin Jen-Shin (godfat)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xmpp4r
|