Class: CarriedPigeon
- Inherits:
-
Object
- Object
- CarriedPigeon
- Defined in:
- lib/collins_notify/adapter/helper/carried-pigeon.rb
Overview
Code is largely ripped off from github.com/portertech/carrier-pigeon which carriers an MIT license. Carrier pigeon offers no ability to detect a 433 response (nickname already in use) and automatically fix it. There’s also not much in the way of debugging. That’s all that is added here.
Instance Attribute Summary collapse
-
#connected ⇒ Object
readonly
Returns the value of attribute connected.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #auth ⇒ Object
- #connect! ⇒ Object
- #die ⇒ Object
-
#initialize(options = {}) ⇒ CarriedPigeon
constructor
A new instance of CarriedPigeon.
- #message(message, notice = false, opts = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CarriedPigeon
Returns a new instance of CarriedPigeon.
29 30 31 32 33 34 35 36 |
# File 'lib/collins_notify/adapter/helper/carried-pigeon.rb', line 29 def initialize(={}) [:host, :port, :nick, :channel, :logger].each do |option| raise "You must provide an IRC #{option}" unless .has_key?(option) end @logger = [:logger] @options = connect! if (.fetch(:connect, true)) # default to connect, same as old behavior end |
Instance Attribute Details
#connected ⇒ Object (readonly)
Returns the value of attribute connected.
28 29 30 |
# File 'lib/collins_notify/adapter/helper/carried-pigeon.rb', line 28 def connected @connected end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
28 29 30 |
# File 'lib/collins_notify/adapter/helper/carried-pigeon.rb', line 28 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
28 29 30 |
# File 'lib/collins_notify/adapter/helper/carried-pigeon.rb', line 28 def @options end |
Class Method Details
.send(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/collins_notify/adapter/helper/carried-pigeon.rb', line 11 def self.send(={}) raise "You must supply a message" unless [:message] if [:uri] then uri = Addressable::URI.parse([:uri]) [:host] = uri.host [:port] = uri.port || 6667 [:nick] = uri.user [:password] = uri.password unless [:channel] then [:channel] = "#" + uri.fragment end end pigeon = CarriedPigeon.new pigeon. [:message], [:notice] pigeon.die end |
Instance Method Details
#auth ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/collins_notify/adapter/helper/carried-pigeon.rb', line 38 def auth # Only auth if not connected and password is specified if connected? or !password then return false end # Must be first according to RFC 2812 sendln "PASS #{password}", :log sendln "USER #{nick} 0 * :#{real_name}", :log true end |
#connect! ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/collins_notify/adapter/helper/carried-pigeon.rb', line 49 def connect! return false if connected? tcp_socket = TCPSocket.new(host, port) if ssl? then 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.sync_close = true @socket.connect else @socket = tcp_socket end if auth? and not auth then die raise "Could not authenticate" end set_nick! @connected = true issue_nickserv_command register end |
#die ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/collins_notify/adapter/helper/carried-pigeon.rb', line 84 def die begin sendln "QUIT :quit", :log socket.gets until socket.eof? rescue Exception => e logger.error "Error quitting IRC - #{e}" ensure socket.close end end |
#message(message, notice = false, opts = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/collins_notify/adapter/helper/carried-pigeon.rb', line 72 def , notice = false, opts = {} command = notice ? "NOTICE" : "PRIVMSG" # Reset join/channel/channel_password options if specified [:join] = opts[:join] if opts.key?(:join) [:channel] = opts[:channel] if opts.key?(:channel) if opts.key?(:channel) then [:channel_password] = opts[:channel_password] end join! sendln "#{command} #{channel} :#{}", :log end |