cinch 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +120 -0
- data/Rakefile +65 -0
- data/lib/cinch.rb +19 -0
- data/lib/cinch/base.rb +236 -0
- data/lib/cinch/irc.rb +44 -0
- data/lib/cinch/irc/message.rb +121 -0
- data/lib/cinch/irc/parser.rb +125 -0
- data/lib/cinch/irc/socket.rb +291 -0
- data/spec/helper.rb +8 -0
- data/spec/irc/helper.rb +8 -0
- data/spec/irc/message_spec.rb +61 -0
- data/spec/irc/parser_spec.rb +107 -0
- data/spec/irc/socket_spec.rb +90 -0
- data/spec/options_spec.rb +40 -0
- metadata +93 -0
data/spec/helper.rb
ADDED
data/spec/irc/helper.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
describe "IRC::Message" do
|
4
|
+
before do
|
5
|
+
@message = Cinch::IRC::Message.new('rawline', 'prefix', 'COMMAND', ['#chan', 'hello world'])
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#add, #[]=" do
|
9
|
+
it "should add an attribute" do
|
10
|
+
@message.add(:custom, 'something')
|
11
|
+
@message.data.should include :custom
|
12
|
+
@message.data[:custom].should == "something"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#delete" do
|
17
|
+
it "should remove an attribute" do
|
18
|
+
@message.add(:custom, 'something')
|
19
|
+
@message.delete(:custom)
|
20
|
+
@message.data.should_not include :custom
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#to_s" do
|
25
|
+
it "should return the raw IRC message" do
|
26
|
+
@message.to_s.should == @message.raw
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#method_missing" do
|
31
|
+
it "should return an attribute if it exists" do
|
32
|
+
@message.add(:custom, 'something')
|
33
|
+
@message.custom.should == 'something'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return nil if no attribute exists" do
|
37
|
+
@message.foobar.should == nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "default attributes" do
|
42
|
+
it "should contain a prefix" do
|
43
|
+
@message.prefix.should == 'prefix'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should contain a command" do
|
47
|
+
@message.command.should == "COMMAND"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should contain params" do
|
51
|
+
@message.params.should be_kind_of(Array)
|
52
|
+
@message.params.size.should == 2
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should contain a symbolized command" do
|
56
|
+
@message.symbol.should == :command
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
# Common commands
|
4
|
+
commands = {
|
5
|
+
:ping => "PING :foobar",
|
6
|
+
:nick => ":foo!~baz@host.com NICK Baz",
|
7
|
+
:join => ":foo!~bar@host.com JOIN #baz",
|
8
|
+
|
9
|
+
:privmsg => {
|
10
|
+
"to a channel" => ":foo!~bar@host.com PRIVMSG #baz :hello world",
|
11
|
+
"to a user" => ":foo!~bar@host.com PRIVMSG Baz :hello world",
|
12
|
+
"with an action" => ":foo!~bar@host.com PRIVMSG #baz :\001ACTION hello word\001",
|
13
|
+
},
|
14
|
+
|
15
|
+
:notice => {
|
16
|
+
"to a channel" => ":foo!~bar@host.com NOTICE #baz :hello world",
|
17
|
+
"to a user" => ":foo!~bar@host.com NOTICE Baz :hello world",
|
18
|
+
},
|
19
|
+
|
20
|
+
:part => {
|
21
|
+
"without a message" => ":foo!~bar@host.com PART #baz",
|
22
|
+
"with a message" => ":foo!~bar@host.com PART #baz :beer",
|
23
|
+
},
|
24
|
+
|
25
|
+
:quit => {
|
26
|
+
"without a message" => ":foo!~bar@host.com QUIT",
|
27
|
+
"with a message" => ":foo!~bar@host.com QUIT :baz"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
describe "IRC::Parser" do
|
32
|
+
before do
|
33
|
+
@parser = Cinch::IRC::Parser.new
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#add_pattern" do
|
37
|
+
it "should add a pattern" do
|
38
|
+
@parser.add_pattern(:custom, /foo/)
|
39
|
+
@parser.patterns.key?(:custom)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should raise ArgumentError if pattern is not Regexp" do
|
43
|
+
lambda { @parser.add_pattern(:custom, 'foo') }.should raise_error(ArgumentError)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#remove_pattern" do
|
48
|
+
it "should remove a pattern" do
|
49
|
+
@parser.add_pattern(:custom, /foo/)
|
50
|
+
@parser.remove_pattern(:custom)
|
51
|
+
@parser.patterns.keys.should_not include(:custom)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return nil if a pattern doesn't exist" do
|
55
|
+
@parser.remove_pattern(:foo).should be nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#parse_servermessage" do
|
60
|
+
it "should return an IRC::Message" do
|
61
|
+
@parser.parse("foo :bar").should be_kind_of(Cinch::IRC::Message)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should raise if given an invalid message" do
|
65
|
+
lambda { @parser.parse("#") }.should raise_error(ArgumentError)
|
66
|
+
end
|
67
|
+
|
68
|
+
commands.each do |cmd, passes|
|
69
|
+
if passes.is_a?(Hash)
|
70
|
+
passes.each do |extra, pass|
|
71
|
+
it "should parse a #{cmd.to_s.upcase} command #{extra}" do
|
72
|
+
m = @parser.parse(pass)
|
73
|
+
m.symbol.should == cmd
|
74
|
+
end
|
75
|
+
end
|
76
|
+
else
|
77
|
+
it "should parse a #{cmd.to_s.upcase} command" do
|
78
|
+
m = @parser.parse(passes)
|
79
|
+
m.symbol.should == cmd
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#parse_userhost" do
|
87
|
+
it "should return an Array" do
|
88
|
+
@parser.parse_userhost(":foo!bar@baz").should be_kind_of(Array)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return 3 values" do
|
92
|
+
@parser.parse_userhost(":foo!bar@baz").size.should be 3
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#valid_channel?" do
|
97
|
+
it "should return true with a valid channel name" do
|
98
|
+
@parser.valid_channel?("#foo").should be true
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return false with an invalid channel name" do
|
102
|
+
@parser.valid_channel?("foo").should be false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class Cinch::IRC::Socket
|
4
|
+
def write(data)
|
5
|
+
return data
|
6
|
+
end
|
7
|
+
|
8
|
+
def read(chompstr="\r\n")
|
9
|
+
str = "foo bar baz\r\n"
|
10
|
+
str.chomp!(chompstr) if chompstr
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
commands = [
|
15
|
+
[:pass, %w(foobar), "PASS foobar"],
|
16
|
+
[:nick, %(ipsum), "NICK ipsum"],
|
17
|
+
[:user, ["guest", 0, '*', "real name"], "USER guest 0 * :real name"],
|
18
|
+
[:oper, %w(foo bar), "OPER foo bar"],
|
19
|
+
[:mode, %w(#foo +v bar), "MODE #foo +v bar"],
|
20
|
+
[:quit, %w(goodbye), "QUIT :goodbye"],
|
21
|
+
[:join, %w(#mychan), "JOIN #mychan"],
|
22
|
+
[:part, %w(#mychan), "PART #mychan"],
|
23
|
+
[:part, %w(#mychan cya!), "PART #mychan :cya!", "with part message"],
|
24
|
+
[:topic, %w(#mychan newtopic), "TOPIC #mychan :newtopic"],
|
25
|
+
[:names, %w(#foo #bar), "NAMES #foo,#bar"],
|
26
|
+
[:list, %w(#foo #bar), "LIST #foo,#bar"],
|
27
|
+
[:invite, %w(foo #mychan), "INVITE foo #mychan"],
|
28
|
+
[:kick, %w(#chan villian), "KICK #chan villian"],
|
29
|
+
[:kick, %w(#chan villian gtfo!), "KICK #chan villian :gtfo!", "with kick reason"],
|
30
|
+
[:privmsg, ['#chan', 'foo bar baz'], "PRIVMSG #chan :foo bar baz"],
|
31
|
+
[:notice, ['#chan', 'foo bar baz'], "NOTICE #chan :foo bar baz"],
|
32
|
+
[:motd, %w(someserver), "MOTD someserver"],
|
33
|
+
[:version, %w(anotherserver), "VERSION anotherserver"],
|
34
|
+
[:stats, %w(m server), "STATS m server"],
|
35
|
+
[:time, %w(irc.someserver.net), "TIME irc.someserver.net"],
|
36
|
+
[:info, %w(foobar), "INFO foobar"],
|
37
|
+
[:squery, %w(irchelp HELPME), "SQUERY irchelp :HELPME"],
|
38
|
+
[:who, %w(*.com o), "WHO *.com o"],
|
39
|
+
[:whois, %w(foo.org user), "WHOIS foo.org user"],
|
40
|
+
[:whowas, %w(foo.org user), "WHOWAS foo.org user"],
|
41
|
+
[:kill, ['badperson', 'get out!'], "KILL badperson :get out!"],
|
42
|
+
[:ping, %w(010123444), "PING 010123444"],
|
43
|
+
[:pong, %w(irc.foobar.org), "PONG irc.foobar.org"],
|
44
|
+
[:away, [], "AWAY"],
|
45
|
+
[:away, ['gone for lunch'], "AWAY :gone for lunch"],
|
46
|
+
[:users, %w(irc.foobar.org), "USERS irc.foobar.org"],
|
47
|
+
[:userhost, %w(foo bar baz), "USERHOST foo bar baz"],
|
48
|
+
]
|
49
|
+
|
50
|
+
describe "Cinch::IRC::Socket" do
|
51
|
+
before do
|
52
|
+
@irc = Cinch::IRC::Socket.new('irc.myserver.net')
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "::new" do
|
56
|
+
it "should return an Cinch::IRC::Socket" do
|
57
|
+
@irc.class.should == Cinch::IRC::Socket
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should default to port 6667" do
|
61
|
+
@irc.port.should == 6667
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not automatically connect" do
|
65
|
+
@irc.connected.should == false
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should set socket instance as nil" do
|
69
|
+
@irc.socket.should == nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#read" do
|
74
|
+
it "should chomp CRLF by default" do
|
75
|
+
@irc.read.should == "foo bar baz"
|
76
|
+
@irc.read.should_not == "foo bar baz\r\n"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
commands.each do |requirements|
|
81
|
+
meth, params, pass, extra = *requirements
|
82
|
+
describe "##{meth}" do
|
83
|
+
it "should send a #{meth.to_s.upcase} command #{extra if extra}" do
|
84
|
+
@irc.send(meth, *params).should == pass
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
describe "Cinch::Base options" do
|
4
|
+
before do
|
5
|
+
@base = Cinch::Base
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should set options via a hash" do
|
9
|
+
base = @base.new(:server => 'irc.foobar.org')
|
10
|
+
base.options.server.should == "irc.foobar.org"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set options via a block" do
|
14
|
+
base = @base.new do
|
15
|
+
server "irc.foobar.org"
|
16
|
+
end
|
17
|
+
base.options.server.should == "irc.foobar.org"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set options via setters" do
|
21
|
+
base = @base.new
|
22
|
+
base.options.server = "irc.foobar.org"
|
23
|
+
base.options.server.should == "irc.foobar.org"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should set specific default values" do
|
27
|
+
defaults = {
|
28
|
+
:port => 6667,
|
29
|
+
:nick => 'Cinch',
|
30
|
+
:prefix => '!',
|
31
|
+
}
|
32
|
+
|
33
|
+
base = @base.new
|
34
|
+
defaults.each do |k, v|
|
35
|
+
base.options.send(k).should == v
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cinch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
version: "0.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Lee 'injekt' Jarvis
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-04-25 00:00:00 +01:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: rspec
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
segments:
|
27
|
+
- 1
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
version: 1.3.0
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
description: An IRC Microframework
|
34
|
+
email: ljjarvis@gmail.com
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files:
|
40
|
+
- README.rdoc
|
41
|
+
files:
|
42
|
+
- README.rdoc
|
43
|
+
- Rakefile
|
44
|
+
- spec/irc/socket_spec.rb
|
45
|
+
- spec/irc/helper.rb
|
46
|
+
- spec/irc/message_spec.rb
|
47
|
+
- spec/irc/parser_spec.rb
|
48
|
+
- spec/helper.rb
|
49
|
+
- spec/options_spec.rb
|
50
|
+
- lib/cinch.rb
|
51
|
+
- lib/cinch/base.rb
|
52
|
+
- lib/cinch/irc/message.rb
|
53
|
+
- lib/cinch/irc/socket.rb
|
54
|
+
- lib/cinch/irc/parser.rb
|
55
|
+
- lib/cinch/irc.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://rdoc.injekt.net/cinch
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --quiet
|
63
|
+
- --title
|
64
|
+
- "Cinch: The IRC Microframework"
|
65
|
+
- --main
|
66
|
+
- README.rdoc
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 8
|
76
|
+
- 6
|
77
|
+
version: 1.8.6
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.6
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: An IRC Microframework
|
92
|
+
test_files: []
|
93
|
+
|