sbfaulkner-net-irc 0.9.1 → 0.9.2

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.
data/README.markdown CHANGED
@@ -14,7 +14,10 @@ Install the gem(s):
14
14
 
15
15
  ## Example
16
16
 
17
- See the examples folder for how to use.
17
+ The gem installs the nicl command-line client (pronounced "nickle", as in worth
18
+ about a...). This client is strictly intended as a sample usage of and testbed
19
+ for Net::IRC, and is not meant as an example of how to write a command-line
20
+ client.
18
21
 
19
22
  ## Legal
20
23
 
data/bin/nicl ADDED
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # nicl Copyright © 2007-2008 unwwwired.net
4
+ # Created by: S. Brent Faulkner (brentf@unwwwired.net) 2007-08-29
5
+ #
6
+
7
+ require 'rubygems'
8
+ require 'net/irc'
9
+
10
+ module Ansi
11
+ RESET = 0
12
+ BOLD = 1
13
+ DIM = 2
14
+ UNDERSCORE = 4
15
+ BLINK = 5
16
+ REVERSE = 7
17
+ HIDDEN = 8
18
+
19
+ BLACK = 0
20
+ RED = 1
21
+ GREEN = 2
22
+ YELLOW = 3
23
+ BLUE = 4
24
+ MAGENTA = 5
25
+ CYAN = 6
26
+ WHITE = 7
27
+
28
+ def esc(*attrs)
29
+ "\033[#{attrs.join(';')}m"
30
+ end
31
+
32
+ def fg(colour)
33
+ 30 + colour
34
+ end
35
+
36
+ def bg(colour)
37
+ 40 + colour
38
+ end
39
+
40
+ def highlight(text, *attrs)
41
+ "#{esc(*attrs)}#{text}#{esc(RESET)}"
42
+ end
43
+ end
44
+
45
+ include Ansi
46
+
47
+ def prompt(text)
48
+ print text
49
+ readline.chomp
50
+ end
51
+
52
+ Net::IRC.logger.level = Logger::DEBUG
53
+ Net::IRC.logger.datetime_format = "%Y/%m/%d %H:%M:%S"
54
+
55
+ Thread.abort_on_exception = true
56
+
57
+ server = ARGV[0] || "irc.freenode.net"
58
+ port = ARGV[1] || 6667
59
+ user = ARGV[2] || prompt('User: ')
60
+ full_name = ARGV[3] || ARGV[2] || prompt('Full name: ')
61
+
62
+ Net::IRC.start user, full_name, server, port do |irc|
63
+ Thread.new do
64
+ irc.each do |message|
65
+ case message
66
+ # TODO: required = VERSION, PING, CLIENTINFO, ACTION
67
+ # TODO: handle internally... probably true for most CTCP requests
68
+ when Net::IRC::CTCPVersion
69
+ irc.ctcp_version(message.source, "net-irc simple-client", Net::IRC::VERSION, PLATFORM, "http://www.github.com/sbfaulkner/net-irc")
70
+
71
+ when Net::IRC::CTCPAction
72
+ puts "#{highlight(message.source, BOLD, fg(YELLOW))} #{highlight(message.target, BOLD, fg(GREEN))}: #{highlight(message.text, BOLD)}"
73
+
74
+ when Net::IRC::CTCPPing
75
+ irc.ctcp_ping(message.source, message.arg)
76
+
77
+ when Net::IRC::CTCPTime
78
+ irc.ctcp_time(message.source)
79
+
80
+ when Net::IRC::CTCP
81
+ puts highlight("Unhandled CTCP REQUEST: #{message.class} (#{message.keyword})", BOLD, fg(RED))
82
+
83
+ when Net::IRC::Join
84
+ puts "#{highlight(message.prefix.nickname, BOLD, fg(YELLOW))} joined #{highlight(message.channels.first, BOLD, fg(GREEN))}."
85
+
86
+ when Net::IRC::Part
87
+ if message.text && ! message.text.empty?
88
+ puts "#{highlight(message.prefix.nickname, BOLD, fg(YELLOW))} has left #{highlight(message.channels.first, BOLD, fg(GREEN))} (#{message.text})."
89
+ else
90
+ puts "#{highlight(message.prefix.nickname, BOLD, fg(YELLOW))} has left #{highlight(message.channels.first, BOLD, fg(GREEN))}."
91
+ end
92
+
93
+ when Net::IRC::Mode
94
+ # TODO: handle internally
95
+ puts highlight("#{message.channel} mode changed #{message.modes}", fg(BLUE))
96
+
97
+ when Net::IRC::Quit
98
+ if message.text && ! message.text.empty?
99
+ puts "#{highlight(message.prefix.nickname, BOLD, fg(YELLOW))} has quit (#{message.text})."
100
+ else
101
+ puts "#{highlight(message.prefix.nickname, BOLD, fg(YELLOW))} has quit."
102
+ end
103
+
104
+ when Net::IRC::Notice
105
+ puts highlight(message.text, fg(CYAN))
106
+
107
+ when Net::IRC::Privmsg
108
+ puts "#{highlight(message.prefix.nickname, BOLD, fg(YELLOW))} #{highlight(message.target, BOLD, fg(GREEN))}: #{highlight(message.text, BOLD)}"
109
+
110
+ when Net::IRC::Nick
111
+ puts "#{highlight(message.prefix.nickname, BOLD)} is now #{highlight(message.nickname, BOLD, fg(YELLOW))}"
112
+
113
+ when Net::IRC::ErrNicknameinuse
114
+ irc.nick message.nickname.sub(/\d*$/) { |n| n.to_i + 1 }
115
+
116
+ when Net::IRC::ErrNeedreggednick
117
+ irc.privmsg('nickserv', 'help')
118
+
119
+ when Net::IRC::Error
120
+ puts highlight("Unhandled ERROR: #{message.class} (#{message.command})", BOLD, fg(RED))
121
+
122
+ when Net::IRC::RplWelcome, Net::IRC::RplYourhost, Net::IRC::RplCreated
123
+ puts message.text
124
+
125
+ when Net::IRC::RplLuserclient, Net::IRC::RplLuserme, Net::IRC::RplLocalusers, Net::IRC::RplGlobalusers, Net::IRC::RplStatsconn
126
+ puts highlight(message.text, fg(BLUE))
127
+
128
+ when Net::IRC::RplLuserop, Net::IRC::RplLuserchannels
129
+ puts highlight("#{message.count} #{message.text}", fg(BLUE))
130
+
131
+ when Net::IRC::RplIsupport
132
+ # TODO: handle internally... parse into capabilities collection
133
+
134
+ when Net::IRC::RplMyinfo
135
+ when Net::IRC::RplMotdstart
136
+
137
+ when Net::IRC::RplTopic
138
+ # TODO: handle internally
139
+ puts "#{highlight(message.channel, BOLD, fg(GREEN))}: #{message.text}"
140
+
141
+ when Net::IRC::RplTopicwhotime
142
+ # TODO: handle internally
143
+ puts "#{highlight(message.channel, BOLD, fg(GREEN))}: #{message.nickname} #{message.time.strftime("%Y/%m/%d %H:%M:%S")}"
144
+
145
+ when Net::IRC::RplNamreply
146
+ # TODO: handle internally
147
+ puts "#{highlight(message.channel, BOLD, fg(GREEN))}: #{message.names.join(', ')}"
148
+
149
+ when Net::IRC::RplEndofnames
150
+ # TODO: handle internally
151
+
152
+ when Net::IRC::RplMotd
153
+ puts message.text.sub(/^- /,'')
154
+
155
+ when Net::IRC::RplEndofmotd
156
+ puts ""
157
+
158
+ when Net::IRC::Reply
159
+ puts highlight("Unhandled REPLY: #{message.class} (#{message.command})", BOLD, fg(RED))
160
+
161
+ when Net::IRC::Message
162
+ puts highlight("Unhandled MESSAGE: #{message.class} (#{message.command})", BOLD, fg(RED))
163
+
164
+ else
165
+ raise IOError, "unknown class #{message.class}"
166
+
167
+ end
168
+ end
169
+ end
170
+
171
+ while line = readline
172
+ scanner = StringScanner.new(line.chomp)
173
+ if command = scanner.scan(/\/([[:alpha:]]+)\s*/) && scanner[1]
174
+ case command.upcase
175
+ when 'JOIN'
176
+ # TODO: validate arguments... support for password... etc.
177
+ irc.join scanner.rest
178
+
179
+ when 'MSG'
180
+ # TODO: validate arguments... support for password... etc.
181
+ scanner.scan(/(.+)\s+(.*)/)
182
+ irc.privmsg(scanner[1], scanner[2])
183
+ when 'PART'
184
+ # TODO: validate arguments... support for password... etc.
185
+ irc.part scanner.rest
186
+
187
+ when 'QUIT'
188
+ break
189
+ else
190
+ puts highlight("Unknown COMMAND: #{command}", BOLD, fg(RED))
191
+ end
192
+ elsif scanner.scan(/(.+)\s+(.*)/)
193
+ irc.privmsg(scanner[1], scanner[2])
194
+ else
195
+ # TODO: error? need a concept of a current room
196
+ end
197
+ end
198
+ end
data/lib/net/irc.rb CHANGED
@@ -23,7 +23,7 @@ module Net
23
23
 
24
24
  PORT_DEFAULT = 6667
25
25
 
26
- VERSION = "0.9.1"
26
+ VERSION = "0.9.2"
27
27
 
28
28
  class CTCP
29
29
  attr_accessor :source, :target, :keyword, :parameters
data/net-irc.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  SPEC = Gem::Specification.new do |s|
2
2
  # identify the gem
3
3
  s.name = "net-irc"
4
- s.version = "0.9.1"
4
+ s.version = "0.9.2"
5
5
  s.author = "S. Brent Faulkner"
6
6
  s.email = "brentf@unwwwired.net"
7
7
  s.homepage = "http://www.unwwwired.net"
@@ -9,12 +9,12 @@ SPEC = Gem::Specification.new do |s|
9
9
  s.platform = Gem::Platform::RUBY
10
10
  # description of gem
11
11
  s.summary = "a ruby implementation of the IRC client protocol"
12
- s.files = %w(examples/test.rb lib/net/irc.rb lib/net/rfc2812.yml MIT-LICENSE Rakefile README.markdown net-irc.gemspec)
12
+ s.files = %w(bin/nicl lib/net/irc.rb lib/net/rfc2812.yml MIT-LICENSE Rakefile README.markdown net-irc.gemspec)
13
13
  s.require_path = "lib"
14
- s.autorequire = "irc"
14
+ s.autorequire = "net/irc"
15
15
  # s.test_file = "test/net-irc.rb"
16
16
  s.has_rdoc = true
17
17
  s.extra_rdoc_files = ["README.markdown"]
18
18
  # s.add_dependency("fastercsv", ">= 1.2.3")
19
- # s.executables = ["rsql"]
19
+ s.executables = ["nicl"]
20
20
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbfaulkner-net-irc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - S. Brent Faulkner
8
- autorequire: irc
8
+ autorequire: net/irc
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
@@ -15,14 +15,14 @@ dependencies: []
15
15
 
16
16
  description:
17
17
  email: brentf@unwwwired.net
18
- executables: []
19
-
18
+ executables:
19
+ - nicl
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
23
  - README.markdown
24
24
  files:
25
- - examples/test.rb
25
+ - bin/nicl
26
26
  - lib/net/irc.rb
27
27
  - lib/net/rfc2812.yml
28
28
  - MIT-LICENSE