Sutto-marvin 0.4.0 → 0.8.0.0

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 (85) hide show
  1. data/bin/marvin +22 -156
  2. data/handlers/keiki_thwopper.rb +21 -0
  3. data/handlers/tweet_tweet.rb +1 -3
  4. data/lib/marvin/abstract_client.rb +75 -189
  5. data/lib/marvin/abstract_parser.rb +9 -11
  6. data/lib/marvin/base.rb +134 -101
  7. data/lib/marvin/client/actions.rb +104 -0
  8. data/lib/marvin/client/default_handlers.rb +97 -0
  9. data/lib/marvin/command_handler.rb +60 -49
  10. data/lib/marvin/console.rb +4 -31
  11. data/lib/marvin/core_commands.rb +30 -12
  12. data/lib/marvin/distributed/client.rb +225 -0
  13. data/lib/marvin/distributed/handler.rb +85 -0
  14. data/lib/marvin/distributed/protocol.rb +88 -0
  15. data/lib/marvin/distributed/server.rb +154 -0
  16. data/lib/marvin/distributed.rb +4 -10
  17. data/lib/marvin/dsl.rb +103 -0
  18. data/lib/marvin/exception_tracker.rb +7 -4
  19. data/lib/marvin/irc/client.rb +127 -99
  20. data/lib/marvin/irc/event.rb +14 -10
  21. data/lib/marvin/irc.rb +0 -1
  22. data/lib/marvin/middle_man.rb +1 -1
  23. data/lib/marvin/parsers/command.rb +10 -8
  24. data/lib/marvin/parsers/prefixes/host_mask.rb +12 -7
  25. data/lib/marvin/parsers/prefixes/server.rb +1 -1
  26. data/lib/marvin/parsers/ragel_parser.rb +59 -52
  27. data/lib/marvin/parsers/ragel_parser.rl +6 -7
  28. data/lib/marvin/parsers/simple_parser.rb +4 -9
  29. data/lib/marvin/parsers.rb +1 -2
  30. data/lib/marvin/settings.rb +29 -79
  31. data/lib/marvin/test_client.rb +20 -26
  32. data/lib/marvin/util.rb +10 -3
  33. data/lib/marvin.rb +42 -39
  34. data/templates/boot.erb +3 -0
  35. data/templates/connections.yml.erb +10 -0
  36. data/templates/debug_handler.erb +5 -0
  37. data/templates/hello_world.erb +10 -0
  38. data/templates/rakefile.erb +15 -0
  39. data/templates/settings.yml.erb +8 -0
  40. data/{config/setup.rb → templates/setup.erb} +8 -10
  41. data/templates/test_helper.erb +17 -0
  42. data/test/abstract_client_test.rb +63 -0
  43. data/test/parser_comparison.rb +2 -2
  44. data/test/parser_test.rb +3 -3
  45. data/test/test_helper.rb +58 -6
  46. metadata +51 -83
  47. data/README.textile +0 -105
  48. data/TUTORIAL.textile +0 -54
  49. data/VERSION.yml +0 -4
  50. data/config/boot.rb +0 -14
  51. data/config/connections.yml.sample +0 -5
  52. data/config/settings.yml.sample +0 -13
  53. data/handlers/logging_handler.rb +0 -89
  54. data/lib/marvin/core_ext.rb +0 -11
  55. data/lib/marvin/daemon.rb +0 -71
  56. data/lib/marvin/data_store.rb +0 -73
  57. data/lib/marvin/dispatchable.rb +0 -99
  58. data/lib/marvin/distributed/dispatch_handler.rb +0 -83
  59. data/lib/marvin/distributed/drb_client.rb +0 -78
  60. data/lib/marvin/distributed/ring_server.rb +0 -41
  61. data/lib/marvin/handler.rb +0 -12
  62. data/lib/marvin/irc/server/abstract_connection.rb +0 -84
  63. data/lib/marvin/irc/server/base_connection.rb +0 -66
  64. data/lib/marvin/irc/server/channel.rb +0 -115
  65. data/lib/marvin/irc/server/named_store.rb +0 -14
  66. data/lib/marvin/irc/server/remote_interface.rb +0 -77
  67. data/lib/marvin/irc/server/user/handle_mixin.rb +0 -140
  68. data/lib/marvin/irc/server/user.rb +0 -5
  69. data/lib/marvin/irc/server/user_connection.rb +0 -134
  70. data/lib/marvin/irc/server/virtual_user_connection.rb +0 -80
  71. data/lib/marvin/irc/server.rb +0 -71
  72. data/lib/marvin/loader.rb +0 -149
  73. data/lib/marvin/logger.rb +0 -86
  74. data/lib/marvin/options.rb +0 -42
  75. data/lib/marvin/parsers/regexp_parser.rb +0 -93
  76. data/lib/marvin/status.rb +0 -72
  77. data/script/client +0 -3
  78. data/script/console +0 -3
  79. data/script/distributed_client +0 -3
  80. data/script/install +0 -1
  81. data/script/ring_server +0 -4
  82. data/script/server +0 -4
  83. data/script/status +0 -3
  84. data/spec/marvin/abstract_client_test.rb +0 -38
  85. data/spec/spec_helper.rb +0 -14
@@ -1,5 +1,9 @@
1
- # line 1 "lib/marvin/parsers/ragel_parser.rl"
2
- # line 107 "lib/marvin/parsers/ragel_parser.rl"
1
+
2
+ # line 1 "ragel_parser.rl"
3
+ # Ragel Parser comes from the Arrbot Guys - Kudos to Halogrium and Epitron.
4
+
5
+
6
+ # line 109 "ragel_parser.rl"
3
7
 
4
8
 
5
9
  module Marvin
@@ -7,7 +11,7 @@ module Marvin
7
11
  class RagelParser < Marvin::AbstractParser
8
12
 
9
13
 
10
- # line 11 "lib/marvin/parsers/ragel_parser.rb"
14
+ # line 15 "ragel_parser.rb"
11
15
  class << self
12
16
  attr_accessor :_irc_actions
13
17
  private :_irc_actions, :_irc_actions=
@@ -434,7 +438,8 @@ class << self
434
438
  end
435
439
  self.irc_en_main = 1;
436
440
 
437
- # line 114 "lib/marvin/parsers/ragel_parser.rl"
441
+
442
+ # line 116 "ragel_parser.rl"
438
443
 
439
444
  private
440
445
 
@@ -448,18 +453,19 @@ self.irc_en_main = 1;
448
453
  hostmask = nil
449
454
  server = nil
450
455
  code = nil
451
- command = Marvin::Parsers::Command.new(data)
456
+ command = Command.new(data)
452
457
 
453
458
 
454
- # line 462 "lib/marvin/parsers/ragel_parser.rb"
459
+ # line 460 "ragel_parser.rb"
455
460
  begin
456
461
  p ||= 0
457
462
  pe ||= data.length
458
463
  cs = irc_start
459
464
  end
460
- # line 137 "lib/marvin/parsers/ragel_parser.rl"
465
+
466
+ # line 132 "ragel_parser.rl"
461
467
 
462
- # line 470 "lib/marvin/parsers/ragel_parser.rb"
468
+ # line 469 "ragel_parser.rb"
463
469
  begin
464
470
  _klen, _trans, _keys, _acts, _nacts = nil
465
471
  _goto_level = 0
@@ -541,139 +547,139 @@ begin
541
547
  _acts += 1
542
548
  case _irc_actions[_acts - 1]
543
549
  when 0 then
544
- # line 4 "lib/marvin/parsers/ragel_parser.rl"
550
+ # line 6 "ragel_parser.rl"
545
551
  begin
546
552
 
547
- server = Marvin::Parsers::Prefixes::Server.new
553
+ server = Prefixes::Server.new
548
554
  end
549
- # line 4 "lib/marvin/parsers/ragel_parser.rl"
555
+ # line 6 "ragel_parser.rl"
550
556
  when 1 then
551
- # line 8 "lib/marvin/parsers/ragel_parser.rl"
557
+ # line 10 "ragel_parser.rl"
552
558
  begin
553
559
 
554
560
  server.name << data[p]
555
561
  end
556
- # line 8 "lib/marvin/parsers/ragel_parser.rl"
562
+ # line 10 "ragel_parser.rl"
557
563
  when 2 then
558
- # line 12 "lib/marvin/parsers/ragel_parser.rl"
564
+ # line 14 "ragel_parser.rl"
559
565
  begin
560
566
 
561
567
  command.prefix = server
562
568
  end
563
- # line 12 "lib/marvin/parsers/ragel_parser.rl"
569
+ # line 14 "ragel_parser.rl"
564
570
  when 3 then
565
- # line 16 "lib/marvin/parsers/ragel_parser.rl"
571
+ # line 18 "ragel_parser.rl"
566
572
  begin
567
573
 
568
- hostmask = Marvin::Parsers::Prefixes::HostMask.new
574
+ hostmask = Prefixes::HostMask.new
569
575
  end
570
- # line 16 "lib/marvin/parsers/ragel_parser.rl"
576
+ # line 18 "ragel_parser.rl"
571
577
  when 4 then
572
- # line 20 "lib/marvin/parsers/ragel_parser.rl"
578
+ # line 22 "ragel_parser.rl"
573
579
  begin
574
580
 
575
- hostmask.nickname << data[p]
581
+ hostmask.nick << data[p]
576
582
  end
577
- # line 20 "lib/marvin/parsers/ragel_parser.rl"
583
+ # line 22 "ragel_parser.rl"
578
584
  when 5 then
579
- # line 24 "lib/marvin/parsers/ragel_parser.rl"
585
+ # line 26 "ragel_parser.rl"
580
586
  begin
581
587
 
582
588
  hostmask.user << data[p]
583
589
  end
584
- # line 24 "lib/marvin/parsers/ragel_parser.rl"
590
+ # line 26 "ragel_parser.rl"
585
591
  when 6 then
586
- # line 28 "lib/marvin/parsers/ragel_parser.rl"
592
+ # line 30 "ragel_parser.rl"
587
593
  begin
588
594
 
589
595
  hostmask.host << data[p]
590
596
  end
591
- # line 28 "lib/marvin/parsers/ragel_parser.rl"
597
+ # line 30 "ragel_parser.rl"
592
598
  when 7 then
593
- # line 32 "lib/marvin/parsers/ragel_parser.rl"
599
+ # line 34 "ragel_parser.rl"
594
600
  begin
595
601
 
596
602
  command.prefix = hostmask
597
603
  end
598
- # line 32 "lib/marvin/parsers/ragel_parser.rl"
604
+ # line 34 "ragel_parser.rl"
599
605
  when 8 then
600
- # line 36 "lib/marvin/parsers/ragel_parser.rl"
606
+ # line 38 "ragel_parser.rl"
601
607
  begin
602
608
 
603
609
  code = ""
604
610
  end
605
- # line 36 "lib/marvin/parsers/ragel_parser.rl"
611
+ # line 38 "ragel_parser.rl"
606
612
  when 9 then
607
- # line 40 "lib/marvin/parsers/ragel_parser.rl"
613
+ # line 42 "ragel_parser.rl"
608
614
  begin
609
615
 
610
616
  code << data[p]
611
617
  end
612
- # line 40 "lib/marvin/parsers/ragel_parser.rl"
618
+ # line 42 "ragel_parser.rl"
613
619
  when 10 then
614
- # line 44 "lib/marvin/parsers/ragel_parser.rl"
620
+ # line 46 "ragel_parser.rl"
615
621
  begin
616
622
 
617
623
  command.code = code
618
624
  end
619
- # line 44 "lib/marvin/parsers/ragel_parser.rl"
625
+ # line 46 "ragel_parser.rl"
620
626
  when 11 then
621
- # line 48 "lib/marvin/parsers/ragel_parser.rl"
627
+ # line 50 "ragel_parser.rl"
622
628
  begin
623
629
 
624
630
  params_1 = []
625
631
  params_2 = []
626
632
  end
627
- # line 48 "lib/marvin/parsers/ragel_parser.rl"
633
+ # line 50 "ragel_parser.rl"
628
634
  when 12 then
629
- # line 53 "lib/marvin/parsers/ragel_parser.rl"
635
+ # line 55 "ragel_parser.rl"
630
636
  begin
631
637
 
632
638
  end
633
- # line 53 "lib/marvin/parsers/ragel_parser.rl"
639
+ # line 55 "ragel_parser.rl"
634
640
  when 13 then
635
- # line 56 "lib/marvin/parsers/ragel_parser.rl"
641
+ # line 58 "ragel_parser.rl"
636
642
  begin
637
643
 
638
644
  params_1 << ""
639
645
  end
640
- # line 56 "lib/marvin/parsers/ragel_parser.rl"
646
+ # line 58 "ragel_parser.rl"
641
647
  when 14 then
642
- # line 60 "lib/marvin/parsers/ragel_parser.rl"
648
+ # line 62 "ragel_parser.rl"
643
649
  begin
644
650
 
645
651
  params_2 << ""
646
652
  end
647
- # line 60 "lib/marvin/parsers/ragel_parser.rl"
653
+ # line 62 "ragel_parser.rl"
648
654
  when 15 then
649
- # line 64 "lib/marvin/parsers/ragel_parser.rl"
655
+ # line 66 "ragel_parser.rl"
650
656
  begin
651
657
 
652
658
  params_1.last << data[p]
653
659
  end
654
- # line 64 "lib/marvin/parsers/ragel_parser.rl"
660
+ # line 66 "ragel_parser.rl"
655
661
  when 16 then
656
- # line 68 "lib/marvin/parsers/ragel_parser.rl"
662
+ # line 70 "ragel_parser.rl"
657
663
  begin
658
664
 
659
665
  params_2.last << data[p]
660
666
  end
661
- # line 68 "lib/marvin/parsers/ragel_parser.rl"
667
+ # line 70 "ragel_parser.rl"
662
668
  when 17 then
663
- # line 72 "lib/marvin/parsers/ragel_parser.rl"
669
+ # line 74 "ragel_parser.rl"
664
670
  begin
665
671
 
666
672
  command.params = params_1
667
673
  end
668
- # line 72 "lib/marvin/parsers/ragel_parser.rl"
674
+ # line 74 "ragel_parser.rl"
669
675
  when 18 then
670
- # line 76 "lib/marvin/parsers/ragel_parser.rl"
676
+ # line 78 "ragel_parser.rl"
671
677
  begin
672
678
 
673
679
  command.params = params_2
674
680
  end
675
- # line 76 "lib/marvin/parsers/ragel_parser.rl"
676
- # line 684 "lib/marvin/parsers/ragel_parser.rb"
681
+ # line 78 "ragel_parser.rl"
682
+ # line 683 "ragel_parser.rb"
677
683
  end # action switch
678
684
  end
679
685
  end
@@ -699,12 +705,13 @@ when 18 then
699
705
  end
700
706
  end
701
707
  end
702
- # line 138 "lib/marvin/parsers/ragel_parser.rl"
708
+
709
+ # line 133 "ragel_parser.rl"
703
710
 
704
711
  if cs >= irc_first_final
705
712
  command
706
713
  else
707
- raise UnparseableMessage, "Failed to parse the message: #{input.inspect}"
714
+ raise UnparseableMessage, "Failed to parse the message: #{line.strip}"
708
715
  end
709
716
  end
710
717
 
@@ -1,11 +1,10 @@
1
- # Ragel Parser comes from the Arrbot Guys -
2
- # Kudos to Halogrium and Epitron.
1
+ # Ragel Parser comes from the Arrbot Guys - Kudos to Halogrium and Epitron.
3
2
 
4
3
  %%{
5
4
  machine irc;
6
5
 
7
6
  action prefix_servername_start {
8
- server = Marvin::Parsers::Prefixes::Server.new
7
+ server = Prefixes::Server.new
9
8
  }
10
9
 
11
10
  action prefix_servername {
@@ -17,11 +16,11 @@
17
16
  }
18
17
 
19
18
  action prefix_hostmask_start {
20
- hostmask = Marvin::Parsers::Prefixes::HostMask.new
19
+ hostmask = Prefixes::HostMask.new
21
20
  }
22
21
 
23
22
  action hostmask_nickname {
24
- hostmask.nickname << fc
23
+ hostmask.nick << fc
25
24
  }
26
25
 
27
26
  action hostmask_user {
@@ -127,7 +126,7 @@ module Marvin
127
126
  hostmask = nil
128
127
  server = nil
129
128
  code = nil
130
- command = Marvin::Parsers::Command.new(data)
129
+ command = Command.new(data)
131
130
 
132
131
  %% write init;
133
132
  %% write exec;
@@ -135,7 +134,7 @@ module Marvin
135
134
  if cs >= irc_first_final
136
135
  command
137
136
  else
138
- raise UnparseableMessage, "Failed to parse the message: #{input.inspect}"
137
+ raise UnparseableMessage, "Failed to parse the message: #{line.strip}"
139
138
  end
140
139
  end
141
140
 
@@ -7,17 +7,12 @@ module Marvin
7
7
  # Parses an incoming message by using string
8
8
  # Manipulation.
9
9
  def self.parse!(line)
10
- if line[0] == ?:
11
- prefix_text, line = line.split(" ", 2)
12
- else
13
- prefix_text = nil
14
- end
15
- command = Marvin::Parsers::Command.new(line + "\r\n")
10
+ prefix_text = nil
11
+ prefix_text, line = line.split(" ", 2) if line[0] == ?:
12
+ command = Command.new("#{line}\r\n")
16
13
  command.prefix = self.extract_prefix(prefix_text)
17
- head, tail = line.split(":", 2)
18
- parts = head.split(" ")
14
+ parts = Marvin::Util.arguments(line)
19
15
  command.code = parts.shift
20
- parts << tail unless tail.nil?
21
16
  command.params = parts
22
17
  return command
23
18
  end
@@ -1,10 +1,9 @@
1
1
  module Marvin
2
2
  module Parsers
3
3
  # Default Parsers
4
- autoload :RegexpParser, 'marvin/parsers/regexp_parser'
5
- autoload :SimpleParser, 'marvin/parsers/simple_parser'
6
4
  autoload :Prefixes, 'marvin/parsers/prefixes'
7
5
  autoload :Command, 'marvin/parsers/command'
6
+ autoload :SimpleParser, 'marvin/parsers/simple_parser'
8
7
  autoload :RagelParser, 'marvin/parsers/ragel_parser'
9
8
  end
10
9
  end
@@ -1,81 +1,31 @@
1
- require 'yaml'
2
- require 'eventmachine'
3
-
4
- module Marvin
5
- class Settings
6
-
7
- cattr_accessor :environment, :configuration, :is_setup, :default_client, :distributed_namespace,
8
- :handler_folder, :default_parser, :log_level, :verbose, :daemon
9
-
10
- self.verbose = false
11
- self.log_level = :info
12
- self.daemon = false
13
-
14
- class << self
15
-
16
- def daemon?
17
- self.daemon
18
- end
19
-
20
- def root
21
- File.expand_path(defined?(MARVIN_ROOT) ? MARVIN_ROOT : File.dirname(__FILE__) / "../..")
22
- end
23
-
24
- def setup(options = {})
25
- return if self.is_setup
26
- self.setup!(options)
27
- end
28
-
29
- def distributed_namespace
30
- @@distributed_namespace ||= :default
31
- end
32
-
33
- def setup!(options = {})
34
- self.environment ||= "development"
35
- self.configuration = {}
36
- self.default_client ||= Marvin::IRC::Client
37
- self.default_parser ||= Marvin::Parsers::SimpleParser
38
- loaded_yaml = YAML.load_file(root / "config/settings.yml")
39
- env_settings = loaded_yaml[self.environment] || {}
40
- loaded_options = loaded_yaml["default"].merge(env_settings).merge(options)
41
- self.configuration.merge!(loaded_options)
42
- self.configuration.symbolize_keys!
43
- mod = Module.new do
44
- Settings.configuration.keys.each do |k|
45
- define_method(k) do
46
- return Settings.configuration[k]
47
- end
48
-
49
- define_method("#{k}=") do |val|
50
- Settings.configuration[k] = val
51
- end
52
- end
53
- end
54
-
55
- # Extend and include.
56
-
57
- extend mod
58
- include mod
59
-
60
- self.is_setup = true
61
- end
62
-
63
- def [](key)
64
- self.setup
65
- return self.configuration[key.to_sym]
66
- end
67
-
68
- def []=(key, value)
69
- self.setup
70
- self.configuration[key.to_sym] = value
71
- return value
72
- end
73
-
74
- def to_hash
75
- self.configuration
76
- end
77
-
78
- end
79
-
1
+ # Example of extending built in Perennial
2
+ # functionality. Since const_get etc acts
3
+ # oddly, this is the best way to do it.
4
+ Marvin::Settings.class_eval do
5
+
6
+ def self.parser
7
+ # We use SimpleParser by default because it is almost
8
+ # 20 times faster (from basic benchmarks) than the Ragel
9
+ # based parser. If you're having issues with unexpected
10
+ # results, please try using Ragel as the parser for you
11
+ # application - It was (afaik) almost a direct port
12
+ # from the RFC where as I've taken some liberties with
13
+ # simple parser for the expected reasons.
14
+ @@parser ||= Marvin::Parsers::SimpleParser
80
15
  end
16
+
17
+ def self.parser=(value)
18
+ raise ArgumentError, 'Is not a valid parser implementation' unless value < Marvin::AbstractParser
19
+ @@parser = value
20
+ end
21
+
22
+ def self.client
23
+ @@client ||= Marvin::IRC::Client
24
+ end
25
+
26
+ def self.client=(value)
27
+ raise ArgumentError, 'Is not a valid client implementation' unless value < Marvin::AbstractClient
28
+ @@client = value
29
+ end
30
+
81
31
  end
@@ -1,63 +1,57 @@
1
- require 'ostruct'
2
- require 'active_support'
3
-
4
1
  module Marvin
5
2
  # Marvin::TestClient is a simple client used for testing
6
3
  # Marvin::Base derivatives in a non-network-reliant setting.
7
4
  class TestClient < AbstractClient
8
- attr_accessor :incoming_commands, :outgoing_commands, :last_sent, :dispatched_events, :connection_open
5
+
6
+ attr_accessor :incoming_commands, :outgoing_commands, :last_sent,
7
+ :dispatched_events, :connection_open
9
8
 
10
9
  cattr_accessor :instances
11
- self.instances = []
10
+ @@instances = []
12
11
 
13
12
  DispatchedEvents = Struct.new(:name, :options)
14
13
 
15
14
  def initialize(opts = {})
16
15
  super
17
- self.incoming_commands = []
18
- self.outgoing_commands = []
19
- self.dispatched_events = []
20
- self.connection_open = false
21
- self.instances << self
16
+ @incoming_commands = []
17
+ @outgoing_commands = []
18
+ @dispatched_events = []
19
+ @connection_open = false
20
+ @@instances << self
22
21
  end
23
22
 
24
23
  def connection_open?
25
- self.connection_open
24
+ !!@connection_open
26
25
  end
27
26
 
28
27
  def send_line(*args)
29
- self.outgoing_commands += args
30
- self.last_sent = args.last
28
+ @outgoing_commands += args
29
+ @last_sent = args.last
31
30
  end
32
31
 
33
32
  def test_command(name, *args)
34
- options = args.extract_options!
33
+ options = args.extract_options!
35
34
  host_mask = options.delete(:host_mask) || ":WiZ!jto@tolsun.oulu.fi"
36
- name = name.to_s.upcase
37
- args = args.flatten.compact
38
- irc_command = "#{host_mask} #{name} #{args.join(" ").strip}"
39
- self.receive_line irc_command
35
+ name = name.to_s.upcase
36
+ args = args.flatten.compact
37
+ receive_line "#{host_mask} #{name} #{args.join(" ").strip}"
40
38
  end
41
39
 
42
40
  def dispatch(name, opts = {})
43
- self.dispatched_events << [name, opts]
41
+ @dispatched_events << [name, opts]
44
42
  super(name, opts)
45
43
  end
46
44
 
47
45
  def self.run
48
- self.instances.each do |i|
49
- i.connection_open = true
50
- end
46
+ @@instances.each { |i| i.connection_open = true }
51
47
  end
52
48
 
53
49
  def self.stop
54
- self.instances.each do |i|
55
- i.connection_open = false
56
- end
50
+ @@instances.each { |i| i.connection_open = false }
57
51
  end
58
52
 
59
53
  def self.add_reconnect(opts = {})
60
- Marvin::Logger.info "Added reconnect with options: #{opts.inspect}"
54
+ logger.info "Added reconnect with options: #{opts.inspect}"
61
55
  end
62
56
 
63
57
  end
data/lib/marvin/util.rb CHANGED
@@ -12,7 +12,8 @@ module Marvin
12
12
  # appending "#" to the front if it doesn't already
13
13
  # start with it.
14
14
  def channel_name(name)
15
- return name.to_s[0..0] == "#" ? name.to_s : "##{name}"
15
+ name = name.to_s
16
+ name =~ /^\#/ ? name : "##{name}"
16
17
  end
17
18
  alias chan channel_name
18
19
 
@@ -26,8 +27,14 @@ module Marvin
26
27
  # Specifies the last parameter of a response, used to
27
28
  # specify parameters which have spaces etc (for example,
28
29
  # the actual message part of a response).
29
- def last_param(section)
30
- section && ":#{section.to_s.strip}"
30
+ def last_param(section, ignore_prefix = true)
31
+ content = section.to_s.strip
32
+ return if content.blank?
33
+ if content =~ /\s+/ && (ignore_prefix || content !~ /^:/)
34
+ ":#{content}"
35
+ else
36
+ content
37
+ end
31
38
  end
32
39
  alias lp last_param
33
40
 
data/lib/marvin.rb CHANGED
@@ -1,53 +1,56 @@
1
- $:.unshift File.dirname(__FILE__) # Append the current working dir to the front of the line.
2
-
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
2
  require 'rubygems'
4
- require 'active_support'
5
- require 'marvin/core_ext'
6
-
7
- # Make all exceptions available
8
- require 'marvin/exceptions'
3
+ require 'perennial'
9
4
 
10
5
  module Marvin
11
- module VERSION
12
- MAJOR = 0
13
- MINOR = 3
14
- PATCH = 2
15
-
16
- STRING = [MAJOR, MINOR, PATCH].join(".")
17
- end
6
+ include Perennial
7
+
8
+ VERSION = [0, 8, 0, 0]
18
9
 
19
- autoload :Util, 'marvin/util'
20
- autoload :Dispatchable, 'marvin/dispatchable'
10
+ # Misc.
11
+ #autoload :Util, 'marvin/util'
12
+ # Client
13
+ #autoload :AbstractClient, 'marvin/abstract_client'
14
+ #autoload :IRC, 'marvin/irc'
15
+ autoload :TestClient, 'marvin/test_client'
16
+ # Console of DOOM.
17
+ autoload :Console, 'marvin/console'
18
+ # Distributed
21
19
  autoload :Distributed, 'marvin/distributed'
22
- autoload :AbstractClient, 'marvin/abstract_client'
20
+ autoload :Status, 'marvin/status'
21
+ # Handler
23
22
  autoload :Base, 'marvin/base'
24
- autoload :Console, 'marvin/console'
25
- autoload :CoreCommands, 'marvin/core_commands'
26
- autoload :ClientMixin, 'marvin/client_mixin'
27
- autoload :Settings, 'marvin/settings'
28
- autoload :Logger, 'marvin/logger'
23
+ autoload :CommandHandler, 'marvin/command_handler'
29
24
  autoload :LoggingHandler, 'marvin/logging_handler'
30
- autoload :IRC, 'marvin/irc'
31
- autoload :TestClient, 'marvin/test_client'
32
- autoload :Loader, 'marvin/loader'
25
+ autoload :CoreCommands, 'marvin/core_commands'
33
26
  autoload :MiddleMan, 'marvin/middle_man'
34
- autoload :DRBHandler, 'marvin/drb_handler'
35
- autoload :DataStore, 'marvin/data_store'
36
- autoload :ExceptionTracker, 'marvin/exception_tracker'
37
- autoload :Options, 'marvin/options'
38
- autoload :Daemon, 'marvin/daemon'
39
- autoload :Status, 'marvin/status'
40
- # Parsers
41
- autoload :AbstractParser, 'marvin/abstract_parser'
42
- autoload :Parsers, 'marvin/parsers.rb'
27
+ # These should be namespaced under IRC
28
+ #autoload :AbstractParser, 'marvin/abstract_parser'
29
+ autoload :Parsers, 'marvin/parsers'
43
30
 
44
- # Default Handlers
45
- autoload :CommandHandler, 'marvin/command_handler'
46
31
 
47
- Settings.setup # Load Settings etc.
32
+ manifest do |m, l|
33
+ Settings.root = File.dirname(File.dirname(__FILE__))
34
+ l.register_controller :client, 'Marvin::Settings.client'
35
+ l.register_controller :console, 'Marvin::Console'
36
+ l.register_controller :distributed_client, 'Marvin::Distributed::Client'
37
+ # Core Commands handily makes available a set
38
+ # of information about what is running etc.
39
+
40
+ l.before_run do
41
+ if l.distributed_client?
42
+ Marvin::Settings.client = Marvin::Distributed::Client
43
+ end
44
+ end
45
+
46
+ end
48
47
 
49
- def self.version
50
- VERSION::STRING
48
+ def self.version(include_minor = false)
49
+ VERSION[0, (include_minor ? 4 : 3)].join(".")
51
50
  end
52
51
 
52
+ has_library :util, :abstract_client, :abstract_parser, :irc, :exception_tracker
53
+
54
+ extends_library :settings
55
+
53
56
  end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'marvin'
3
+ Marvin::Settings.root = Pathname.new(__FILE__).dirname.join("..").expand_path
@@ -0,0 +1,10 @@
1
+ "irc.freenode.net":
2
+ port: 6667
3
+ channels:
4
+ - "#marvin-testing"
5
+
6
+ "irc.oftc.net":
7
+ port: 6697
8
+ ssl: true
9
+ channels:
10
+ - "#marvin-testing"
@@ -0,0 +1,5 @@
1
+ # Use this class to debug stuff as you
2
+ # go along - e.g. dump events etc.
3
+ class DebugHandler < Marvin::CommandHandler
4
+
5
+ end