Sha256: 810caf03a9eed58f783af33489aae1fed71fab60b894207802e3e9d321796409
Contents?: true
Size: 1.09 KB
Versions: 3
Compression:
Stored size: 1.09 KB
Contents
require "addressable/uri" require "socket" require "openssl" class CarrierPigeon def initialize(server, port, nick, password, ssl) tcp_socket = TCPSocket.new(server, port || 6667) if ssl ssl_context = OpenSSL::SSL::SSLContext.new ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE @socket = OpenSSL::SSL::SSLSocket.new(tcp_socket, ssl_context) @socket.sync = true @socket.connect else @socket = tcp_socket end sendln "PASS #{password}" if password sendln "NICK #{nick}" sendln "USER #{nick} 0 * :#{nick}" end def message(channel, message) sendln "PRIVMSG #{channel} :#{message}" end def die @socket.close end def self.send(options={}) raise ArgumentError unless options[:uri] && options[:message] uri = Addressable::URI.parse(options[:uri]) ssl = options[:ssl] || false pidgeon = new(uri.host, uri.port, uri.user, uri.password, ssl) pidgeon.message("#" + uri.fragment, options[:message]) pidgeon.die end private def sendln(cmd) @socket.write("#{cmd}\r\n") STDOUT.flush end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
carrier-pigeon-0.0.3 | lib/carrier-pigeon.rb |
carrier-pigeon-0.0.2 | lib/carrier-pigeon.rb |
carrier-pigeon-0.0.1 | lib/carrier-pigeon.rb |