Sha256: e292852c899f28fdd68fee448f436ff004bee2791cf28123c6c2bf756a79ab3b

Contents?: true

Size: 704 Bytes

Versions: 1

Compression:

Stored size: 704 Bytes

Contents

module Hipbot
  module Adapters
    class Telnet
      include Hipbot::Adaptable

      attr_accessor :connection

      def start!
        ::EM::start_server('0.0.0.0', 3001, Connection, self)
      end

      def send_to_user user, message
        connection.send_data("#{self}:#{user}:#{message}\n")
      end

      class Connection < EM::Connection
        include Cache

        def initialize adapter
          adapter.connection = self
        end

        attr_cache :user do
          Hipbot::User.find_or_create_by(name: 'Telnet User')
        end

        def receive_data data
          message = data.strip
          Hipbot.react(user, nil, message)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hipbot-1.0.4 lib/hipbot/adapters/telnet.rb