Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Switch over to use the Line-based protocol

  • Loading branch information...
commit 50872a3349ab5cb5a45800e3b16f6268fb06484b 1 parent a0439cb
Tim Carey-Smith authored November 02, 2007

Showing 1 changed file with 16 additions and 12 deletions. Show diff stats Hide diff stats

  1. 28  lib/bot/handler.rb
28  lib/bot/handler.rb
@@ -2,27 +2,31 @@
2 2
 
3 3
 module Bot
4 4
   module Handler
  5
+    include EventMachine::Protocols::LineText2
  6
+
5 7
     def post_init
6 8
       @client = Client.new("testbot", "testbot", "testbot")
7 9
       puts "A connection has started"
8 10
       @client.initial_messages.each do |m|
9  
-        send_data m.to_s
  11
+        send_message(m)
10 12
       end
11 13
     end
12 14
 
13  
-    def receive_data(data)
14  
-      data.split("\r\n").each do |line|
15  
-        operation = proc do
16  
-          @client.dispatch(line)
17  
-        end
18  
-        callback = proc do |responses|
19  
-          responses.each do |response|
20  
-            puts "sending #{response}"
21  
-            send_data response.to_s
22  
-          end
  15
+    def receive_line(line)
  16
+      operation = proc do
  17
+        @client.dispatch(line)
  18
+      end
  19
+      callback = proc do |responses|
  20
+        responses.each do |response|
  21
+          send_message(response)
23 22
         end
24  
-        EventMachine.defer(operation, callback)
25 23
       end
  24
+      EventMachine.defer(operation, callback)
  25
+    end
  26
+
  27
+    def send_message(m)
  28
+      puts "Sending #{m}"
  29
+      send_data m.to_s
26 30
     end
27 31
 
28 32
     def unbind

0 notes on commit 50872a3

Please sign in to comment.
Something went wrong with that request. Please try again.