Ruby-IRC 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/lib/IRC.rb CHANGED
@@ -122,7 +122,11 @@ class IRC
122
122
 
123
123
  # send CTCP
124
124
  def send_ctcp(to, type, message)
125
- IRCConnection.send_to_server("privmsg #{to} :\001#{type} #{message}");
125
+ IRCConnection.send_to_server("privmsg #{to} :\001#{type} #{message}\001");
126
+ end
127
+
128
+ def send_ctcpreply(to, type, message)
129
+ send_notice(to, "\001#{type} #{message}\001")
126
130
  end
127
131
 
128
132
  # Quits the IRC Server
@@ -74,6 +74,8 @@ class IRC
74
74
  else
75
75
  thread_event(event)
76
76
  end
77
+ # Memory leak patch thanks to Patrick Sinclair
78
+ @threads.delete_if {|thr| thr.stop? }
77
79
  end
78
80
  @threads.each {|thr| thr.join }
79
81
  end
@@ -120,7 +122,11 @@ class IRC
120
122
 
121
123
  # send CTCP
122
124
  def send_ctcp(to, type, message)
123
- IRCConnection.send_to_server("privmsg #{to} :\001#{type} #{message}");
125
+ IRCConnection.send_to_server("privmsg #{to} :\001#{type} #{message}\001");
126
+ end
127
+
128
+ def send_ctcpreply(to, type, message)
129
+ send_notice(to, "\001#{type} #{message}\001")
124
130
  end
125
131
 
126
132
  # Quits the IRC Server
@@ -1,4 +1,5 @@
1
1
 
2
+
2
3
  # Handles connection to IRC Server
3
4
  class IRCConnection
4
5
  @@quit = 0
@@ -39,8 +40,9 @@ class IRCConnection
39
40
 
40
41
  def IRCConnection.create_tcp_socket(server, port)
41
42
  # Now with SSL Support. Thanks to dominiek@digigen.nl for the idea on this.
42
- tcpsocket = TCPsocket.open(server, port)
43
+ tcpsocket = TCPSocket.open(server, port)
43
44
  if @@options[:use_ssl]
45
+ require 'openssl' # Only require OpenSSL if we need to use it.
44
46
  ssl_context = OpenSSL::SSL::SSLContext.new()
45
47
  ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
46
48
  @@socket = OpenSSL::SSL::SSLSocket.new(tcpsocket, ssl_context)
@@ -60,7 +60,6 @@ class IRCConnection
60
60
 
61
61
  # Sends a line of text to the server
62
62
  def IRCConnection.send_to_server(line)
63
- puts "sending line #{line}"
64
63
  @@socket.write(line + "\n")
65
64
  end
66
65
 
@@ -86,10 +85,8 @@ class IRCConnection
86
85
  def IRCConnection.do_one_loop
87
86
  read_sockets = select(@@readsockets, nil, nil, 0.1);
88
87
  if !read_sockets.nil?
89
- puts "STUFF TO READ!"
90
88
  read_sockets[0].each {|sock|
91
89
  if sock.eof? && sock == @@socket
92
- p "Detected Socket Close"
93
90
  remove_IO_socket(sock)
94
91
  sleep 10
95
92
  handle_connection(@server, @port, @nick, @realname)
@@ -25,7 +25,7 @@ class IRCEvent
25
25
  # mess_parts[0] is server info
26
26
  # mess_parts[1] is the message that was sent
27
27
  @message = mess_parts[1]
28
- @stats = mess_parts[0].scan(/[-`\^\{\}\[\]\w.\#\@\+]+/)
28
+ @stats = mess_parts[0].scan(/[-`\^\{\}\[\]\w.\#\@\+=]+/)
29
29
  if @stats[0].match(/^PING/)
30
30
  @event_type = 'ping'
31
31
  elsif @stats[1] && @stats[1].match(/^\d+/)
@@ -34,7 +34,7 @@ class IRCEvent
34
34
  else
35
35
  @event_type = @stats[2].downcase if @stats[2]
36
36
  end
37
-
37
+
38
38
  if @event_type != 'ping'
39
39
  @from = @stats[0]
40
40
  @user = IRCUser.create_user(@from)
metadata CHANGED
@@ -1,51 +1,76 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: Ruby-IRC
5
3
  version: !ruby/object:Gem::Version
6
- version: 1.0.12
7
- date: 2008-06-10 00:00:00 -07:00
8
- summary: An IRC Client library
9
- require_paths:
10
- - lib
11
- email: cboyer@musiciansfriend.com
12
- homepage: http://www.pulpreligion.org
13
- rubyforge_project:
14
- description:
15
- autorequire: IRC
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: "true"
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
25
- version:
4
+ hash: 13
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 13
10
+ version: 1.0.13
26
11
  platform: ruby
27
- signing_key:
28
- cert_chain:
29
- post_install_message:
30
12
  authors:
31
- - Chris Boyer
32
- files:
33
- - lib/eventmap.yml
34
- - lib/IRC.rb
35
- - lib/IRC.rb.~1.10.~
36
- - lib/IRCChannel.rb
37
- - lib/IRCConnection.rb
38
- - lib/IRCConnection.rb.~1.6.~
39
- - lib/IRCEvent.rb
40
- - lib/IRCEvent.rb.~1.10.~
41
- - lib/IRCUser.rb
42
- - lib/IRCUtil.rb
43
- - README
44
- test_files: []
45
- rdoc_options: []
46
- extra_rdoc_files:
47
- - README
13
+ - Chris Boyer
14
+ autorequire: IRC
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-05-28 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: cboyer@musiciansfriend.com
48
24
  executables: []
25
+
49
26
  extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README
30
+ files:
31
+ - lib/eventmap.yml
32
+ - lib/IRC.rb
33
+ - lib/IRC.rb.~1.12.~
34
+ - lib/IRCChannel.rb
35
+ - lib/IRCConnection.rb
36
+ - lib/IRCConnection.rb.~1.7.~
37
+ - lib/IRCEvent.rb
38
+ - lib/IRCUser.rb
39
+ - lib/IRCUtil.rb
40
+ - README
41
+ has_rdoc: true
42
+ homepage: http://www.pulpreligion.org
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
50
68
  requirements: []
51
- dependencies: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.7
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: An IRC Client library
75
+ test_files: []
76
+
@@ -1,94 +0,0 @@
1
- require 'yaml'
2
-
3
- # This is a lookup class for IRC event name mapping
4
- class EventLookup
5
- @@lookup = YAML.load_file("#{File.dirname(__FILE__)}/eventmap.yml")
6
-
7
- # returns the event name, given a number
8
- def EventLookup::find_by_number(num)
9
- return @@lookup[num.to_i]
10
- end
11
- end
12
-
13
-
14
- # Handles an IRC generated event.
15
- # Handlers are for the IRC framework to use
16
- # Callbacks are for users to add.
17
- # Both handlers and callbacks can be called for the same event.
18
- class IRCEvent
19
- @@handlers = { 'ping' => lambda {|event| IRCConnection.send_to_server("PONG #{event.message}") } }
20
- @@callbacks = Hash.new()
21
- attr_reader :hostmask, :message, :event_type, :from, :channel, :target, :mode, :stats
22
- def initialize (line)
23
- line.sub!(/^:/, '')
24
- mess_parts = line.split(':', 2);
25
- # mess_parts[0] is server info
26
- # mess_parts[1] is the message that was sent
27
- @message = mess_parts[1]
28
- @stats = mess_parts[0].scan(/[-`\^\{\}\[\]\w.\#\@\+]+/)
29
- if @stats[0].match(/^PING/)
30
- @event_type = 'ping'
31
- elsif @stats[1] && @stats[1].match(/^\d+/)
32
- @event_type = EventLookup::find_by_number(@stats[1]);
33
- @channel = @stats[3]
34
- else
35
- @event_type = @stats[2].downcase if @stats[2]
36
- end
37
-
38
- if @event_type != 'ping'
39
- @from = @stats[0]
40
- @user = IRCUser.create_user(@from)
41
- end
42
- # FIXME: this list would probably be more accurate to exclude commands than to include them
43
- @hostmask = @stats[1] if %W(topic privmsg join).include? @event_type
44
- @channel = @stats[3] if @stats[3] && !@channel
45
- @target = @stats[5] if @stats[5]
46
- @mode = @stats[4] if @stats[4]
47
- if @mode.nil? && @event_type == 'mode'
48
- # Server modes (like +i) are sent in the 'message' part, and not
49
- # the 'stat' part of the message.
50
- @mode = @message
51
- end
52
-
53
- puts "Line: #{line}"
54
- puts "Breakdown #{@stats.join(",")}"
55
- # Unfortunatly, not all messages are created equal. This is our
56
- # special exceptions section
57
- if @event_type == 'join'
58
- @channel = @message
59
- end
60
-
61
- end
62
-
63
- # Adds a callback for the specified irc message.
64
- def IRCEvent.add_callback(message_id, &callback)
65
- @@callbacks[message_id] = callback
66
- end
67
-
68
- # Adds a handler to the handler function hash.
69
- def IRCEvent.add_handler(message_id, proc=nil, &handler)
70
- if block_given?
71
- @@handlers[message_id] = handler
72
- elsif proc
73
- @@handlers[message_id] = proc
74
- end
75
- end
76
-
77
- # Process this event, preforming which ever handler and callback is specified
78
- # for this event.
79
- def process
80
- handled = nil
81
- if @@handlers[@event_type]
82
- @@handlers[@event_type].call(self)
83
- handled = 1
84
- end
85
- if @@callbacks[@event_type]
86
- @@callbacks[@event_type].call(self)
87
- handled = 1
88
- end
89
- if !handled
90
- # puts "No handler for event type #@event_type in #{self.class}"
91
- end
92
- end
93
- end
94
-