safubot 0.0.5 → 0.0.6

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/doc/index.html CHANGED
@@ -119,9 +119,9 @@
119
119
  <span class='kw'>end</span>
120
120
  <span class='kw'>end</span>
121
121
 
122
- <span class='comment'># This will fork the Twitter/XMPP streaming processes as needed
123
- </span><span class='comment'># and then wait for them. You can call run_nowait if you want
124
- </span><span class='comment'># a non-blocking form.
122
+ <span class='comment'># This will run the Twitter/XMPP streaming processes.
123
+ </span><span class='comment'># If both are needed, the first-enabled one will be forked
124
+ </span><span class='comment'># into its own process.
125
125
  </span><span class='const'>NiftyBot</span><span class='period'>.</span><span class='id new'>new</span><span class='period'>.</span><span class='id run'>run</span>
126
126
  </pre>
127
127
 
@@ -166,11 +166,11 @@
166
166
 
167
167
  <h2><a name="caveats">Caveats</a></h2>
168
168
 
169
- <p>I've yet to determine how to make multiple libraries with their own EventMachine loops play nice together, so the TweetStream and Blather clients are currently run in their own processes. Keep in mind the effect this will have on the execution context of your event handlers. MongoDB is your friend!</p>
169
+ <p>I've yet to determine how to make multiple libraries with their own EventMachine loops play nice together, so the TweetStream and Blather clients are currently run in separate processes. Keep in mind the effect this will have on the execution context of your event handlers. MongoDB is your friend!</p>
170
170
  </div></div>
171
171
 
172
172
  <div id="footer">
173
- Generated on Thu Dec 1 18:19:17 2011 by
173
+ Generated on Thu Dec 1 11:12:26 2011 by
174
174
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
175
175
  0.7.3 (ruby-1.9.2).
176
176
  </div>
data/doc/method_list.html CHANGED
@@ -105,17 +105,17 @@
105
105
 
106
106
 
107
107
  <li class="r1 ">
108
- <span class='object_link'><a href="Safubot/XMPP/Bot.html#client-instance_method" title="Safubot::XMPP::Bot#client (method)">#client</a></span>
108
+ <span class='object_link'><a href="Safubot/Twitter/Bot.html#client-instance_method" title="Safubot::Twitter::Bot#client (method)">#client</a></span>
109
109
 
110
- <small>Safubot::XMPP::Bot</small>
110
+ <small>Safubot::Twitter::Bot</small>
111
111
 
112
112
  </li>
113
113
 
114
114
 
115
115
  <li class="r2 ">
116
- <span class='object_link'><a href="Safubot/Twitter/Bot.html#client-instance_method" title="Safubot::Twitter::Bot#client (method)">#client</a></span>
116
+ <span class='object_link'><a href="Safubot/XMPP/Bot.html#client-instance_method" title="Safubot::XMPP::Bot#client (method)">#client</a></span>
117
117
 
118
- <small>Safubot::Twitter::Bot</small>
118
+ <small>Safubot::XMPP::Bot</small>
119
119
 
120
120
  </li>
121
121
 
@@ -177,17 +177,17 @@
177
177
 
178
178
 
179
179
  <li class="r2 ">
180
- <span class='object_link'><a href="Safubot/Twitter/Tweet.html#from-class_method" title="Safubot::Twitter::Tweet.from (method)">from</a></span>
180
+ <span class='object_link'><a href="Safubot/Twitter/Bot.html#fork-instance_method" title="Safubot::Twitter::Bot#fork (method)">#fork</a></span>
181
181
 
182
- <small>Safubot::Twitter::Tweet</small>
182
+ <small>Safubot::Twitter::Bot</small>
183
183
 
184
184
  </li>
185
185
 
186
186
 
187
187
  <li class="r1 ">
188
- <span class='object_link'><a href="Safubot/XMPP/Message.html#from-class_method" title="Safubot::XMPP::Message.from (method)">from</a></span>
188
+ <span class='object_link'><a href="Safubot/XMPP/Bot.html#fork-instance_method" title="Safubot::XMPP::Bot#fork (method)">#fork</a></span>
189
189
 
190
- <small>Safubot::XMPP::Message</small>
190
+ <small>Safubot::XMPP::Bot</small>
191
191
 
192
192
  </li>
193
193
 
@@ -200,6 +200,22 @@
200
200
  </li>
201
201
 
202
202
 
203
+ <li class="r1 ">
204
+ <span class='object_link'><a href="Safubot/XMPP/Message.html#from-class_method" title="Safubot::XMPP::Message.from (method)">from</a></span>
205
+
206
+ <small>Safubot::XMPP::Message</small>
207
+
208
+ </li>
209
+
210
+
211
+ <li class="r2 ">
212
+ <span class='object_link'><a href="Safubot/Twitter/Tweet.html#from-class_method" title="Safubot::Twitter::Tweet.from (method)">from</a></span>
213
+
214
+ <small>Safubot::Twitter::Tweet</small>
215
+
216
+ </li>
217
+
218
+
203
219
  <li class="r1 ">
204
220
  <span class='object_link'><a href="Safubot/Twitter/Bot.html#handle_message-instance_method" title="Safubot::Twitter::Bot#handle_message (method)">#handle_message</a></span>
205
221
 
@@ -249,25 +265,25 @@
249
265
 
250
266
 
251
267
  <li class="r1 ">
252
- <span class='object_link'><a href="Safubot/Twitter/Bot.html#initialize-instance_method" title="Safubot::Twitter::Bot#initialize (method)">#initialize</a></span>
268
+ <span class='object_link'><a href="Safubot/Bot.html#initialize-instance_method" title="Safubot::Bot#initialize (method)">#initialize</a></span>
253
269
 
254
- <small>Safubot::Twitter::Bot</small>
270
+ <small>Safubot::Bot</small>
255
271
 
256
272
  </li>
257
273
 
258
274
 
259
275
  <li class="r2 ">
260
- <span class='object_link'><a href="Safubot/XMPP/Bot.html#initialize-instance_method" title="Safubot::XMPP::Bot#initialize (method)">#initialize</a></span>
276
+ <span class='object_link'><a href="Safubot/Twitter/Bot.html#initialize-instance_method" title="Safubot::Twitter::Bot#initialize (method)">#initialize</a></span>
261
277
 
262
- <small>Safubot::XMPP::Bot</small>
278
+ <small>Safubot::Twitter::Bot</small>
263
279
 
264
280
  </li>
265
281
 
266
282
 
267
283
  <li class="r1 ">
268
- <span class='object_link'><a href="Safubot/Bot.html#initialize-instance_method" title="Safubot::Bot#initialize (method)">#initialize</a></span>
284
+ <span class='object_link'><a href="Safubot/XMPP/Bot.html#initialize-instance_method" title="Safubot::XMPP::Bot#initialize (method)">#initialize</a></span>
269
285
 
270
- <small>Safubot::Bot</small>
286
+ <small>Safubot::XMPP::Bot</small>
271
287
 
272
288
  </li>
273
289
 
@@ -289,25 +305,25 @@
289
305
 
290
306
 
291
307
  <li class="r2 ">
292
- <span class='object_link'><a href="Safubot/XMPP/Message.html#make_request-instance_method" title="Safubot::XMPP::Message#make_request (method)">#make_request</a></span>
308
+ <span class='object_link'><a href="Safubot/Twitter/DirectMessage.html#make_request-instance_method" title="Safubot::Twitter::DirectMessage#make_request (method)">#make_request</a></span>
293
309
 
294
- <small>Safubot::XMPP::Message</small>
310
+ <small>Safubot::Twitter::DirectMessage</small>
295
311
 
296
312
  </li>
297
313
 
298
314
 
299
315
  <li class="r1 ">
300
- <span class='object_link'><a href="Safubot/Twitter/DirectMessage.html#make_request-instance_method" title="Safubot::Twitter::DirectMessage#make_request (method)">#make_request</a></span>
316
+ <span class='object_link'><a href="Safubot/Twitter/Tweet.html#make_request-instance_method" title="Safubot::Twitter::Tweet#make_request (method)">#make_request</a></span>
301
317
 
302
- <small>Safubot::Twitter::DirectMessage</small>
318
+ <small>Safubot::Twitter::Tweet</small>
303
319
 
304
320
  </li>
305
321
 
306
322
 
307
323
  <li class="r2 ">
308
- <span class='object_link'><a href="Safubot/Twitter/Tweet.html#make_request-instance_method" title="Safubot::Twitter::Tweet#make_request (method)">#make_request</a></span>
324
+ <span class='object_link'><a href="Safubot/XMPP/Message.html#make_request-instance_method" title="Safubot::XMPP::Message#make_request (method)">#make_request</a></span>
309
325
 
310
- <small>Safubot::Twitter::Tweet</small>
326
+ <small>Safubot::XMPP::Message</small>
311
327
 
312
328
  </li>
313
329
 
@@ -361,17 +377,17 @@
361
377
 
362
378
 
363
379
  <li class="r1 ">
364
- <span class='object_link'><a href="Safubot/Bot.html#opts-instance_method" title="Safubot::Bot#opts (method)">#opts</a></span>
380
+ <span class='object_link'><a href="Safubot/Twitter/Bot.html#opts-instance_method" title="Safubot::Twitter::Bot#opts (method)">#opts</a></span>
365
381
 
366
- <small>Safubot::Bot</small>
382
+ <small>Safubot::Twitter::Bot</small>
367
383
 
368
384
  </li>
369
385
 
370
386
 
371
387
  <li class="r2 ">
372
- <span class='object_link'><a href="Safubot/Twitter/Bot.html#opts-instance_method" title="Safubot::Twitter::Bot#opts (method)">#opts</a></span>
388
+ <span class='object_link'><a href="Safubot/Bot.html#opts-instance_method" title="Safubot::Bot#opts (method)">#opts</a></span>
373
389
 
374
- <small>Safubot::Twitter::Bot</small>
390
+ <small>Safubot::Bot</small>
375
391
 
376
392
  </li>
377
393
 
@@ -393,17 +409,17 @@
393
409
 
394
410
 
395
411
  <li class="r1 ">
396
- <span class='object_link'><a href="Safubot/XMPP/Bot.html#pid-instance_method" title="Safubot::XMPP::Bot#pid (method)">#pid</a></span>
412
+ <span class='object_link'><a href="Safubot/Twitter/Bot.html#pid-instance_method" title="Safubot::Twitter::Bot#pid (method)">#pid</a></span>
397
413
 
398
- <small>Safubot::XMPP::Bot</small>
414
+ <small>Safubot::Twitter::Bot</small>
399
415
 
400
416
  </li>
401
417
 
402
418
 
403
419
  <li class="r2 ">
404
- <span class='object_link'><a href="Safubot/Twitter/Bot.html#pid-instance_method" title="Safubot::Twitter::Bot#pid (method)">#pid</a></span>
420
+ <span class='object_link'><a href="Safubot/XMPP/Bot.html#pid-instance_method" title="Safubot::XMPP::Bot#pid (method)">#pid</a></span>
405
421
 
406
- <small>Safubot::Twitter::Bot</small>
422
+ <small>Safubot::XMPP::Bot</small>
407
423
 
408
424
  </li>
409
425
 
@@ -497,9 +513,9 @@
497
513
 
498
514
 
499
515
  <li class="r2 ">
500
- <span class='object_link'><a href="Safubot/Twitter/Bot.html#run-instance_method" title="Safubot::Twitter::Bot#run (method)">#run</a></span>
516
+ <span class='object_link'><a href="Safubot/XMPP/Bot.html#run-instance_method" title="Safubot::XMPP::Bot#run (method)">#run</a></span>
501
517
 
502
- <small>Safubot::Twitter::Bot</small>
518
+ <small>Safubot::XMPP::Bot</small>
503
519
 
504
520
  </li>
505
521
 
@@ -513,9 +529,9 @@
513
529
 
514
530
 
515
531
  <li class="r2 ">
516
- <span class='object_link'><a href="Safubot/XMPP/Bot.html#run-instance_method" title="Safubot::XMPP::Bot#run (method)">#run</a></span>
532
+ <span class='object_link'><a href="Safubot/Twitter/Bot.html#run-instance_method" title="Safubot::Twitter::Bot#run (method)">#run</a></span>
517
533
 
518
- <small>Safubot::XMPP::Bot</small>
534
+ <small>Safubot::Twitter::Bot</small>
519
535
 
520
536
  </li>
521
537
 
@@ -529,17 +545,17 @@
529
545
 
530
546
 
531
547
  <li class="r2 ">
532
- <span class='object_link'><a href="Safubot/Bot.html#run_nowait-instance_method" title="Safubot::Bot#run_nowait (method)">#run_nowait</a></span>
548
+ <span class='object_link'><a href="Safubot/Twitter/Bot.html#run_stream-instance_method" title="Safubot::Twitter::Bot#run_stream (method)">#run_stream</a></span>
533
549
 
534
- <small>Safubot::Bot</small>
550
+ <small>Safubot::Twitter::Bot</small>
535
551
 
536
552
  </li>
537
553
 
538
554
 
539
555
  <li class="r1 ">
540
- <span class='object_link'><a href="Safubot/Twitter/Bot.html#run_stream-instance_method" title="Safubot::Twitter::Bot#run_stream (method)">#run_stream</a></span>
556
+ <span class='object_link'><a href="Safubot/XMPP/Bot.html#send-instance_method" title="Safubot::XMPP::Bot#send (method)">#send</a></span>
541
557
 
542
- <small>Safubot::Twitter::Bot</small>
558
+ <small>Safubot::XMPP::Bot</small>
543
559
 
544
560
  </li>
545
561
 
@@ -553,7 +569,7 @@
553
569
 
554
570
 
555
571
  <li class="r1 ">
556
- <span class='object_link'><a href="Safubot/XMPP/Bot.html#send-instance_method" title="Safubot::XMPP::Bot#send (method)">#send</a></span>
572
+ <span class='object_link'><a href="Safubot/XMPP/Bot.html#state-instance_method" title="Safubot::XMPP::Bot#state (method)">#state</a></span>
557
573
 
558
574
  <small>Safubot::XMPP::Bot</small>
559
575
 
@@ -561,7 +577,7 @@
561
577
 
562
578
 
563
579
  <li class="r2 ">
564
- <span class='object_link'><a href="Safubot/XMPP/Bot.html#state-instance_method" title="Safubot::XMPP::Bot#state (method)">#state</a></span>
580
+ <span class='object_link'><a href="Safubot/XMPP/Bot.html#stop-instance_method" title="Safubot::XMPP::Bot#stop (method)">#stop</a></span>
565
581
 
566
582
  <small>Safubot::XMPP::Bot</small>
567
583
 
@@ -569,33 +585,33 @@
569
585
 
570
586
 
571
587
  <li class="r1 ">
572
- <span class='object_link'><a href="Safubot/Bot.html#stop-instance_method" title="Safubot::Bot#stop (method)">#stop</a></span>
588
+ <span class='object_link'><a href="Safubot/Twitter/Bot.html#stop-instance_method" title="Safubot::Twitter::Bot#stop (method)">#stop</a></span>
573
589
 
574
- <small>Safubot::Bot</small>
590
+ <small>Safubot::Twitter::Bot</small>
575
591
 
576
592
  </li>
577
593
 
578
594
 
579
595
  <li class="r2 ">
580
- <span class='object_link'><a href="Safubot/Twitter/Bot.html#stop-instance_method" title="Safubot::Twitter::Bot#stop (method)">#stop</a></span>
596
+ <span class='object_link'><a href="Safubot/Bot.html#stop-instance_method" title="Safubot::Bot#stop (method)">#stop</a></span>
581
597
 
582
- <small>Safubot::Twitter::Bot</small>
598
+ <small>Safubot::Bot</small>
583
599
 
584
600
  </li>
585
601
 
586
602
 
587
603
  <li class="r1 ">
588
- <span class='object_link'><a href="Safubot/XMPP/Bot.html#stop-instance_method" title="Safubot::XMPP::Bot#stop (method)">#stop</a></span>
604
+ <span class='object_link'><a href="Safubot/Twitter/Bot.html#stream-instance_method" title="Safubot::Twitter::Bot#stream (method)">#stream</a></span>
589
605
 
590
- <small>Safubot::XMPP::Bot</small>
606
+ <small>Safubot::Twitter::Bot</small>
591
607
 
592
608
  </li>
593
609
 
594
610
 
595
611
  <li class="r2 ">
596
- <span class='object_link'><a href="Safubot/Twitter/Bot.html#stream-instance_method" title="Safubot::Twitter::Bot#stream (method)">#stream</a></span>
612
+ <span class='object_link'><a href="Safubot/Bot.html#subbots-instance_method" title="Safubot::Bot#subbots (method)">#subbots</a></span>
597
613
 
598
- <small>Safubot::Twitter::Bot</small>
614
+ <small>Safubot::Bot</small>
599
615
 
600
616
  </li>
601
617
 
@@ -657,9 +673,9 @@
657
673
 
658
674
 
659
675
  <li class="r2 ">
660
- <span class='object_link'><a href="Safubot/Twitter/Tweet.html#user-instance_method" title="Safubot::Twitter::Tweet#user (method)">#user</a></span>
676
+ <span class='object_link'><a href="Safubot/XMPP/Message.html#user-instance_method" title="Safubot::XMPP::Message#user (method)">#user</a></span>
661
677
 
662
- <small>Safubot::Twitter::Tweet</small>
678
+ <small>Safubot::XMPP::Message</small>
663
679
 
664
680
  </li>
665
681
 
@@ -673,49 +689,49 @@
673
689
 
674
690
 
675
691
  <li class="r2 ">
676
- <span class='object_link'><a href="Safubot/XMPP/Message.html#user-instance_method" title="Safubot::XMPP::Message#user (method)">#user</a></span>
692
+ <span class='object_link'><a href="Safubot/Twitter/Tweet.html#user-instance_method" title="Safubot::Twitter::Tweet#user (method)">#user</a></span>
677
693
 
678
- <small>Safubot::XMPP::Message</small>
694
+ <small>Safubot::Twitter::Tweet</small>
679
695
 
680
696
  </li>
681
697
 
682
698
 
683
699
  <li class="r1 ">
684
- <span class='object_link'><a href="Safubot/Twitter/Bot.html#username-instance_method" title="Safubot::Twitter::Bot#username (method)">#username</a></span>
700
+ <span class='object_link'><a href="Safubot/Query.html#username-instance_method" title="Safubot::Query#username (method)">#username</a></span>
685
701
 
686
- <small>Safubot::Twitter::Bot</small>
702
+ <small>Safubot::Query</small>
687
703
 
688
704
  </li>
689
705
 
690
706
 
691
707
  <li class="r2 ">
692
- <span class='object_link'><a href="Safubot/XMPP/Message.html#username-instance_method" title="Safubot::XMPP::Message#username (method)">#username</a></span>
708
+ <span class='object_link'><a href="Safubot/Twitter/Bot.html#username-instance_method" title="Safubot::Twitter::Bot#username (method)">#username</a></span>
693
709
 
694
- <small>Safubot::XMPP::Message</small>
710
+ <small>Safubot::Twitter::Bot</small>
695
711
 
696
712
  </li>
697
713
 
698
714
 
699
715
  <li class="r1 ">
700
- <span class='object_link'><a href="Safubot/Twitter/Tweet.html#username-instance_method" title="Safubot::Twitter::Tweet#username (method)">#username</a></span>
716
+ <span class='object_link'><a href="Safubot/Twitter/DirectMessage.html#username-instance_method" title="Safubot::Twitter::DirectMessage#username (method)">#username</a></span>
701
717
 
702
- <small>Safubot::Twitter::Tweet</small>
718
+ <small>Safubot::Twitter::DirectMessage</small>
703
719
 
704
720
  </li>
705
721
 
706
722
 
707
723
  <li class="r2 ">
708
- <span class='object_link'><a href="Safubot/Query.html#username-instance_method" title="Safubot::Query#username (method)">#username</a></span>
724
+ <span class='object_link'><a href="Safubot/XMPP/Message.html#username-instance_method" title="Safubot::XMPP::Message#username (method)">#username</a></span>
709
725
 
710
- <small>Safubot::Query</small>
726
+ <small>Safubot::XMPP::Message</small>
711
727
 
712
728
  </li>
713
729
 
714
730
 
715
731
  <li class="r1 ">
716
- <span class='object_link'><a href="Safubot/Twitter/DirectMessage.html#username-instance_method" title="Safubot::Twitter::DirectMessage#username (method)">#username</a></span>
732
+ <span class='object_link'><a href="Safubot/Twitter/Tweet.html#username-instance_method" title="Safubot::Twitter::Tweet#username (method)">#username</a></span>
717
733
 
718
- <small>Safubot::Twitter::DirectMessage</small>
734
+ <small>Safubot::Twitter::Tweet</small>
719
735
 
720
736
  </li>
721
737
 
@@ -94,7 +94,7 @@
94
94
  </div>
95
95
 
96
96
  <div id="footer">
97
- Generated on Thu Dec 1 18:19:17 2011 by
97
+ Generated on Thu Dec 1 11:12:27 2011 by
98
98
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
99
99
  0.7.3 (ruby-1.9.2).
100
100
  </div>
data/lib/safubot/bot.rb CHANGED
@@ -78,7 +78,7 @@ module Safubot
78
78
  class Bot
79
79
  include Evented
80
80
 
81
- attr_reader :opts, :twitter, :xmpp
81
+ attr_reader :opts, :twitter, :xmpp, :subbots
82
82
 
83
83
  ##
84
84
  # Records an error in processing and emits a corresponding :request_error event.
@@ -219,27 +219,21 @@ module Safubot
219
219
  end
220
220
  end
221
221
 
222
- # Runs an initial request-processing loop and then forks the streaming processes.
223
- def run_nowait
222
+ def run
224
223
  pull; process; push
225
- @twitter.run if @twitter
226
- @xmpp.run if @xmpp
227
- end
228
224
 
229
- # Calls run_nowait and then waits for all child processes.
230
- def run
231
- run_nowait
232
- begin
233
- Process.waitall
234
- rescue Interrupt
235
- stop
225
+ @subbots[0..-2].each do |subbot|
226
+ subbot.fork
236
227
  end
228
+
229
+ # Run the final subbot in this process to avoid unnecessary forking
230
+ # and thus memory consumption.
231
+ @subbots[-1].run
237
232
  end
238
233
 
239
234
  # Shuts down the streaming processes.
240
235
  def stop
241
- @twitter.stop if @twitter
242
- @xmpp.stop if @xmpp
236
+ @subbots.each { |subbot| subbot.stop }
243
237
  end
244
238
 
245
239
  # Initialises Twitter-related functionality.
@@ -249,6 +243,7 @@ module Safubot
249
243
  process_request(req)
250
244
  req.responses.where(:dispatched => false).map(&method(:dispatch))
251
245
  end
246
+ @subbots.push(@twitter)
252
247
  end
253
248
 
254
249
  # Initialises XMPP-related functionality.
@@ -259,6 +254,7 @@ module Safubot
259
254
  process_request(req)
260
255
  req.responses.where(:dispatched => false).map(&method(:dispatch))
261
256
  end
257
+ @subbots.push(@xmpp)
262
258
  end
263
259
 
264
260
  def initialize(options={})
@@ -266,7 +262,9 @@ module Safubot
266
262
  @opts = defaults.merge(options)
267
263
  MongoMapper.database = @opts[:database]
268
264
  MongoMapper.connection = Mongo::Connection.new('localhost', 27017, :pool_size => 5)
265
+ MongoMapper::Document.plugin(MongoMapper::Plugins::IdentityMap)
269
266
  @handlers = {}
267
+ @subbots = []
270
268
  end
271
269
  end
272
270
  end
@@ -268,17 +268,22 @@ module Safubot
268
268
  else
269
269
  Log.error "TweetStream client exited unexpectedly: #{error_report(e)}"
270
270
  Log.error "Restarting TweetStream client in 5 seconds."
271
- sleep 5; init_stream; run_stream
271
+ EM::Timer.new(5) { init_stream; run_stream }
272
272
  end
273
273
  end
274
274
  end
275
275
 
276
- # Starts our TweetStream client running in a new process.
276
+ # Starts our TweetStream client running.
277
277
  def run
278
+ init_stream
279
+ run_stream
280
+ end
281
+
282
+ # Starts our TweetStream client running in a new process.
283
+ def fork
278
284
  @pid = Process.fork do
279
285
  Signal.trap("TERM") { stop }
280
- init_stream
281
- run_stream
286
+ run
282
287
  end
283
288
  end
284
289
 
@@ -1,3 +1,3 @@
1
1
  module Safubot
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/safubot/xmpp.rb CHANGED
@@ -98,7 +98,7 @@ module Safubot
98
98
  sleep 1 # HACK (Mispy): Give the state a chance to change when we're stopped.
99
99
  if @state == :running
100
100
  Log.warn("XMPP disconnected; attempting reconnection in 5 seconds.")
101
- sleep 5; @client.connect
101
+ EM::Timer.new(5) { @client.connect }
102
102
  end
103
103
  end
104
104
 
@@ -106,7 +106,6 @@ module Safubot
106
106
  Log.error "Unhandled Blather error: #{error_report(e)}"
107
107
  end
108
108
 
109
-
110
109
  @state = :running
111
110
  end
112
111
 
@@ -122,17 +121,22 @@ module Safubot
122
121
  elsif @state == :running
123
122
  Log.error "XMPP client exited unexpectedly: #{error_report(e)}"
124
123
  Log.error "Restarting XMPP client in 5 seconds."
125
- sleep 5; init_blather; run_blather
124
+ EM::Timer.new(5) { init_blather; run_blather }
126
125
  end
127
126
  end
128
127
  end
129
128
 
130
- # Starts our Blather client running in a new process.
129
+ # Starts our Blather client running.
131
130
  def run
131
+ init_blather
132
+ run_blather
133
+ end
134
+
135
+ # Starts our Blather client running in a new process.
136
+ def fork
132
137
  @pid = Process.fork do
133
138
  Signal.trap("TERM") { stop }
134
- init_blather
135
- run_blather
139
+ run
136
140
  end
137
141
  end
138
142
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: safubot
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jaiden Mispy