Sutto-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.
Files changed (44) hide show
  1. data/README.textile +70 -50
  2. data/VERSION.yml +1 -1
  3. data/bin/marvin +10 -6
  4. data/config/connections.yml.sample +5 -0
  5. data/config/settings.yml.sample +2 -7
  6. data/config/setup.rb +1 -0
  7. data/handlers/debug_handler.rb +5 -0
  8. data/handlers/hello_world.rb +1 -1
  9. data/lib/marvin.rb +1 -0
  10. data/lib/marvin/abstract_client.rb +79 -42
  11. data/lib/marvin/abstract_parser.rb +14 -2
  12. data/lib/marvin/base.rb +44 -6
  13. data/lib/marvin/dispatchable.rb +9 -4
  14. data/lib/marvin/drb_handler.rb +7 -2
  15. data/lib/marvin/exceptions.rb +3 -0
  16. data/lib/marvin/irc.rb +1 -1
  17. data/lib/marvin/irc/client.rb +31 -7
  18. data/lib/marvin/irc/event.rb +9 -4
  19. data/lib/marvin/irc/replies.rb +154 -0
  20. data/lib/marvin/loader.rb +1 -0
  21. data/lib/marvin/logger.rb +66 -3
  22. data/lib/marvin/options.rb +33 -0
  23. data/lib/marvin/parsers.rb +3 -0
  24. data/lib/marvin/parsers/command.rb +73 -0
  25. data/lib/marvin/parsers/prefixes.rb +8 -0
  26. data/lib/marvin/parsers/prefixes/host_mask.rb +30 -0
  27. data/lib/marvin/parsers/prefixes/server.rb +24 -0
  28. data/lib/marvin/parsers/ragel_parser.rb +713 -0
  29. data/lib/marvin/parsers/ragel_parser.rl +144 -0
  30. data/lib/marvin/parsers/regexp_parser.rb +0 -3
  31. data/lib/marvin/parsers/simple_parser.rb +20 -81
  32. data/lib/marvin/settings.rb +8 -8
  33. data/lib/marvin/util.rb +2 -2
  34. data/script/{run → client} +0 -0
  35. data/script/daemon-runner +1 -1
  36. data/script/install +3 -0
  37. data/test/parser_comparison.rb +36 -0
  38. data/test/parser_test.rb +20 -0
  39. data/test/test_helper.rb +10 -0
  40. metadata +19 -9
  41. data/lib/marvin/irc/socket_client.rb +0 -69
  42. data/lib/marvin/parsers/simple_parser/default_events.rb +0 -37
  43. data/lib/marvin/parsers/simple_parser/event_extensions.rb +0 -14
  44. data/lib/marvin/parsers/simple_parser/prefixes.rb +0 -34
@@ -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
@@ -1,14 +0,0 @@
1
- # An extension to Marvin::IRC::Event which
2
- # lets a user specify a prefix to use.
3
- class Marvin::Parsers::SimpleParser < Marvin::AbstractParser
4
-
5
- class EventWithPrefix < Marvin::IRC::Event
6
- attr_accessor :prefix
7
-
8
- def to_hash
9
- super.merge(prefix.blank? ? {} : prefix.to_hash)
10
- end
11
-
12
- end
13
-
14
- end
@@ -1,34 +0,0 @@
1
- # A Set of prefixes for a given IRC line
2
- # as parsed from an incoming line.
3
- class Marvin::Parsers::SimpleParser < Marvin::AbstractParser
4
-
5
- class Prefix; end
6
-
7
- class ServerNamePrefix < Prefix
8
- attr_accessor :server_name
9
-
10
- def initialize(name)
11
- self.server_name = name
12
- end
13
-
14
- def to_hash
15
- {:server => self.server_name}
16
- end
17
-
18
- end
19
-
20
- class UserPrefix < Prefix
21
- attr_accessor :nick, :ident, :host
22
-
23
- def initialize(nick, ident = nil, host = nil)
24
- self.nick = nick
25
- self.ident = ident
26
- self.host = host
27
- end
28
-
29
- def to_hash
30
- {:host => self.host, :nick => self.nick, :ident => self.ident}
31
- end
32
- end
33
-
34
- end