jeffrafter-marvin 0.1.20081115 → 0.1.20081120
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.textile +105 -32
- data/VERSION.yml +1 -1
- data/bin/marvin +10 -6
- data/config/connections.yml.sample +5 -0
- data/config/settings.yml.sample +2 -7
- data/config/setup.rb +6 -1
- data/handlers/debug_handler.rb +5 -0
- data/handlers/hello_world.rb +1 -1
- data/lib/marvin.rb +13 -9
- data/lib/marvin/abstract_client.rb +88 -43
- data/lib/marvin/abstract_parser.rb +14 -2
- data/lib/marvin/base.rb +44 -6
- data/lib/marvin/dispatchable.rb +9 -4
- data/lib/marvin/exception_tracker.rb +1 -1
- data/lib/marvin/exceptions.rb +3 -0
- data/lib/marvin/irc.rb +4 -5
- data/lib/marvin/irc/client.rb +39 -7
- data/lib/marvin/irc/event.rb +9 -4
- data/lib/marvin/irc/replies.rb +154 -0
- data/lib/marvin/loader.rb +26 -8
- data/lib/marvin/logger.rb +66 -3
- data/lib/marvin/options.rb +33 -0
- data/lib/marvin/parsers.rb +3 -0
- data/lib/marvin/parsers/command.rb +105 -0
- data/lib/marvin/parsers/prefixes.rb +8 -0
- data/lib/marvin/parsers/prefixes/host_mask.rb +30 -0
- data/lib/marvin/parsers/prefixes/server.rb +24 -0
- data/lib/marvin/parsers/ragel_parser.rb +713 -0
- data/lib/marvin/parsers/ragel_parser.rl +144 -0
- data/lib/marvin/parsers/regexp_parser.rb +0 -3
- data/lib/marvin/parsers/simple_parser.rb +20 -81
- data/lib/marvin/settings.rb +9 -9
- data/lib/marvin/test_client.rb +5 -1
- data/lib/marvin/util.rb +20 -3
- data/script/{run → client} +0 -0
- data/script/daemon-runner +1 -1
- data/script/install +3 -0
- data/test/parser_comparison.rb +62 -0
- data/test/parser_test.rb +264 -0
- data/test/test_helper.rb +10 -0
- metadata +19 -9
- data/lib/marvin/drb_handler.rb +0 -7
- data/lib/marvin/irc/abstract_server.rb +0 -4
- data/lib/marvin/irc/base_server.rb +0 -11
- data/lib/marvin/irc/socket_client.rb +0 -69
- data/lib/marvin/parsers/simple_parser/default_events.rb +0 -37
- data/lib/marvin/parsers/simple_parser/event_extensions.rb +0 -14
- data/lib/marvin/parsers/simple_parser/prefixes.rb +0 -34
data/test/parser_test.rb
ADDED
@@ -0,0 +1,264 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
# In reality this tests several different classes:
|
4
|
+
# 1) The parser itself
|
5
|
+
# 2) The Command class
|
6
|
+
# 3) The two different types of prefixes
|
7
|
+
# 4) The Event class
|
8
|
+
class ParserTest < Test::Unit::TestCase
|
9
|
+
@@parser = Marvin::Parsers::SimpleParser
|
10
|
+
|
11
|
+
context "When parsing a LIST" do
|
12
|
+
setup { @parsed = @@parser.new("LIST #twilight_zone,#42") }
|
13
|
+
|
14
|
+
should "not be nil" do
|
15
|
+
assert !@parsed.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
should "have a command" do
|
19
|
+
assert !@parsed.command.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have not a prefix" do
|
23
|
+
assert @parsed.command.prefix.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
should "have a code of LIST" do
|
27
|
+
assert_equal "LIST", @parsed.command.code
|
28
|
+
end
|
29
|
+
|
30
|
+
should "have the correct arguments" do
|
31
|
+
assert_equal ["#twilight_zone,#42"], @parsed.command.params
|
32
|
+
end
|
33
|
+
|
34
|
+
should "be able to convert to an event" do
|
35
|
+
assert !@parsed.to_event.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
should "have the correct incoming event name" do
|
39
|
+
assert_equal :incoming_list, @parsed.to_event.to_incoming_event_name
|
40
|
+
end
|
41
|
+
|
42
|
+
should "have the correct outgoing event name" do
|
43
|
+
assert_equal :outgoing_list, @parsed.to_event.to_outgoing_event_name
|
44
|
+
end
|
45
|
+
|
46
|
+
should "convert to the correct hash" do
|
47
|
+
assert_equal({:channel => "#twilight_zone,#42", :target => ""}, @parsed.to_event.to_hash)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
context "When parsing a JOIN" do
|
53
|
+
setup { @parsed = @@parser.new(":RelayBot!n=MarvinBot@static.amnet.net.au JOIN :#relayrelay") }
|
54
|
+
|
55
|
+
should "not be nil" do
|
56
|
+
assert !@parsed.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
should "have a command" do
|
60
|
+
assert !@parsed.command.nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
should "have a prefix" do
|
64
|
+
assert !@parsed.command.prefix.nil?
|
65
|
+
end
|
66
|
+
|
67
|
+
should "have a code of JOIN" do
|
68
|
+
assert_equal "JOIN", @parsed.command.code
|
69
|
+
end
|
70
|
+
|
71
|
+
should "have the correct arguments" do
|
72
|
+
assert_equal ["#relayrelay"], @parsed.command.params
|
73
|
+
end
|
74
|
+
|
75
|
+
should "have a host mask" do
|
76
|
+
assert @parsed.command.prefix.is_a?(Marvin::Parsers::Prefixes::HostMask)
|
77
|
+
end
|
78
|
+
|
79
|
+
should "have the correct nick" do
|
80
|
+
assert_equal "RelayBot", @parsed.command.prefix.nickname
|
81
|
+
end
|
82
|
+
|
83
|
+
should "have the correct user" do
|
84
|
+
assert_equal "n=MarvinBot", @parsed.command.prefix.user
|
85
|
+
end
|
86
|
+
|
87
|
+
should "have the correct host" do
|
88
|
+
assert_equal "static.amnet.net.au", @parsed.command.prefix.host
|
89
|
+
end
|
90
|
+
|
91
|
+
should "be able to convert to an event" do
|
92
|
+
assert !@parsed.to_event.nil?
|
93
|
+
end
|
94
|
+
|
95
|
+
should "have the correct incoming event name" do
|
96
|
+
assert_equal :incoming_join, @parsed.to_event.to_incoming_event_name
|
97
|
+
end
|
98
|
+
|
99
|
+
should "have the correct outgoing event name" do
|
100
|
+
assert_equal :outgoing_join, @parsed.to_event.to_outgoing_event_name
|
101
|
+
end
|
102
|
+
|
103
|
+
should "convert to the correct hash" do
|
104
|
+
assert_equal({:target => "#relayrelay", :key => ""}.merge(@parsed.command.prefix.to_hash), @parsed.to_event.to_hash)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
context "When parsing a PRIVMSG" do
|
110
|
+
setup { @parsed = @@parser.new(":SuttoL!n=SuttoL@sutto.net PRIVMSG #relayrelay :testing...") }
|
111
|
+
|
112
|
+
should "not be nil" do
|
113
|
+
assert !@parsed.nil?
|
114
|
+
end
|
115
|
+
|
116
|
+
should "have a command" do
|
117
|
+
assert !@parsed.command.nil?
|
118
|
+
end
|
119
|
+
|
120
|
+
should "have a prefix" do
|
121
|
+
assert !@parsed.command.prefix.nil?
|
122
|
+
end
|
123
|
+
|
124
|
+
should "have a code of PRIVMSG" do
|
125
|
+
assert_equal "PRIVMSG", @parsed.command.code
|
126
|
+
end
|
127
|
+
|
128
|
+
should "have the correct arguments" do
|
129
|
+
assert_equal ["#relayrelay", "testing..."], @parsed.command.params
|
130
|
+
end
|
131
|
+
|
132
|
+
should "have a host mask" do
|
133
|
+
assert @parsed.command.prefix.is_a?(Marvin::Parsers::Prefixes::HostMask)
|
134
|
+
end
|
135
|
+
|
136
|
+
should "have the correct nick" do
|
137
|
+
assert_equal "SuttoL", @parsed.command.prefix.nickname
|
138
|
+
end
|
139
|
+
|
140
|
+
should "have the correct user" do
|
141
|
+
assert_equal "n=SuttoL", @parsed.command.prefix.user
|
142
|
+
end
|
143
|
+
|
144
|
+
should "have the correct host" do
|
145
|
+
assert_equal "sutto.net", @parsed.command.prefix.host
|
146
|
+
end
|
147
|
+
|
148
|
+
should "be able to convert to an event" do
|
149
|
+
assert !@parsed.to_event.nil?
|
150
|
+
end
|
151
|
+
|
152
|
+
should "have the correct incoming event name" do
|
153
|
+
assert_equal :incoming_message, @parsed.to_event.to_incoming_event_name
|
154
|
+
end
|
155
|
+
|
156
|
+
should "have the correct outgoing event name" do
|
157
|
+
assert_equal :outgoing_message, @parsed.to_event.to_outgoing_event_name
|
158
|
+
end
|
159
|
+
|
160
|
+
should "convert to the correct hash" do
|
161
|
+
assert_equal({:target => "#relayrelay", :message => "testing..."}.merge(@parsed.command.prefix.to_hash), @parsed.to_event.to_hash)
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
context "When parsing a numeric - 366" do
|
167
|
+
setup { @parsed = @@parser.new(":irc.darth.vpn.spork.in 366 testbot #testing :End of NAMES list") }
|
168
|
+
|
169
|
+
should "not be nil" do
|
170
|
+
assert !@parsed.nil?
|
171
|
+
end
|
172
|
+
|
173
|
+
should "have a command" do
|
174
|
+
assert !@parsed.command.nil?
|
175
|
+
end
|
176
|
+
|
177
|
+
should "have a prefix" do
|
178
|
+
assert !@parsed.command.prefix.nil?
|
179
|
+
end
|
180
|
+
|
181
|
+
should "have a code of 366" do
|
182
|
+
assert_equal "366", @parsed.command.code
|
183
|
+
end
|
184
|
+
|
185
|
+
should "have the correct arguments" do
|
186
|
+
assert_equal ["testbot", "#testing", "End of NAMES list"], @parsed.command.params
|
187
|
+
end
|
188
|
+
|
189
|
+
should "have a host mask" do
|
190
|
+
assert @parsed.command.prefix.is_a?(Marvin::Parsers::Prefixes::Server)
|
191
|
+
end
|
192
|
+
|
193
|
+
should "have the correct name" do
|
194
|
+
assert_equal "irc.darth.vpn.spork.in", @parsed.command.prefix.name
|
195
|
+
end
|
196
|
+
|
197
|
+
should "be able to convert to an event" do
|
198
|
+
assert !@parsed.to_event.nil?
|
199
|
+
end
|
200
|
+
|
201
|
+
should "have the correct incoming event name" do
|
202
|
+
assert_equal :incoming_numeric, @parsed.to_event.to_incoming_event_name
|
203
|
+
end
|
204
|
+
|
205
|
+
should "have the correct outgoing event name" do
|
206
|
+
assert_equal :outgoing_numeric, @parsed.to_event.to_outgoing_event_name
|
207
|
+
end
|
208
|
+
|
209
|
+
should "convert to the correct hash" do
|
210
|
+
assert_equal({:code => "366", :data => "testbot #testing :End of NAMES list"}.merge(@parsed.command.prefix.to_hash), @parsed.to_event.to_hash)
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
context "When parsing a numeric - 004" do
|
216
|
+
setup { @parsed = @@parser.new(":wolfe.freenode.net 004 MarvinBot3000 wolfe.freenode.net hyperion-1.0.2b aAbBcCdDeEfFGhHiIjkKlLmMnNopPQrRsStTuUvVwWxXyYzZ01234569*@ bcdefFhiIklmnoPqstv") }
|
217
|
+
|
218
|
+
should "not be nil" do
|
219
|
+
assert !@parsed.nil?
|
220
|
+
end
|
221
|
+
|
222
|
+
should "have a command" do
|
223
|
+
assert !@parsed.command.nil?
|
224
|
+
end
|
225
|
+
|
226
|
+
should "have a prefix" do
|
227
|
+
assert !@parsed.command.prefix.nil?
|
228
|
+
end
|
229
|
+
|
230
|
+
should "have a code of 366" do
|
231
|
+
assert_equal "004", @parsed.command.code
|
232
|
+
end
|
233
|
+
|
234
|
+
should "have the correct arguments" do
|
235
|
+
assert_equal ["MarvinBot3000" , "wolfe.freenode.net", "hyperion-1.0.2b", "aAbBcCdDeEfFGhHiIjkKlLmMnNopPQrRsStTuUvVwWxXyYzZ01234569*@", "bcdefFhiIklmnoPqstv"], @parsed.command.params
|
236
|
+
end
|
237
|
+
|
238
|
+
should "have a host mask" do
|
239
|
+
assert @parsed.command.prefix.is_a?(Marvin::Parsers::Prefixes::Server)
|
240
|
+
end
|
241
|
+
|
242
|
+
should "have the correct name" do
|
243
|
+
assert_equal "wolfe.freenode.net", @parsed.command.prefix.name
|
244
|
+
end
|
245
|
+
|
246
|
+
should "be able to convert to an event" do
|
247
|
+
assert !@parsed.to_event.nil?
|
248
|
+
end
|
249
|
+
|
250
|
+
should "have the correct incoming event name" do
|
251
|
+
assert_equal :incoming_numeric, @parsed.to_event.to_incoming_event_name
|
252
|
+
end
|
253
|
+
|
254
|
+
should "have the correct outgoing event name" do
|
255
|
+
assert_equal :outgoing_numeric, @parsed.to_event.to_outgoing_event_name
|
256
|
+
end
|
257
|
+
|
258
|
+
should "convert to the correct hash" do
|
259
|
+
assert_equal({:code => "004", :data => "MarvinBot3000 wolfe.freenode.net hyperion-1.0.2b aAbBcCdDeEfFGhHiIjkKlLmMnNopPQrRsStTuUvVwWxXyYzZ01234569*@ bcdefFhiIklmnoPqstv"}.merge(@parsed.command.prefix.to_hash), @parsed.to_event.to_hash)
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jeffrafter-marvin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.20081120
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darcy Laycock
|
@@ -9,8 +9,8 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-11-
|
13
|
-
default_executable:
|
12
|
+
date: 2008-11-22 00:00:00 -08:00
|
13
|
+
default_executable: marvin
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Marvin is a Ruby IRC library / framework for ultimate awesomeness and with an evented design.
|
@@ -42,33 +42,43 @@ files:
|
|
42
42
|
- lib/marvin/irc/base_server.rb
|
43
43
|
- lib/marvin/irc/client.rb
|
44
44
|
- lib/marvin/irc/event.rb
|
45
|
-
- lib/marvin/irc/
|
45
|
+
- lib/marvin/irc/replies.rb
|
46
46
|
- lib/marvin/irc.rb
|
47
47
|
- lib/marvin/loader.rb
|
48
48
|
- lib/marvin/logger.rb
|
49
49
|
- lib/marvin/middle_man.rb
|
50
|
+
- lib/marvin/options.rb
|
50
51
|
- lib/marvin/parsers
|
52
|
+
- lib/marvin/parsers/command.rb
|
53
|
+
- lib/marvin/parsers/prefixes
|
54
|
+
- lib/marvin/parsers/prefixes/host_mask.rb
|
55
|
+
- lib/marvin/parsers/prefixes/server.rb
|
56
|
+
- lib/marvin/parsers/prefixes.rb
|
57
|
+
- lib/marvin/parsers/ragel_parser.rb
|
58
|
+
- lib/marvin/parsers/ragel_parser.rl
|
51
59
|
- lib/marvin/parsers/regexp_parser.rb
|
52
|
-
- lib/marvin/parsers/simple_parser
|
53
|
-
- lib/marvin/parsers/simple_parser/default_events.rb
|
54
|
-
- lib/marvin/parsers/simple_parser/event_extensions.rb
|
55
|
-
- lib/marvin/parsers/simple_parser/prefixes.rb
|
56
60
|
- lib/marvin/parsers/simple_parser.rb
|
57
61
|
- lib/marvin/parsers.rb
|
58
62
|
- lib/marvin/settings.rb
|
59
63
|
- lib/marvin/test_client.rb
|
60
64
|
- lib/marvin/util.rb
|
61
65
|
- lib/marvin.rb
|
66
|
+
- test/parser_comparison.rb
|
67
|
+
- test/parser_test.rb
|
68
|
+
- test/test_helper.rb
|
62
69
|
- spec/marvin
|
63
70
|
- spec/marvin/abstract_client_test.rb
|
64
71
|
- spec/spec_helper.rb
|
72
|
+
- script/client
|
65
73
|
- script/daemon-runner
|
66
|
-
- script/
|
74
|
+
- script/install
|
75
|
+
- handlers/debug_handler.rb
|
67
76
|
- handlers/hello_world.rb
|
68
77
|
- handlers/logging_handler.rb
|
69
78
|
- handlers/tweet_tweet.rb
|
70
79
|
- config/setup.rb
|
71
80
|
- config/settings.yml.sample
|
81
|
+
- config/connections.yml.sample
|
72
82
|
has_rdoc: false
|
73
83
|
homepage: http://blog.ninjahideout.com/
|
74
84
|
post_install_message:
|
data/lib/marvin/drb_handler.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'socket'
|
2
|
-
|
3
|
-
module Marvin::IRC
|
4
|
-
class SocketClient < Marvin::AbstractClient
|
5
|
-
attr_accessor :socket
|
6
|
-
|
7
|
-
def run
|
8
|
-
@socket = TCPSocket.new(self.configuration.server, self.configuration.port)
|
9
|
-
self.process_connect
|
10
|
-
self.enter_loop
|
11
|
-
end
|
12
|
-
|
13
|
-
def send_line(*args)
|
14
|
-
args.each { |l| @socket.write l } if !@socket.closed?
|
15
|
-
end
|
16
|
-
|
17
|
-
def disconnect_processed?
|
18
|
-
@disconnect_processed
|
19
|
-
end
|
20
|
-
|
21
|
-
def enter_loop
|
22
|
-
until @socket.closed?
|
23
|
-
line = @socket.readline.strip
|
24
|
-
receive_line line
|
25
|
-
end
|
26
|
-
self.process_disconnect unless self.disconnect_processed?
|
27
|
-
@disconnect_processed = true
|
28
|
-
rescue SystemExit
|
29
|
-
self.process_disconnect unless self.disconnect_processed?
|
30
|
-
@disconnect_processed = true
|
31
|
-
rescue Exception => e
|
32
|
-
Marvin::ExceptionTracker.log(e)
|
33
|
-
end
|
34
|
-
|
35
|
-
def quit(*args)
|
36
|
-
super(*args)
|
37
|
-
end
|
38
|
-
|
39
|
-
## Client specific details
|
40
|
-
|
41
|
-
def self.run
|
42
|
-
self.setup # So we have options etc
|
43
|
-
logger.debug "Connecting to #{self.configuration.server}:#{self.configuration.port}"
|
44
|
-
self.new.run
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.stop
|
48
|
-
logger.debug "Telling all connections to quit"
|
49
|
-
self.connections.each do |connection|
|
50
|
-
connection.quit
|
51
|
-
logger.debug "Preparing to close socket"
|
52
|
-
connection.socket.close
|
53
|
-
end
|
54
|
-
logger.debug "Stopped."
|
55
|
-
end
|
56
|
-
|
57
|
-
# Registers a callback handle that will be periodically run.
|
58
|
-
def periodically(timing, event_callback)
|
59
|
-
callback = proc { self.dispatch event_callback.to_sym }
|
60
|
-
Thread.new do
|
61
|
-
while true
|
62
|
-
callback.call
|
63
|
-
sleep timing
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
class Marvin::Parsers::SimpleParser < Marvin::AbstractParser
|
2
|
-
module DefaultEvents
|
3
|
-
|
4
|
-
def self.included(parent)
|
5
|
-
parent.class_eval do
|
6
|
-
extend ClassMethods
|
7
|
-
# Register the default set of events with commands
|
8
|
-
register_event :nick, :NICK, :new_nick
|
9
|
-
register_event :quit, :QUIT, :message
|
10
|
-
register_event :ping, :PING, :data
|
11
|
-
register_event :join, :JOIN, :target
|
12
|
-
register_event :invite, :INVITE, :target, :channel
|
13
|
-
register_event :message, :PRIVMSG, :target, :message
|
14
|
-
register_event :part, :PART, :target, :message
|
15
|
-
register_event :mode, :MODE, :target, :mode
|
16
|
-
register_event :kick, :KICK, :target, :channel, :reason
|
17
|
-
register_event :topic, :TOPIC, :target, :topic
|
18
|
-
# Add the default numeric event
|
19
|
-
register_event :numeric, :numeric, :code, :data
|
20
|
-
# And a few others reserved for special purposed
|
21
|
-
register_event :action, :action, :message
|
22
|
-
register_event :ctcp, :ctcp, :message
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
module ClassMethods
|
27
|
-
|
28
|
-
# Register an event from a given name,
|
29
|
-
# command as well as a set of arguments.
|
30
|
-
def register_event(name, command, *args)
|
31
|
-
event = Marvin::Parsers::SimpleParser::EventWithPrefix.new(name, *args)
|
32
|
-
self.events[command] = event
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|