This repository has been archived by the owner on Dec 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
whois.rb
98 lines (81 loc) · 2.43 KB
/
whois.rb
1
2
3
4
5
6
7
8
9
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
62
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
88
89
90
91
92
93
94
95
96
97
98
module Weechat
module IRC
class Whois
attr_reader :data
def populated?
@populated
end
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
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
def method_missing(m, *args)
if @data.has_key?(m.to_sym)
@data[m.to_sym]
else
super
end
end
end # Whois
end
end