rhuidean 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/README.markdown +63 -0
  2. data/lib/rhuidean/client.rb +87 -34
  3. data/rakefile +5 -3
  4. metadata +6 -6
  5. data/README +0 -17
data/README.markdown ADDED
@@ -0,0 +1,63 @@
1
+ rhuidean -- a small, lightweight IRC client library
2
+ ===================================================
3
+
4
+ This program is free but copyrighted software; see the LICENSE file.
5
+
6
+ Information and repositories can be found on [GitHub][].
7
+
8
+ [github]: http://github.com/rakaur/rhuidean/
9
+
10
+ TABLE OF CONTENTS
11
+ -----------------
12
+ 1. Credits
13
+ 2. Installation
14
+ 3. Contact and support
15
+
16
+ 1. CREDITS
17
+ ----------
18
+
19
+ Rhuidean is not based on any other code. I wrote the majority of it in a
20
+ single day as a way to try out a Ruby-based event system and as an exercise
21
+ writing in The Ruby Way. As such, rhuidean's code is very clean and concise,
22
+ and it also offers clever ways of accomplishing basic and advanced tasks.
23
+
24
+ The current active development/maintenance is done by:
25
+
26
+ - rakaur, Eric Will <rakaur@malkier.net>
27
+ - sycobuny, Stephen Belcher <sycobuny@malkier.net>
28
+
29
+ Almost all of the testing was also done by us. I (rakaur) wrote all of the base
30
+ code, and sycobuny has expanded on it with more in-depth classes.
31
+
32
+ 2. INSTALLATION
33
+ ---------------
34
+
35
+ This should be as simple as:
36
+
37
+ $ gem install rhuidean
38
+
39
+ If you're installing from the development repository, you may build a gem
40
+ based on the current code and install it by doing:
41
+
42
+ $ rake gem
43
+ $ gem install pkg/rhuidean-*.gem
44
+
45
+ There's just not much else to it.
46
+
47
+ 3. CONTACT AND SUPPORT
48
+ ----------------------
49
+
50
+ For bug or feature reports, please use GitHub's [issue tracking][1].
51
+
52
+ [1]: http://github.com/rakaur/rhuidean/issues/
53
+
54
+ If you're reporting a bug, please include information on how to reproduce the
55
+ problem. If you can't reproduce it there's probably nothing we can do. If the
56
+ library crashed, be sure to include Ruby's backtrace information.
57
+
58
+ If your problem requires extensive debugging in a real-time situation, you
59
+ can usually find us on irc.malkier.net in #malkier.
60
+
61
+ If you've read this far, congratulations. You are among the few elite people
62
+ that actually read documentation. Thank you.
63
+
@@ -14,7 +14,7 @@ module IRC
14
14
  class Client
15
15
  ##
16
16
  # constants
17
- VERSION = '0.2.3'
17
+ VERSION = '0.2.4'
18
18
 
19
19
  ##
20
20
  # instance attributes
@@ -77,9 +77,29 @@ class Client
77
77
  # If we have a block let it set up our instance attributes.
78
78
  yield(self) if block_given?
79
79
 
80
- # Set up event handlers.
80
+ # Core events which are needed to work at all.
81
+ on(:read_ready) { read }
82
+ on(:write_ready) { write }
83
+ on(:recvq_ready) { parse }
84
+
85
+ on(:dead) { self.dead = true }
86
+
87
+ on(:exit) do |from|
88
+ log("exiting via #{from}...")
89
+ Thread.exit
90
+ end
91
+
92
+ on(:PING) { |m| raw("PONG :#{m.target}") }
93
+
94
+ # Set up event handlers. These track some state and such, and can
95
+ # be overridden for other functionality in any child classes.
81
96
  set_default_handlers
82
97
 
98
+ # Special method for default CTCP replies
99
+ # I use this so they don't get wiped out when someone overrides
100
+ # the default handlers, but also so that they CAN be wiped out.
101
+ set_ctcp_handlers
102
+
83
103
  self
84
104
  end
85
105
 
@@ -93,49 +113,45 @@ class Client
93
113
  # returns:: +self+
94
114
  #
95
115
  def set_default_handlers
96
- on(:read_ready) { read }
97
- on(:write_ready) { write }
98
- on(:recvq_ready) { parse }
99
- on(:dead) { self.dead = true }
100
-
101
116
  # Consider ourselves connected on 001
102
117
  on(Numeric::RPL_WELCOME) { log("connected to #@server:#@port") }
103
118
 
104
- # Keep alive...
105
- on(:PING) { |m| raw("PONG :#{m.target}") }
106
-
107
119
  # Track our nickname...
108
- on(:NICK) do |m|
109
- if m.origin =~ /^(#{@nickname})\!(.+)\@(.+)$/
110
- @nickname = m.params[0]
111
- end
112
- end
120
+ on(:NICK) { |m| @nickname = m.target if m.origin_nick == @nickname }
113
121
 
114
122
  # Track channels
115
- on(:JOIN) do |m|
116
- @channels << m.target if m.origin =~ /^(#{@nickname})\!(.+)\@(.+)$/
117
- end
123
+ on(:JOIN) { |m| @channels << m.target if m.origin_nick == @nickname }
118
124
 
119
- # Track channels
120
125
  on(:PART) do |m|
121
- if m.origin =~ /^(#{@nickname})\!(.+)\@(.+)$/
122
- @channels.delete(m.target)
123
- end
126
+ @channels.delete(m.target) if m.origin_nick == @nickname
124
127
  end
125
128
 
126
- # Track channels
127
- on(:KICK) do |m|
128
- @channels.delete(m.target) if m.params[0] == @nickname
129
- end
130
-
131
- on(:exit) do |from|
132
- log("exiting via #{from}...")
133
- Thread.exit
134
- end
129
+ on(:KICK) { |m| @channels.delete(m.target) if m.params[0] == @nickname }
135
130
 
136
131
  self
137
132
  end
138
133
 
134
+ #
135
+ # Sets up some default CTCP replies.
136
+ # ---
137
+ # returns:: +self+
138
+ #
139
+ def set_ctcp_handlers
140
+ on(:PRIVMSG) do |m|
141
+ case m.ctcp
142
+ when :ping
143
+ notice(m.origin_nick, "\1PING #{m.params.join(' ')}\1")
144
+ when :version
145
+ v_str = "rhuidean-#{VERSION}"
146
+ notice(m.origin_nick, "\1VERSION #{v_str}\1")
147
+ when :clientinfo
148
+ notice(m.origin_nick, "\1CLIENTINFO 114 97 107 97 117 114\1")
149
+ else
150
+ next
151
+ end
152
+ end
153
+ end
154
+
139
155
  #
140
156
  # Verifies all required attributes are set.
141
157
  # ---
@@ -294,6 +310,7 @@ class Client
294
310
  # Registers Event handlers with our EventQueue.
295
311
  # ---
296
312
  # <tt>c.on(:PRIVMSG) do |m|
313
+ # next if m.params.empty?
297
314
  # if m.params =~ /\.die/ and m.origin == my_master
298
315
  # c.quit(params)
299
316
  # c.exit
@@ -440,17 +457,53 @@ end
440
457
 
441
458
  # A simple data-holding class.
442
459
  class Message
460
+ ##
461
+ # constants
462
+ ORIGIN_RE = /^(.+)\!(.+)\@(.+)$/
463
+
443
464
  ##
444
465
  # instance attributes
445
- attr_reader :client, :raw, :origin, :target, :params
466
+ attr_reader :client, :ctcp, :origin, :params, :raw, :target
467
+ attr_reader :origin_nick
446
468
 
447
469
  #
448
470
  # Creates a new Message. We use these to represent the old
449
471
  # style of (char *origin, char *target, char *parv[]) in C.
450
472
  #
451
473
  def initialize(client, raw, origin, target, params)
452
- @client, @raw, @origin = client, raw, origin
453
- @target, @params = target, params
474
+ @client, @ctcp, @origin = client, nil, origin
475
+ @params, @raw, @target = params, raw, target
476
+
477
+ # Is the origin a user? Let's make this a little more simple...
478
+ if m = ORIGIN_RE.match(@origin)
479
+ @origin_nick = m[1]
480
+ end
481
+
482
+ # Reformat it a bit if it's a CTCP.
483
+ if @params and not @params.empty? and @params[0][0] == "\1"
484
+ @params[-1].chop!
485
+ @ctcp = @params.shift[1 .. -1].downcase.to_sym
486
+ end
487
+ end
488
+
489
+ ######
490
+ public
491
+ ######
492
+
493
+ def to_channel?
494
+ %w(# & !).include?(@target[0])
495
+ end
496
+
497
+ def is_ctcp?
498
+ @ctcp
499
+ end
500
+
501
+ def is_action?
502
+ @ctcp == :action
503
+ end
504
+
505
+ def is_dcc?
506
+ @ctcp == :dcc
454
507
  end
455
508
  end
456
509
 
data/rakefile CHANGED
@@ -10,6 +10,8 @@
10
10
  require 'rake/' + m
11
11
  end
12
12
 
13
+ VER = '0.2.4'
14
+
13
15
  #
14
16
  # Default task - unit tests.
15
17
  #
@@ -38,13 +40,13 @@ end
38
40
  #
39
41
  # $ rake package
40
42
  #
41
- PKG_FILES = FileList['README', 'rakefile',
43
+ PKG_FILES = FileList['README.markdown', 'rakefile',
42
44
  'lib/rhuidean.rb', 'lib/rhuidean/**/*.rb',
43
45
  'test/*.rb']
44
46
 
45
47
  Rake::PackageTask.new('package') do |p|
46
48
  p.name = 'rhuidean'
47
- p.version = '0.2.3'
49
+ p.version = VER
48
50
  p.need_tar = false
49
51
  p.need_zip = false
50
52
  p.package_files = PKG_FILES
@@ -52,7 +54,7 @@ end
52
54
 
53
55
  spec = Gem::Specification.new do |s|
54
56
  s.name = 'rhuidean'
55
- s.version = '0.2.3'
57
+ s.version = VER
56
58
  s.author = 'Eric Will'
57
59
  s.email = 'rakaur@malkier.net'
58
60
  s.homepage = 'http://github.com/rakaur/rhuidean/'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhuidean
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eric Will
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-20 00:00:00 -04:00
18
+ date: 2010-09-24 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -28,11 +28,11 @@ extensions: []
28
28
  extra_rdoc_files: []
29
29
 
30
30
  files:
31
- - README
31
+ - README.markdown
32
32
  - rakefile
33
33
  - lib/rhuidean.rb
34
- - lib/rhuidean/event.rb
35
34
  - lib/rhuidean/client.rb
35
+ - lib/rhuidean/event.rb
36
36
  - lib/rhuidean/methods.rb
37
37
  - lib/rhuidean/numeric.rb
38
38
  - lib/rhuidean/timer.rb
data/README DELETED
@@ -1,17 +0,0 @@
1
- #
2
- # rhuidean: a small, lightweight IRC client library
3
- # README: at-a-glance documentation
4
- #
5
- # Copyright (c) 2004-2009 Eric Will <rakaur@malkier.net>
6
- # Copyright (c) 2003-2004 shrike development team
7
- #
8
-
9
- This repository contains a simple, quick IRC client library. If you have a
10
- decent understanding of IRC and want to control most of the IRC events
11
- yourself this is very easy and quick to pick up. The library handles all of
12
- the socket code and sets up a simple event handling system for IRC events.
13
-
14
- It's not very well documented yet, but I'm still working on it.
15
-
16
- The code itself is documented. Run `rake rdoc` and check out the doc/ directory.
17
-