raibo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/raibo.rb +7 -0
- data/lib/raibo/connection.rb +71 -0
- data/lib/raibo/version.rb +3 -0
- data/raibo.gemspec +21 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/lib/raibo.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
module Raibo
|
2
|
+
class Connection
|
3
|
+
attr_accessor :server, :port, :nick, :channel
|
4
|
+
|
5
|
+
def initialize(server, opts={})
|
6
|
+
@server = server
|
7
|
+
@port = opts[:port] || 6667
|
8
|
+
@nick = opts[:nick] || 'Raibo'
|
9
|
+
@channel = opts[:channel] || '#raibo'
|
10
|
+
@verbose = !!opts[:verbose]
|
11
|
+
end
|
12
|
+
|
13
|
+
def open
|
14
|
+
@connection = TCPSocket.new(@server, @port)
|
15
|
+
send "USER #{@nick} 0 * :Hi"
|
16
|
+
nick @nick
|
17
|
+
|
18
|
+
handle_lines do |line|
|
19
|
+
case line
|
20
|
+
when /:Nickname is already in use./
|
21
|
+
@nick = "#{@nick}_"
|
22
|
+
nick @nick
|
23
|
+
when /001/
|
24
|
+
join @channel
|
25
|
+
break
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def close
|
31
|
+
@connection.close if @connection
|
32
|
+
end
|
33
|
+
|
34
|
+
def handle_lines
|
35
|
+
while (line = @connection.gets)
|
36
|
+
puts "--> #{line}" if @verbose
|
37
|
+
|
38
|
+
if line =~ /^PING (.*)/
|
39
|
+
send "PONG #{$1}"
|
40
|
+
else
|
41
|
+
yield line
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def nick(nick)
|
47
|
+
send "NICK #{nick}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def join(channel)
|
51
|
+
send "JOIN #{channel}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def part(channel)
|
55
|
+
send "PART #{channel}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def say(msg)
|
59
|
+
msg(@channel, msg)
|
60
|
+
end
|
61
|
+
|
62
|
+
def msg(dest, msg)
|
63
|
+
send "PRIVMSG #{dest} :#{msg}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def send(str)
|
67
|
+
puts "<-- #{str}" if @verbose
|
68
|
+
@connection.puts(str)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/raibo.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "raibo/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "raibo"
|
7
|
+
s.version = Raibo::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Ryan Fitzgerald"]
|
10
|
+
s.email = ["rwfitzge@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{A simple IRC library}
|
13
|
+
s.description = %q{}
|
14
|
+
|
15
|
+
s.rubyforge_project = "raibo"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: raibo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ryan Fitzgerald
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-12 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: ""
|
23
|
+
email:
|
24
|
+
- rwfitzge@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- Rakefile
|
35
|
+
- lib/raibo.rb
|
36
|
+
- lib/raibo/connection.rb
|
37
|
+
- lib/raibo/version.rb
|
38
|
+
- raibo.gemspec
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: ""
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: raibo
|
69
|
+
rubygems_version: 1.5.1
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: A simple IRC library
|
73
|
+
test_files: []
|
74
|
+
|