Class: Stalkerr::Session
- Inherits:
-
Net::IRC::Server::Session
- Object
- Net::IRC::Server::Session
- Stalkerr::Session
- Defined in:
- lib/stalkerr/session.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Session
constructor
A new instance of Session.
- #on_disconnected ⇒ Object
- #on_join(m) ⇒ Object
- #on_user(m) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Session
Returns a new instance of Session.
9 10 11 12 13 14 15 16 17 |
# File 'lib/stalkerr/session.rb', line 9 def initialize(*args) super @debug = args.last.debug @channels = {} Dir["#{File.dirname(__FILE__)}/target/*.rb"].each do |path| name = File.basename(path, '.rb') @channels.merge!(name.to_sym => "##{name}") end end |
Instance Method Details
#on_disconnected ⇒ Object
19 20 21 |
# File 'lib/stalkerr/session.rb', line 19 def on_disconnected @retrieve_thread.kill rescue nil end |
#on_join(m) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/stalkerr/session.rb', line 37 def on_join(m) super matched = m.params[1].match(/(.*?):(.*)/) channel = m.params[0] if !@channels.value?(channel) || !matched @log.error "#{channel} not found." end @class_name = "Stalkerr::Target::#{@channels.invert[channel].capitalize}" @username = matched[1] @password = matched[2] post @username, JOIN, channel @retrieve_thread = Thread.start do loop do begin target.stalking do |prefix, command, *params| post(prefix, command, *params) end sleep Stalkerr::Const::FETCH_INTERVAL rescue Exception => e @log.error e.inspect e.backtrace.each { |l| @log.error "\t#{l}" } sleep 10 end end end end |
#on_user(m) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/stalkerr/session.rb', line 23 def on_user(m) super @real, *@opts = @real.split(/\s+/) @opts = OpenStruct.new @opts.inject({}) { |r, i| key, value = i.split("=", 2) r.update key => case value when nil then true when /\A\d+\z/ then value.to_i when /\A(?:\d+\.\d*|\.\d+)\z/ then value.to_f else value end } end |