baseirc 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README.rdoc +59 -0
- data/Rakefile +46 -0
- data/lib/baseirc.rb +328 -0
- metadata +59 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010 spox <spox@modspox.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
== BaseIRC
|
2
|
+
|
3
|
+
BaseIRC is a very simple library for talking to an IRC server. The only thing
|
4
|
+
this library provides is the outgoing communication from your application. (If
|
5
|
+
you are looking to handle incoming messages take a look at the MessageFactory
|
6
|
+
library.)
|
7
|
+
|
8
|
+
=== install (easy):
|
9
|
+
|
10
|
+
gem install baseirc
|
11
|
+
|
12
|
+
=== install (less easy)
|
13
|
+
|
14
|
+
git clone http://github.com/spox/baseirc.git
|
15
|
+
cd baseirc
|
16
|
+
gem build *.gemspec
|
17
|
+
gem install ./
|
18
|
+
|
19
|
+
=== install (less easy that's a little easier)
|
20
|
+
|
21
|
+
{rip}[http://hellorip.com/about.html] makes it easy to install directly from a github repository.
|
22
|
+
|
23
|
+
=== Testing
|
24
|
+
|
25
|
+
BaseIRC is currently tested on:
|
26
|
+
|
27
|
+
* Ruby 1.8.6-p383
|
28
|
+
* Ruby 1.8.7-p248
|
29
|
+
* Ruby 1.9.1-p376
|
30
|
+
* JRuby 1.4.0
|
31
|
+
|
32
|
+
== Example
|
33
|
+
|
34
|
+
=== Code:
|
35
|
+
|
36
|
+
require 'baseirc'
|
37
|
+
|
38
|
+
socket = []
|
39
|
+
irc = BaseIRC::IRC.new(socket)
|
40
|
+
irc.privmsg('spox', 'hi')
|
41
|
+
|
42
|
+
p socket
|
43
|
+
|
44
|
+
=== Result:
|
45
|
+
|
46
|
+
["PRIVMSG spox :hi"]
|
47
|
+
|
48
|
+
The BaseIRC::IRC object takes a socket, or socket like, object. The only thing
|
49
|
+
the library requires of this object is that it has << defined.
|
50
|
+
|
51
|
+
== Last remarks
|
52
|
+
|
53
|
+
If you find any bugs, please report them through {github}[http://github.com/spox/baseirc/issues].
|
54
|
+
If you are in need of any help, you can generally find me on DALnet and Freenode.
|
55
|
+
|
56
|
+
== License
|
57
|
+
|
58
|
+
BaseIRC is licensed under the MIT License
|
59
|
+
Copyright (c) 2009 spox <spox@modspox.com>
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/clean'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/testtask'
|
9
|
+
require 'spec/rake/spectask'
|
10
|
+
|
11
|
+
spec = Gem::Specification.new do |s|
|
12
|
+
s.name = 'baseirc'
|
13
|
+
s.version = '1.0'
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.extra_rdoc_files = ['README.rdoc', 'LICENSE']
|
16
|
+
s.summary = 'Library for sending to an IRC server'
|
17
|
+
s.description = s.summary
|
18
|
+
s.author = 'spox'
|
19
|
+
s.email = 'spox@modspox.com'
|
20
|
+
s.files = %w(LICENSE README.rdoc Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
|
21
|
+
s.require_path = "lib"
|
22
|
+
end
|
23
|
+
|
24
|
+
Rake::GemPackageTask.new(spec) do |p|
|
25
|
+
p.gem_spec = spec
|
26
|
+
p.need_tar = true
|
27
|
+
p.need_zip = true
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
files =['README.rdoc', 'LICENSE', 'lib/**/*.rb']
|
32
|
+
rdoc.rdoc_files.add(files)
|
33
|
+
rdoc.main = "README.rdoc" # page to start on
|
34
|
+
rdoc.title = "BaseIRC Docs"
|
35
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
36
|
+
rdoc.options << '--line-numbers'
|
37
|
+
end
|
38
|
+
|
39
|
+
Rake::TestTask.new do |t|
|
40
|
+
t.test_files = FileList['test/**/*.rb']
|
41
|
+
end
|
42
|
+
|
43
|
+
Spec::Rake::SpecTask.new do |t|
|
44
|
+
t.spec_files = FileList['spec/**/*.rb']
|
45
|
+
t.libs << Dir["lib"]
|
46
|
+
end
|
data/lib/baseirc.rb
ADDED
@@ -0,0 +1,328 @@
|
|
1
|
+
# BaseIRC module
|
2
|
+
module BaseIRC
|
3
|
+
# IRC class for sending communcation to an IRC server
|
4
|
+
class IRC
|
5
|
+
# s:: Socket to send through
|
6
|
+
# Create a new IRC object
|
7
|
+
def initialize(s)
|
8
|
+
@socket = nil
|
9
|
+
self.socket = s
|
10
|
+
end
|
11
|
+
|
12
|
+
# s:: Socket to send through
|
13
|
+
# Set the socket to use
|
14
|
+
def socket=(s)
|
15
|
+
unless(s.respond_to?(:<<))
|
16
|
+
raise ArgumentError.new('Please supply a socket')
|
17
|
+
end
|
18
|
+
@socket = s
|
19
|
+
end
|
20
|
+
|
21
|
+
# Return currently used socket
|
22
|
+
def socket
|
23
|
+
@socket
|
24
|
+
end
|
25
|
+
|
26
|
+
# password:: Password to send
|
27
|
+
# Sends PASS message
|
28
|
+
def pass(password)
|
29
|
+
@socket << "PASS #{password}"
|
30
|
+
end
|
31
|
+
|
32
|
+
# nick:: Nick to send
|
33
|
+
# Sends NICK message
|
34
|
+
def nick(nick)
|
35
|
+
@socket << "NICK #{nick}"
|
36
|
+
end
|
37
|
+
|
38
|
+
# u:: Username
|
39
|
+
# m:: Mode
|
40
|
+
# r: Real name
|
41
|
+
# Sends USER message
|
42
|
+
def user(u, m, r)
|
43
|
+
@socket << "USER #{u} #{m} * :#{r}"
|
44
|
+
end
|
45
|
+
|
46
|
+
# n:: Name
|
47
|
+
# p:: Password
|
48
|
+
# Sends OPER message
|
49
|
+
def oper(n, p)
|
50
|
+
@socket << "OPER #{n} #{p}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def mode(t, m, c=nil)
|
54
|
+
if(c)
|
55
|
+
@socket << "MODE #{c} #{m} #{t}"
|
56
|
+
else
|
57
|
+
@socket << "MODE #{t} #{m}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# message:: Quit message
|
62
|
+
# Sends QUIT message
|
63
|
+
def quit(message)
|
64
|
+
@socket << "QUIT :#{message}"
|
65
|
+
end
|
66
|
+
|
67
|
+
# s:: Server
|
68
|
+
# c:: Comment
|
69
|
+
# Sends SQUIT message
|
70
|
+
def squit(s, c)
|
71
|
+
@socket << "SQUIT #{s} :#{c}"
|
72
|
+
end
|
73
|
+
|
74
|
+
# c:: Channel
|
75
|
+
# k:: Key
|
76
|
+
# Sends JOIN message
|
77
|
+
def join(c, k=nil)
|
78
|
+
@socket << "JOIN #{c} #{k}".strip
|
79
|
+
end
|
80
|
+
|
81
|
+
# c:: Channel
|
82
|
+
# r:: Reason
|
83
|
+
# Sends PART message
|
84
|
+
def part(c, r='')
|
85
|
+
@socket << "PART #{c} :#{r}"
|
86
|
+
end
|
87
|
+
|
88
|
+
# c:: Channel
|
89
|
+
# t:: topic
|
90
|
+
# Sends TOPIC message
|
91
|
+
def topic(c, t)
|
92
|
+
@socket << "TOPIC #{c} :#{t}"
|
93
|
+
end
|
94
|
+
|
95
|
+
# c:: Channel
|
96
|
+
# t:: Target server
|
97
|
+
# Sends NAMES message
|
98
|
+
def names(c, t=nil)
|
99
|
+
@socket << "NAMES #{c} #{t}".strip
|
100
|
+
end
|
101
|
+
|
102
|
+
# c:: Channel
|
103
|
+
# Sends LIST message
|
104
|
+
def list(c=nil)
|
105
|
+
@socket << "LIST #{c}".strip
|
106
|
+
end
|
107
|
+
|
108
|
+
# n:: Nick
|
109
|
+
# c:: Channel
|
110
|
+
# Sends INVITE message
|
111
|
+
def invite(n, c)
|
112
|
+
@socket << "INVITE #{n} #{c}"
|
113
|
+
end
|
114
|
+
|
115
|
+
# n:: Nick
|
116
|
+
# c:: Channel
|
117
|
+
# r:: Reason
|
118
|
+
# Sends KICK message
|
119
|
+
def kick(n, c, r)
|
120
|
+
@socket << "KICK #{c} #{n} :#{r}"
|
121
|
+
end
|
122
|
+
|
123
|
+
# t:: Target
|
124
|
+
# m:: Message
|
125
|
+
# Sends PRIVMSG message
|
126
|
+
|
127
|
+
def privmsg(t, m)
|
128
|
+
@socket << "PRIVMSG #{t} :#{m}"
|
129
|
+
end
|
130
|
+
|
131
|
+
# t:: Target
|
132
|
+
# m:: Message
|
133
|
+
# Sends NOTICE message
|
134
|
+
def notice(t, m)
|
135
|
+
@socket << "NOTICE #{t} :#{m}"
|
136
|
+
end
|
137
|
+
|
138
|
+
# t:: Target
|
139
|
+
# Sends MOTD message
|
140
|
+
def motd(t)
|
141
|
+
@socket << "MOTD #{t}"
|
142
|
+
end
|
143
|
+
|
144
|
+
# m:: Mask
|
145
|
+
# t:: Target
|
146
|
+
# Sends LUSERS message
|
147
|
+
def lusers(m, t)
|
148
|
+
@socket << "LUSERS #{m} #{t}"
|
149
|
+
end
|
150
|
+
|
151
|
+
# t:: Target
|
152
|
+
# Sends VERSION message
|
153
|
+
def version(t)
|
154
|
+
@socket << "VERSION #{t}"
|
155
|
+
end
|
156
|
+
|
157
|
+
# q:: Query (single character within set a-z)
|
158
|
+
# t:: Target
|
159
|
+
# Sends STATS message
|
160
|
+
def stats(q, t)
|
161
|
+
unless(q =~ /^[a-z]$/)
|
162
|
+
raise ArgumentError.new('Query must be a single character')
|
163
|
+
end
|
164
|
+
@socket << "STATS #{q} #{t}"
|
165
|
+
end
|
166
|
+
|
167
|
+
# s:: Server
|
168
|
+
# m:: Mask
|
169
|
+
# Sends LINKS message
|
170
|
+
def links(s, m)
|
171
|
+
@socket << "LIST #{s} #{m}"
|
172
|
+
end
|
173
|
+
|
174
|
+
# t:: Target
|
175
|
+
# Sends TIME message
|
176
|
+
def time(t)
|
177
|
+
@socket << "TIME #{t}"
|
178
|
+
end
|
179
|
+
|
180
|
+
# t:: Target server
|
181
|
+
# p:: Port
|
182
|
+
# r:: Remove server
|
183
|
+
# Sends CONNECT message
|
184
|
+
def connect(t, p, r)
|
185
|
+
@socket << "CONNECT #{t} #{p} #{r}"
|
186
|
+
end
|
187
|
+
|
188
|
+
# t:: Target
|
189
|
+
# Sends TRACE message
|
190
|
+
def trace(t)
|
191
|
+
@socket << "TRACE #{t}"
|
192
|
+
end
|
193
|
+
|
194
|
+
# t:: Target
|
195
|
+
# Sends ADMIN message
|
196
|
+
def admin(t)
|
197
|
+
@socket << "ADMIN #{t}"
|
198
|
+
end
|
199
|
+
|
200
|
+
# t:: Target
|
201
|
+
# Sends INFO message
|
202
|
+
def info(t)
|
203
|
+
@socket << "INFO #{t}"
|
204
|
+
end
|
205
|
+
|
206
|
+
# m:: Mask
|
207
|
+
# t:: Type
|
208
|
+
# Sends SERVLIST message
|
209
|
+
def servlist(m, t)
|
210
|
+
@socket << "SERVLIST #{m} #{t}"
|
211
|
+
end
|
212
|
+
|
213
|
+
# s:: Service name
|
214
|
+
# m:: Message
|
215
|
+
# Sends SQUERY message
|
216
|
+
def squery(s, m)
|
217
|
+
@socket << "SQUERY #{s} #{m}"
|
218
|
+
end
|
219
|
+
|
220
|
+
# m:: Mask
|
221
|
+
# o:: Ops only
|
222
|
+
# Sends WHO message
|
223
|
+
def who(m, o=false)
|
224
|
+
o = o ? 'o' : ''
|
225
|
+
@socket << "WHO #{m} #{o}".strip
|
226
|
+
end
|
227
|
+
|
228
|
+
# n:: Nick
|
229
|
+
# s:: Server
|
230
|
+
# Sends WHOIS message
|
231
|
+
# Sends WHOIS message to server
|
232
|
+
def whois(n, s=nil)
|
233
|
+
@socket << "WHOIS #{[s,n].compact.join(' ')}"
|
234
|
+
end
|
235
|
+
|
236
|
+
# n:: Nick
|
237
|
+
# c:: Count
|
238
|
+
# t:: Target
|
239
|
+
# Sends WHOWAS message
|
240
|
+
def whowas(n, c=nil, t=nil)
|
241
|
+
@socket << "WHOWAS #{[n,c,t].compact.join(' ')}"
|
242
|
+
end
|
243
|
+
|
244
|
+
# n:: Nick
|
245
|
+
# c:: Comment
|
246
|
+
# Sends KILL message
|
247
|
+
def kill(n, c)
|
248
|
+
@socket << "KILL #{n} :#{c}"
|
249
|
+
end
|
250
|
+
|
251
|
+
# m:: Message
|
252
|
+
# Sends PING message
|
253
|
+
def ping(m=nil)
|
254
|
+
@socket << "PING #{m}".strip
|
255
|
+
end
|
256
|
+
|
257
|
+
# s:: Server
|
258
|
+
# m:: Message
|
259
|
+
# Sends PONG message
|
260
|
+
def pong(s, m)
|
261
|
+
@socket << "PONG #{s} #{m}"
|
262
|
+
end
|
263
|
+
|
264
|
+
# m:: Message
|
265
|
+
# Sends AWAY message to mark as away
|
266
|
+
def away(m=nil)
|
267
|
+
@socket << "AWAY :#{m}"
|
268
|
+
end
|
269
|
+
|
270
|
+
# Sends AWAY message to mark as unaway
|
271
|
+
def unaway
|
272
|
+
@socket << "AWAY"
|
273
|
+
end
|
274
|
+
|
275
|
+
# Sends REHASH message
|
276
|
+
def rehash
|
277
|
+
@socket << "REHASH"
|
278
|
+
end
|
279
|
+
|
280
|
+
# Sends DIE message
|
281
|
+
def die
|
282
|
+
@socket << "DIE"
|
283
|
+
end
|
284
|
+
|
285
|
+
# Sends RESTART message
|
286
|
+
def restart
|
287
|
+
@socket << "RESTART"
|
288
|
+
end
|
289
|
+
|
290
|
+
# n:: Nick
|
291
|
+
# t:: Target
|
292
|
+
# c:: Channel
|
293
|
+
# Sends SUMMON message
|
294
|
+
def summon(n, t, c)
|
295
|
+
@socket << "SUMMON #{n} #{t} #{c}"
|
296
|
+
end
|
297
|
+
|
298
|
+
# t:: Target
|
299
|
+
# Sends USERS message
|
300
|
+
def users(t)
|
301
|
+
@socket << "USERS #{t}"
|
302
|
+
end
|
303
|
+
|
304
|
+
# m:: Message
|
305
|
+
# Sends WALLOPS message
|
306
|
+
def wallops(m)
|
307
|
+
@socket << "WALLOPS :#{m}"
|
308
|
+
end
|
309
|
+
|
310
|
+
# n:: Nick
|
311
|
+
# Sends USERHOST message to server
|
312
|
+
def userhost(n)
|
313
|
+
@socket << "USERHOST #{n}"
|
314
|
+
end
|
315
|
+
|
316
|
+
# n:: Nick
|
317
|
+
# Sends ISON message to server
|
318
|
+
def ison(n)
|
319
|
+
@socket << "ISON #{n}"
|
320
|
+
end
|
321
|
+
|
322
|
+
# m:: Raw string
|
323
|
+
# Send raw message
|
324
|
+
def raw(m)
|
325
|
+
@socket << m
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: baseirc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1.0"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- spox
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-18 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Library for sending to an IRC server
|
17
|
+
email: spox@modspox.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- LICENSE
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- lib/baseirc.rb
|
30
|
+
has_rdoc: true
|
31
|
+
homepage:
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.3.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: Library for sending to an IRC server
|
58
|
+
test_files: []
|
59
|
+
|