-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy_client.rb
98 lines (91 loc) · 2.51 KB
/
proxy_client.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
class ProxyClient < IRCClient
def initialize(nick, actor, serv)
carp "Initializing service #{nick}"
@nick = nick
super(nil,serv)
@conn = IrcClient::ProxyConnector.new(nick,'pass',self,actor)
end
def peer
return @nick
end
def handle_connect
@conn.connect
end
def getnick(user)
if user =~ /^:([^!]+)!.*/
return $1
else
return user
end
end
def reply(method, *args)
puts "reply: #{method}, args: #{args}"
case method
when :raw
arg = *args
@conn.invoke :unknown, arg
when :ping
host = *args
@conn.invoke :ping, host
when :pong
msg = *args
@conn.invoke :pong, msg
when :join
user,channel = args
@conn.invoke :join, getnick(user), channel
when :privmsg
user, channel, msg = args
@conn.invoke :privmsg, getnick(user), channel, msg
when :notice
user, channel, msg = args
@conn.invoke :notice, getnick(user), channel, msg
when :topic
user, channel, msg = args
@conn.invoke :topic, getnick(user), channel, msg
when :nick
nick = *args
@conn.invoke :nick, nick
when :mode
nick, rest = args
@conn.invoke :mode, nick, rest
when :numeric
numeric,msg,detail = args
server = $config['hostname']
@conn.invoke :numeric, server, numeric, msg, detail
end
end
#From the local services
def invoke(method, *args)
case method
when :pong
server = *args
handle_pong server
when :pass
pass = *args
handle_pass pass
when :nick
nick = *args
handle_nick nick
when :user
user, mode, vhost, realname = args
handle_user user, mode, vhost, realname
when :names
channel, serv = *args
handle_names channel, serv
when :join
channel = *args
handle_join channel
when :part
channel, msg = args
handle_part channel, msg
when :quit
msg = args
handle_quit msg
when :privmsg
channel, msg = args
handle_privmsg channel, msg
else
handle_unknown "#{method} #{args.join(',')}"
end
end
end