net-irc 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +17 -6
- data/Rakefile +0 -5
- data/examples/client.rb +0 -0
- data/examples/lig.rb +102 -28
- data/examples/lingr.rb +29 -36
- data/examples/nig.rb +13 -7
- data/examples/sig.rb +186 -0
- data/examples/tig.rb +210 -76
- data/examples/wig.rb +18 -8
- data/lib/net/irc.rb +23 -21
- data/spec/net-irc_spec.rb +0 -0
- metadata +7 -6
data/examples/wig.rb
CHANGED
@@ -22,7 +22,7 @@ Configuration example for Tiarra ( http://coderepos.org/share/wiki/Tiarra ).
|
|
22
22
|
wassr {
|
23
23
|
host: localhost
|
24
24
|
port: 16670
|
25
|
-
name: username@example.com athack
|
25
|
+
name: username@example.com athack jabber=username@example.com:jabberpasswd
|
26
26
|
password: password on Wassr
|
27
27
|
in-encoding: utf8
|
28
28
|
out-encoding: utf8
|
@@ -34,7 +34,7 @@ If `athack` client option specified,
|
|
34
34
|
all nick in join message is leading with @.
|
35
35
|
|
36
36
|
So if you complemente nicks (ex. Irssi),
|
37
|
-
it's good for
|
37
|
+
it's good for Twitter like reply command (@nick).
|
38
38
|
|
39
39
|
In this case, you will see torrent of join messages after connected,
|
40
40
|
because NAMES list can't send @ leading nick (it interpreted op.)
|
@@ -96,6 +96,7 @@ if __FILE__ == $0
|
|
96
96
|
:host => "localhost",
|
97
97
|
:log => nil,
|
98
98
|
:debug => false,
|
99
|
+
:foreground => false,
|
99
100
|
}
|
100
101
|
|
101
102
|
OptionParser.new do |parser|
|
@@ -125,6 +126,15 @@ if __FILE__ == $0
|
|
125
126
|
opts[:debug] = true
|
126
127
|
end
|
127
128
|
|
129
|
+
on("-f", "--foreground", "run foreground") do |foreground|
|
130
|
+
opts[:log] = $stdout
|
131
|
+
opts[:foreground] = true
|
132
|
+
end
|
133
|
+
|
134
|
+
on("-n", "--name [login id]") do |name|
|
135
|
+
opts[:name] = name
|
136
|
+
end
|
137
|
+
|
128
138
|
parse!(ARGV)
|
129
139
|
end
|
130
140
|
end
|
@@ -132,14 +142,14 @@ if __FILE__ == $0
|
|
132
142
|
opts[:logger] = Logger.new(opts[:log], "daily")
|
133
143
|
opts[:logger].level = opts[:debug] ? Logger::DEBUG : Logger::INFO
|
134
144
|
|
135
|
-
def daemonize(
|
136
|
-
|
145
|
+
def daemonize(foreground=false)
|
146
|
+
trap("SIGINT") { exit! 0 }
|
147
|
+
trap("SIGTERM") { exit! 0 }
|
148
|
+
trap("SIGHUP") { exit! 0 }
|
149
|
+
return yield if $DEBUG || foreground
|
137
150
|
Process.fork do
|
138
151
|
Process.setsid
|
139
152
|
Dir.chdir "/"
|
140
|
-
trap("SIGINT") { exit! 0 }
|
141
|
-
trap("SIGTERM") { exit! 0 }
|
142
|
-
trap("SIGHUP") { exit! 0 }
|
143
153
|
File.open("/dev/null") {|f|
|
144
154
|
STDIN.reopen f
|
145
155
|
STDOUT.reopen f
|
@@ -150,7 +160,7 @@ if __FILE__ == $0
|
|
150
160
|
exit! 0
|
151
161
|
end
|
152
162
|
|
153
|
-
daemonize(opts[:debug]) do
|
163
|
+
daemonize(opts[:debug] || opts[:foreground]) do
|
154
164
|
Net::IRC::Server.new(opts[:host], opts[:port], WassrIrcGateway, opts).start
|
155
165
|
end
|
156
166
|
end
|
data/lib/net/irc.rb
CHANGED
@@ -9,7 +9,7 @@ require "monitor"
|
|
9
9
|
module Net; end
|
10
10
|
|
11
11
|
module Net::IRC
|
12
|
-
VERSION = "0.0.
|
12
|
+
VERSION = "0.0.3"
|
13
13
|
class IRCException < StandardError; end
|
14
14
|
|
15
15
|
module PATTERN # :nodoc:
|
@@ -129,8 +129,8 @@ module Net::IRC
|
|
129
129
|
RPL_YOUREOPER = '381'
|
130
130
|
RPL_REHASHING = '382'
|
131
131
|
RPL_YOURESERVICE = '383'
|
132
|
-
|
133
|
-
|
132
|
+
RPL_TIME = '391'
|
133
|
+
RPL_USERSSTART = '392'
|
134
134
|
RPL_USERS = '393'
|
135
135
|
RPL_ENDOFUSERS = '394'
|
136
136
|
RPL_NOUSERS = '395'
|
@@ -201,7 +201,7 @@ module Net::IRC
|
|
201
201
|
ERR_PASSWDMISMATCH = '464'
|
202
202
|
ERR_YOUREBANNEDCREEP = '465'
|
203
203
|
ERR_YOUWILLBEBANNED = '466'
|
204
|
-
|
204
|
+
ERR_KEYSET = '467'
|
205
205
|
ERR_CHANNELISFULL = '471'
|
206
206
|
ERR_UNKNOWNMODE = '472'
|
207
207
|
ERR_INVITEONLYCHAN = '473'
|
@@ -291,8 +291,7 @@ module Net::IRC
|
|
291
291
|
end
|
292
292
|
|
293
293
|
COMMANDS = Constants.constants.inject({}) {|r,i| # :nodoc:
|
294
|
-
r
|
295
|
-
r
|
294
|
+
r.update(Constants.const_get(i) => i)
|
296
295
|
}
|
297
296
|
|
298
297
|
class Prefix < String
|
@@ -457,9 +456,9 @@ class Net::IRC::Client
|
|
457
456
|
def start
|
458
457
|
@socket = TCPSocket.open(@host, @port)
|
459
458
|
on_connected
|
460
|
-
post PASS,
|
461
|
-
post NICK,
|
462
|
-
post USER,
|
459
|
+
post PASS, @opts.pass if @opts.pass
|
460
|
+
post NICK, @opts.nick
|
461
|
+
post USER, @opts.user, "0", "*", @opts.real
|
463
462
|
while l = @socket.gets
|
464
463
|
begin
|
465
464
|
@log.debug "RECEIVE: #{l.chomp}"
|
@@ -671,8 +670,9 @@ class Net::IRC::Client
|
|
671
670
|
# post PRIVMSG, "#channel", "foobar"
|
672
671
|
def post(command, *params)
|
673
672
|
m = Message.new(nil, command, params.map {|s|
|
674
|
-
s.gsub(/[\r\n]/, " ")
|
673
|
+
s ? s.gsub(/[\r\n]/, " ") : ""
|
675
674
|
})
|
675
|
+
|
676
676
|
@log.debug "SEND: #{m.to_s.chomp}"
|
677
677
|
@socket << m
|
678
678
|
end
|
@@ -769,13 +769,11 @@ class Net::IRC::Server
|
|
769
769
|
@log.debug "RECEIVE: #{l.chomp}"
|
770
770
|
m = Message.parse(l)
|
771
771
|
next if on_message(m) === true
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
send(name, m) if respond_to?(name)
|
778
|
-
end
|
772
|
+
|
773
|
+
name = "on_#{(COMMANDS[m.command.upcase] || m.command).downcase}"
|
774
|
+
send(name, m) if respond_to?(name)
|
775
|
+
|
776
|
+
break if m.command == QUIT
|
779
777
|
rescue Message::InvalidMessage
|
780
778
|
@log.error "MessageParse: " + l.inspect
|
781
779
|
end
|
@@ -806,14 +804,13 @@ class Net::IRC::Server
|
|
806
804
|
@nick = m.params[0]
|
807
805
|
end
|
808
806
|
|
809
|
-
|
810
807
|
# Default USER callback.
|
811
|
-
# Set @user, @real, @host and call
|
808
|
+
# Set @user, @real, @host and call initial_message.
|
812
809
|
def on_user(m)
|
813
810
|
@user, @real = m.params[0], m.params[3]
|
814
811
|
@host = @socket.peeraddr[2]
|
815
812
|
@prefix = Prefix.new("#{@nick}!#{@user}@#{@host}")
|
816
|
-
|
813
|
+
initial_message
|
817
814
|
end
|
818
815
|
|
819
816
|
# Call when socket connected.
|
@@ -829,6 +826,11 @@ class Net::IRC::Server
|
|
829
826
|
def on_message(m)
|
830
827
|
end
|
831
828
|
|
829
|
+
# Default PING callback. Response PONG.
|
830
|
+
def on_ping(m)
|
831
|
+
post server_name, PONG, m.params[0]
|
832
|
+
end
|
833
|
+
|
832
834
|
# Do nothing.
|
833
835
|
# This is for avoiding error on calling super.
|
834
836
|
# So you can always call super at subclass.
|
@@ -852,7 +854,7 @@ class Net::IRC::Server
|
|
852
854
|
|
853
855
|
# Call when client connected.
|
854
856
|
# Send RPL_WELCOME sequence. If you want to customize, override this method at subclass.
|
855
|
-
def
|
857
|
+
def initial_message
|
856
858
|
post server_name, RPL_WELCOME, @nick, "Welcome to the Internet Relay Network #{@prefix}"
|
857
859
|
post server_name, RPL_YOURHOST, @nick, "Your host is #{server_name}, running version #{server_version}"
|
858
860
|
post server_name, RPL_CREATED, @nick, "This server was created #{Time.now}"
|
data/spec/net-irc_spec.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-irc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cho45
|
@@ -9,7 +9,7 @@ autorequire: ""
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-06-14 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -30,11 +30,12 @@ files:
|
|
30
30
|
- spec/spec.opts
|
31
31
|
- lib/net
|
32
32
|
- lib/net/irc.rb
|
33
|
-
- examples/
|
34
|
-
- examples/
|
33
|
+
- examples/sig.rb
|
34
|
+
- examples/tig.rb
|
35
35
|
- examples/lingr.rb
|
36
|
+
- examples/client.rb
|
36
37
|
- examples/nig.rb
|
37
|
-
- examples/
|
38
|
+
- examples/lig.rb
|
38
39
|
- examples/wig.rb
|
39
40
|
has_rdoc: true
|
40
41
|
homepage: http://lowreal.rubyforge.org
|
@@ -69,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
70
|
requirements: []
|
70
71
|
|
71
72
|
rubyforge_project: lowreal
|
72
|
-
rubygems_version: 1.
|
73
|
+
rubygems_version: 1.1.1
|
73
74
|
signing_key:
|
74
75
|
specification_version: 2
|
75
76
|
summary: ""
|