Class: Weechat::IRC::Whois

Inherits:
Object
  • Object
show all
Defined in:
lib/weechat/irc/whois.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Whois) initialize(user, &block)



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/weechat/irc/whois.rb', line 63

def initialize(user, &block)
  @data = {
    :nick        => "",
    :user        => "",
    :host        => "",
    :real_name   => "",
    :operator    => false,
    :idle        => 0,
    :away_reason => "",
    :channels    => [],
  }
  @hooks = []
  @populated = false
  @block = block #async callback
  @user = user

  # DONE: 301, 311, 313, 317, 318, 319, 401
  # CONSIDERED: 312
  # TODO: 307, 310, 320, 338, 330, 378, 379, 671
  [301,307,310,311,312,313,317,318,319,320,338,330,378,379,401,671].each do |numeric|
    @hooks << Weechat::Modifier.new("irc_in_#{numeric}") {|modifier, line| process_reply(line) }
  end

  user.server.exec("/whois #{user.name}")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(m, *args)



89
90
91
92
93
94
95
# File 'lib/weechat/irc/whois.rb', line 89

def method_missing(m, *args)
  if @data.has_key?(m.to_sym)
    @data[m.to_sym]
  else
    super
  end
end

Instance Attribute Details

- (Object) data (readonly)

Returns the value of attribute data



4
5
6
# File 'lib/weechat/irc/whois.rb', line 4

def data
  @data
end

Instance Method Details

- (Boolean) populated?



6
7
8
# File 'lib/weechat/irc/whois.rb', line 6

def populated?
  @populated
end

- (Object) process_reply(line)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
# File 'lib/weechat/irc/whois.rb', line 10

def process_reply(line)
  ret = line
  m = Weechat::IRC::Message.new(line.message)
  m.params.shift

  nick = m.params.first
  if nick == @user.name
    ret = nil

    case m.command
    when "401", "318" # ERR_NOSUCHNICK, RPL_ENDOFWHOIS
      # NOTE: 401 (no such nick) may not result in a 318
      @hooks.each do |hook|
        hook.unhook
      end
      @hooks = []
      @populated = true

      if @block
        @block.call(self)
      end

    when "311" # RPL_WHOISUSER
      @data[:nick] = m.params[0]
      @data[:user] = m.params[1]
      @data[:host] = m.params[2]
      @data[:real_name] = m.params[4]

    when "312" # RPL_WHOISSERVER

    when "313" # RPL_WHOISOPERATOR
      @data[:operator] = true

    when "317" # RPL_WHOISIDLE
      @data[:idle] = m.params.first.to_i

    when "301" # RPL_AWAY
      @data[:away_reason] = m.params.last

    when "319" # RPL_WHOISCHANNELS
      m.params[1].split(" ").each do |channel|
        if channel !~ /^([&#!.~]|\+{2}).+$/
          channel[0..0] = ""
        end

        @data[:channels] << Weechat::IRC::Channel.new(@user.server, channel)
      end
    end
  end

  ret
end