mod_spox 0.1.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/CHANGELOG +36 -0
  2. data/INSTALL +2 -2
  3. data/README +0 -1
  4. data/bin/mod_spox +51 -12
  5. data/data/mod_spox/extras/AOLSpeak.rb +5 -18
  6. data/data/mod_spox/extras/AutoKick.rb +44 -23
  7. data/data/mod_spox/extras/AutoMode.rb +2 -5
  8. data/data/mod_spox/extras/AutoRejoin.rb +21 -0
  9. data/data/mod_spox/extras/Bouncer.rb +10 -10
  10. data/data/mod_spox/extras/Bytes.rb +12 -0
  11. data/data/mod_spox/extras/Confess.rb +131 -52
  12. data/data/mod_spox/extras/DCC.rb +189 -0
  13. data/data/mod_spox/extras/DevWatch.rb +32 -33
  14. data/data/mod_spox/extras/FloodKicker.rb +129 -0
  15. data/data/mod_spox/extras/GoogleIt.rb +13 -0
  16. data/data/mod_spox/extras/Headers.rb +31 -4
  17. data/data/mod_spox/extras/Karma.rb +103 -49
  18. data/data/mod_spox/extras/Logger.rb +45 -30
  19. data/data/mod_spox/extras/LolSpeak.rb +1 -1
  20. data/data/mod_spox/extras/NickServ.rb +83 -0
  21. data/data/mod_spox/extras/PhpCli.rb +12 -15
  22. data/data/mod_spox/extras/PhpFuncLookup.rb +57 -25
  23. data/data/mod_spox/extras/Quotes.rb +5 -4
  24. data/data/mod_spox/extras/RegexTracker.rb +160 -0
  25. data/data/mod_spox/extras/Roulette.rb +22 -23
  26. data/data/mod_spox/extras/Search.rb +3 -2
  27. data/data/mod_spox/extras/Slashdot.rb +35 -0
  28. data/data/mod_spox/extras/Topten.rb +5 -5
  29. data/data/mod_spox/extras/TracTicket.rb +68 -0
  30. data/data/mod_spox/extras/Translate.rb +69 -30
  31. data/data/mod_spox/extras/Twitter.rb +372 -0
  32. data/data/mod_spox/extras/UrbanDictionary.rb +21 -12
  33. data/data/mod_spox/extras/Weather.rb +1 -1
  34. data/data/mod_spox/plugins/Authenticator.rb +63 -30
  35. data/data/mod_spox/plugins/Banner.rb +164 -151
  36. data/data/mod_spox/plugins/Helper.rb +18 -7
  37. data/data/mod_spox/plugins/PluginLoader.rb +46 -22
  38. data/data/mod_spox/plugins/PoolConfig.rb +52 -0
  39. data/data/mod_spox/plugins/Quitter.rb +1 -1
  40. data/data/mod_spox/plugins/Status.rb +28 -0
  41. data/lib/mod_spox/Action.rb +20 -3
  42. data/lib/mod_spox/BaseConfig.rb +1 -0
  43. data/lib/mod_spox/Bot.rb +98 -75
  44. data/lib/mod_spox/BotConfig.rb +14 -6
  45. data/lib/mod_spox/ConfigurationWizard.rb +94 -105
  46. data/lib/mod_spox/Database.rb +33 -13
  47. data/lib/mod_spox/Helpers.rb +67 -38
  48. data/lib/mod_spox/Loader.rb +25 -5
  49. data/lib/mod_spox/Logger.rb +20 -62
  50. data/lib/mod_spox/MessageFactory.rb +34 -25
  51. data/lib/mod_spox/Monitors.rb +5 -0
  52. data/lib/mod_spox/Pipeline.rb +40 -51
  53. data/lib/mod_spox/Plugin.rb +40 -9
  54. data/lib/mod_spox/PluginManager.rb +46 -38
  55. data/lib/mod_spox/Pool.rb +129 -143
  56. data/lib/mod_spox/Socket.rb +41 -50
  57. data/lib/mod_spox/Sockets.rb +211 -0
  58. data/lib/mod_spox/Timer.rb +86 -69
  59. data/lib/mod_spox/handlers/BadNick.rb +1 -1
  60. data/lib/mod_spox/handlers/Created.rb +1 -1
  61. data/lib/mod_spox/handlers/Handler.rb +9 -0
  62. data/lib/mod_spox/handlers/Invite.rb +1 -1
  63. data/lib/mod_spox/handlers/Join.rb +2 -2
  64. data/lib/mod_spox/handlers/Kick.rb +1 -1
  65. data/lib/mod_spox/handlers/LuserChannels.rb +1 -1
  66. data/lib/mod_spox/handlers/LuserOp.rb +1 -1
  67. data/lib/mod_spox/handlers/LuserUnknown.rb +1 -1
  68. data/lib/mod_spox/handlers/Mode.rb +2 -2
  69. data/lib/mod_spox/handlers/MyInfo.rb +1 -1
  70. data/lib/mod_spox/handlers/Names.rb +1 -1
  71. data/lib/mod_spox/handlers/Nick.rb +20 -3
  72. data/lib/mod_spox/handlers/NickInUse.rb +3 -3
  73. data/lib/mod_spox/handlers/Notice.rb +5 -15
  74. data/lib/mod_spox/handlers/Part.rb +1 -1
  75. data/lib/mod_spox/handlers/Ping.rb +1 -1
  76. data/lib/mod_spox/handlers/Pong.rb +1 -1
  77. data/lib/mod_spox/handlers/Privmsg.rb +2 -2
  78. data/lib/mod_spox/handlers/Quit.rb +1 -1
  79. data/lib/mod_spox/handlers/Topic.rb +2 -1
  80. data/lib/mod_spox/handlers/Welcome.rb +3 -3
  81. data/lib/mod_spox/handlers/Who.rb +9 -7
  82. data/lib/mod_spox/handlers/Whois.rb +29 -16
  83. data/lib/mod_spox/handlers/YourHost.rb +1 -1
  84. data/lib/mod_spox/messages/incoming/Privmsg.rb +38 -19
  85. data/lib/mod_spox/messages/internal/DCCListener.rb +12 -0
  86. data/lib/mod_spox/messages/internal/DCCRequest.rb +12 -0
  87. data/lib/mod_spox/messages/internal/DCCSocket.rb +19 -0
  88. data/lib/mod_spox/messages/internal/StatusRequest.rb +2 -1
  89. data/lib/mod_spox/messages/outgoing/Privmsg.rb +21 -5
  90. data/lib/mod_spox/migrations/001_initialize_models.rb +115 -0
  91. data/lib/mod_spox/models/Auth.rb +24 -16
  92. data/lib/mod_spox/models/AuthGroup.rb +4 -3
  93. data/lib/mod_spox/models/Channel.rb +20 -12
  94. data/lib/mod_spox/models/ChannelMode.rb +2 -2
  95. data/lib/mod_spox/models/Config.rb +11 -3
  96. data/lib/mod_spox/models/Group.rb +6 -1
  97. data/lib/mod_spox/models/Nick.rb +93 -33
  98. data/lib/mod_spox/models/NickChannel.rb +8 -6
  99. data/lib/mod_spox/models/NickGroup.rb +16 -0
  100. data/lib/mod_spox/models/NickMode.rb +3 -3
  101. data/lib/mod_spox/models/Server.rb +6 -2
  102. data/lib/mod_spox/models/Setting.rb +12 -6
  103. data/lib/mod_spox/models/Signature.rb +7 -13
  104. data/lib/mod_spox/models/Trigger.rb +1 -1
  105. metadata +125 -100
@@ -1,77 +1,35 @@
1
- require 'mod_spox/Pool'
2
-
1
+ require 'logger'
3
2
  module ModSpox
4
3
 
5
4
  class Logger
6
-
7
- def self.do_initialization
8
- Logger.fd(nil) unless Logger.class_variable_defined?(:@@fd)
9
- Logger.severity unless Logger.class_variable_defined?(:@@severity)
10
- @@lock = Mutex.new unless Logger.class_variable_defined?(:@@lock)
11
- @@lock.synchronize do
12
- @@writer = LogWriter.new(@@fd) unless Logger.class_variable_defined?(:@@writer)
13
- @@initialized = true
14
- end
15
- end
16
-
17
- # severity:: minimum severity for visible logging
18
- # Sets the maximum level of visible logs
19
- def self.severity(severity=1)
20
- @@severity = severity
21
- end
22
-
23
- # filedes:: file descriptor to log to
24
- # Sets the file descriptor for logging. By default
25
- # logs will be sent to STDOUT
26
- def self.fd(filedes=nil)
27
- @@fd = filedes.nil? ? $stdout : filedes
28
- end
29
-
30
- # message:: message to log
31
- # severity:: severity level (lower is more severe)
32
- # Log a message. It is important to note that the lower the
33
- # severity level of a message, the better chance it has of
34
- # being outputted
35
- def self.log(message, severity=1)
36
- do_initialization unless Logger.class_variable_defined?(:@@initialized)
37
- @@writer.log(message) unless @@severity < severity
38
- end
39
-
40
- def self.kill
41
- @@writer.kill
42
- end
43
-
44
- end
45
-
46
- class LogWriter
47
-
48
- attr_reader :fd
49
5
 
50
- def initialize(fd)
51
- @fd = fd
52
- @kill = false
53
- @queue = Queue.new
54
- @thread = Thread.new do
55
- until(@kill)
56
- processor
57
- end
6
+ def Logger.initialize(output=nil, level=:fatal)
7
+ if(output.nil?)
8
+ @@log = nil
9
+ else
10
+ levels = {:info => Object::Logger::INFO, :warn => Object::Logger::WARN, :fatal => Object::Logger::FATAL}
11
+ @@log = Object::Logger.new(output)
12
+ @@log.level = levels.has_key?(level) ? levels[level] : Object::Logger::WARN
58
13
  end
59
14
  end
60
15
 
61
- def kill
62
- @kill = true
63
- @queue << "Logger has been told to shut down"
16
+ def Logger.warn(s)
17
+ unless @@log.nil?
18
+ Pool << lambda{@@log.warn(s)}
19
+ end
64
20
  end
65
21
 
66
- def log(message)
67
- @queue << message
22
+ def Logger.info(s)
23
+ unless @@log.nil?
24
+ Pool << lambda{@@log.info(s)}
25
+ end
68
26
  end
69
27
 
70
- def processor
71
- message = @queue.pop
72
- @fd.puts("LOGGER [#{Time.now}]: #{message}")
28
+ def Logger.fatal(s)
29
+ unless @@log.nil?
30
+ Pool << lambda{@@log.fatal(s)}
31
+ end
73
32
  end
74
33
 
75
34
  end
76
-
77
35
  end
@@ -5,27 +5,30 @@
5
5
 
6
6
  module ModSpox
7
7
 
8
- class MessageFactory < Pool
9
-
8
+ class MessageFactory
9
+
10
10
  # pipeline:: Message pipeline
11
11
  # Create a new MessageFactory
12
12
  def initialize(pipeline)
13
- super()
14
13
  @pipeline = pipeline
15
14
  @handlers = Hash.new
16
- Logger.log("Created new factory queue: #{@queue}", 15)
15
+ @lock = Mutex.new
17
16
  build_handlers
18
- start_pool
17
+ @sync = [RPL_MOTDSTART, RPL_MOTD, RPL_ENDOFMOTD, RPL_WHOREPLY, RPL_ENDOFWHO,
18
+ RPL_NAMREPLY, RPL_ENDOFNAMES, RPL_WHOISUSER, RPL_WHOISSERVER, RPL_WHOISOPERATOR,
19
+ RPL_WHOISIDLE, RPL_WHOISCHANNELS, RPL_WHOISIDENTIFIED, RPL_ENDOFWHOIS]
19
20
  end
20
-
21
+
21
22
  # string:: server message to be parsed
22
23
  # Parses messages from server. This is placed in a queue to
23
24
  # be processed thus there is now wait for processing to be
24
25
  # completed.
25
26
  def <<(string)
26
- @queue << string
27
+ Pool << lambda{ parse_message(string) }
27
28
  end
28
-
29
+
30
+ private
31
+
29
32
  # Builds the message handlers. This will load all Messages and Handlers
30
33
  # found in the lib directory and then initialize all the Handlers
31
34
  def build_handlers
@@ -35,43 +38,49 @@ module ModSpox
35
38
  Handlers.constants.each{|name|
36
39
  klass = Handlers.const_get(name)
37
40
  if(klass < Handlers::Handler)
38
- Logger.log("Building handler: #{name}")
41
+ Logger.info("Building handler: #{name}")
39
42
  begin
40
43
  klass.new(@handlers)
41
44
  rescue Object => boom
42
- Logger.log("ERROR: Failed to build handler: #{name} -> #{boom}")
45
+ Logger.warn("ERROR: Failed to build handler: #{name} -> #{boom}")
43
46
  end
44
47
  end
45
48
  }
46
- Logger.log("Handlers now available:", 15)
47
- @handlers.each_pair{|k,v| Logger.log("#{k} -> #{v}", 15)}
49
+ Logger.info("Handlers now available:")
50
+ @handlers.each_pair{|k,v| Logger.info("#{k} -> #{v}")}
48
51
  end
49
-
52
+
50
53
  # message:: server message
51
54
  # Parses the server message and passes it to the proper handler
52
55
  def parse_message(message)
53
- Logger.log("Processing message: #{message}", 15)
56
+ Logger.info("Processing message: #{message}")
54
57
  begin
55
58
  if(message =~ /^:\S+ (\S+)/ || message =~ /^([A-Za-z0-9]+)\s/)
56
59
  key = $1
57
60
  key = key.to_sym unless key[0].chr =~ /\d/
58
61
  if(@handlers.has_key?(key))
59
- Logger.log("Message of type #{key} is now being handled by #{@handlers[key]}", 10)
60
- message = @handlers[key].process(message)
61
- @pipeline << message unless message.nil?
62
+ Logger.info("Message of type #{key} is now being handled by #{@handlers[key]}")
63
+ if(@sync.include?(key))
64
+ Logger.info("Message of type #{key} requires synchronized processing")
65
+ Pool << lambda do
66
+ @lock.synchronize do
67
+ message = @handlers[key].process(message)
68
+ @pipeline << message unless message.nil?
69
+ end
70
+ end
71
+ else
72
+ Pool << lambda do
73
+ message = @handlers[key].process(message)
74
+ @pipeline << message unless message.nil?
75
+ end
76
+ end
62
77
  end
63
78
  end
64
79
  rescue Object => boom
65
- Logger.log("Failed to parse message from server: #{boom}\n#{boom.backtrace.join("\n")}")
80
+ Logger.warn("Failed to parse message from server: #{boom}\n#{boom.backtrace.join("\n")}")
66
81
  end
67
82
  end
68
-
69
- private
70
-
71
- def processor
72
- parse_message(@queue.pop)
73
- end
74
-
83
+
75
84
  end
76
85
 
77
86
  end
@@ -72,6 +72,11 @@ module ModSpox
72
72
  def remove_thread(thread)
73
73
  @threads.delete(thread) if @threads.include?(thread)
74
74
  end
75
+
76
+ # Returns the number of threads currently waiting in this monitor
77
+ def count
78
+ @threads.size
79
+ end
75
80
 
76
81
  end
77
82
  end
@@ -4,13 +4,10 @@
4
4
  'mod_spox/Exceptions'].each{|f|require f}
5
5
  module ModSpox
6
6
 
7
- class Pipeline < Pool
7
+ class Pipeline
8
8
 
9
9
  # Create a new Pipeline
10
10
  def initialize
11
- super()
12
- @timeout = 20 # Anything over 20 seconds and we assume a plugin locked up the thread
13
- Logger.log("Created queue #{@queue} in pipeline", 10)
14
11
  @hooks = Hash.new
15
12
  @plugins = Hash.new
16
13
  @admin = Models::Group.filter(:name => 'admin').first
@@ -19,54 +16,53 @@ module ModSpox
19
16
  populate_signatures
20
17
  hook(self, :populate_triggers, :Internal_TriggersUpdate)
21
18
  hook(self, :populate_signatures, :Internal_SignaturesUpdate)
22
- start_pool
23
19
  end
24
-
20
+
25
21
  # message:: Message to send down pipeline
26
22
  # Queues a message to send down pipeline
27
23
  def <<(message)
28
- Logger.log("Message added to pipeline queue: #{message}", 5)
29
- @queue << message
24
+ Logger.info("Message added to pipeline queue: #{message}")
25
+ message_processor(message)
30
26
  end
31
-
27
+
32
28
  # plugin:: Plugin to hook to pipeline
33
29
  # Hooks a plugin into the pipeline so it can be called
34
30
  # directly when it matches a trigger
35
31
  def hook_plugin(plugin)
36
- Logger.log("Plugin #{plugin.name} hooking into pipeline", 10)
32
+ Logger.info("Plugin #{plugin.name} hooking into pipeline")
37
33
  @plugins[plugin.name.to_sym] = plugin
38
34
  end
39
-
35
+
40
36
  # plugin:: Plugin to unhook from pipeline
41
37
  # Unhooks a plugin from the pipeline (This does not unhook
42
38
  # it from the standard hooks)
43
39
  def unhook_plugin(plugin)
44
- Logger.log("Plugin #{plugin.name} unhooking from pipeline", 10)
40
+ Logger.info("Plugin #{plugin.name} unhooking from pipeline")
45
41
  @plugins.delete(plugin.name.to_sym)
46
42
  @hooks.each_pair do |type, things|
47
43
  things.delete(plugin.name.to_sym) if things.has_key?(plugin.name.to_sym)
48
44
  end
49
45
  end
50
-
46
+
51
47
  # plugin:: Plugin to hook to pipeline
52
48
  # method:: Plugin method pipeline should call to process message
53
49
  # type:: Type of message the plugin wants to process
54
50
  # Hooks a plugin into the pipeline for a specific type of message
55
51
  def hook(object, method, type)
56
- Logger.log("Object #{object.class.to_s} hooking into messages of type: #{type}", 10)
52
+ Logger.info("Object #{object.class.to_s} hooking into messages of type: #{type}")
57
53
  type = type.gsub(/::/, '_').to_sym unless type.is_a?(Symbol)
58
54
  method = method.to_sym unless method.is_a?(Symbol)
59
55
  name = object.class.to_s.gsub(/^.+:/, '')
60
56
  @hooks[type] = Hash.new unless @hooks.has_key?(type)
61
57
  @hooks[type][name.to_sym] = Array.new unless @hooks[type][name.to_sym].is_a?(Array)
62
- @hooks[type][name.to_sym] << {:object => object, :method => method}
58
+ @hooks[type][name.to_sym] << {:object => object, :method => method}
63
59
  end
64
-
60
+
65
61
  # plugin:: Plugin to unhook from pipeline
66
62
  # type:: Type of message the plugin no longer wants to process
67
63
  # This will remove the hook a plugin has for a specific message type
68
64
  def unhook(object, method, type)
69
- Logger.log("Object #{object.class.to_s} unhooking from messages of type: #{type}", 10)
65
+ Logger.info("Object #{object.class.to_s} unhooking from messages of type: #{type}")
70
66
  type = type.gsub(/::/, '_').to_sym unless type.is_a?(Symbol)
71
67
  name = object.class.to_s.gsub(/^.+:/, '').to_sym
72
68
  raise Exceptions::InvalidValue.new("Unknown hook type given: #{type.to_s}") unless @hooks.has_key?(type)
@@ -77,14 +73,14 @@ module ModSpox
77
73
  @hooks[type].delete(name) if @hooks[type][name].empty
78
74
  @hooks.delete(type) if @hooks[type].empty?
79
75
  end
80
-
76
+
81
77
  # Clears all hooks from the pipeline (Commonly used when reloading plugins)
82
78
  def clear
83
- Logger.log("All hooks have been cleared from pipeline", 10)
79
+ Logger.info("All hooks have been cleared from pipeline")
84
80
  @hooks.clear
85
81
  @plugins.clear
86
82
  end
87
-
83
+
88
84
  # Repopulate the active trigger list
89
85
  def populate_triggers(m=nil)
90
86
  @populate_lock.synchronize do
@@ -92,13 +88,12 @@ module ModSpox
92
88
  Models::Trigger.filter(:active => true).each{|t|@triggers << t.trigger}
93
89
  end
94
90
  end
95
-
91
+
96
92
  # Repopulate the active signatures list
97
93
  def populate_signatures(m=nil)
98
94
  @populate_lock.synchronize do
99
95
  @signatures = {}
100
96
  Models::Signature.all.each do |s|
101
- Logger.log("Signature being processed: #{s.signature}")
102
97
  c = s.signature[0].chr.downcase
103
98
  if(c =~ /^[a-z]$/)
104
99
  type = c.to_sym
@@ -114,49 +109,46 @@ module ModSpox
114
109
  end
115
110
  end
116
111
  end
117
-
112
+
118
113
  private
119
-
114
+
120
115
  # Processes messages
121
- def processor
122
- message = @queue.pop
116
+ def message_processor(message)
123
117
  begin
124
- Logger.log("Pipeline is processing a message: #{message}", 10)
118
+ Logger.info("Pipeline is processing a message: #{message}")
125
119
  parse(message)
126
- type = message.class.to_s.gsub(/^ModSpox::Messages::/, '').gsub(/::/, '_').to_sym
120
+ type = message.class.to_s.gsub(/^(ModSpox::Messages::|#<.+?>::)/, '').gsub(/::/, '_').to_sym
127
121
  mod = type.to_s.gsub(/_.+$/, '').to_sym
128
- Logger.log("Pipeline determines that #{message} is of type: #{type}", 10)
122
+ Logger.info("Pipeline determines that #{message} is of type: #{type}")
129
123
  [type, mod, :all].each do |type|
130
124
  if(@hooks.has_key?(type))
131
125
  @hooks[type].each_value do |objects|
132
126
  begin
133
- Timeout::timeout(@timeout) do
134
- objects.each{|v| v[:object].send(v[:method].to_s, message) }
127
+ objects.each do |v|
128
+ Pool << lambda{ v[:object].send(v[:method].to_s, message) }
135
129
  end
136
- rescue Timeout::Error => boom
137
- Logger.log('Timeout reached while waiting for plugin to complete task')
138
130
  rescue Object => boom
139
- Logger.log("Plugin threw exception while attempting to process message: #{boom}\n#{boom.backtrace.join("\n")}")
131
+ Logger.warn("Plugin threw exception while attempting to process message: #{boom}\n#{boom.backtrace.join("\n")}")
140
132
  end
141
133
  end
142
134
  end
143
135
  end
144
136
  rescue Object => boom
145
- Logger.log("Pipeline encountered an exception while processing a message: #{boom}\n#{boom.backtrace.join("\n")}", 10)
137
+ Logger.warn("Pipeline encountered an exception while processing a message: #{boom}\n#{boom.backtrace.join("\n")}")
146
138
  end
147
139
  end
148
-
140
+
149
141
  # message:: Message to parse
150
142
  # This will parse a message to see if it matches any valid
151
143
  # trigger signatures. If matches are found, they will be sent
152
- # to the proper plugin for processing
144
+ # to the proper plugin for processing
153
145
  def parse(message)
154
146
  return unless message.kind_of?(Messages::Incoming::Privmsg) || message.kind_of?(Messages::Incoming::Notice)
155
147
  trigger = nil
156
148
  @triggers.each{|t| trigger = t if message.message =~ /^#{Regexp.escape(t)}/}
157
149
  if(!trigger.nil? || message.addressed?)
158
150
  return if !trigger.nil? && message.message.length == trigger.length
159
- Logger.log("Message has matched against a known trigger", 15)
151
+ Logger.info("Message has matched against a known trigger")
160
152
  c = (message.addressed? && trigger.nil?) ? message.message[0].chr.downcase : message.message[trigger.length].chr.downcase
161
153
  if(c =~ /^[a-z]$/)
162
154
  type = c.to_sym
@@ -165,38 +157,35 @@ module ModSpox
165
157
  else
166
158
  type = :other
167
159
  end
168
- return unless @signatures[type]
169
- @signatures[type].each do |sig|
170
- Logger.log("Matching against: #{trigger}#{sig.signature}")
160
+ sig_check = @signatures.has_key?(type) ? @signatures[type] : []
161
+ sig_check = sig_check + @signatures[:other] if type != :other && @signatures.has_key?(:other)
162
+ sig_check.each do |sig|
163
+ Logger.info("Matching against: #{trigger}#{sig.signature}")
171
164
  esc_trig = trigger.nil? ? '' : Regexp.escape(trigger)
172
165
  res = message.message.scan(/^#{esc_trig}#{sig.signature}$/)
173
166
  if(res.size > 0)
174
- next unless message.source.auth_groups.include?(sig.group) || message.source.auth_groups.include?(@admin) ||sig.group.nil?
167
+ next unless message.source.auth_groups.include?(sig.group) || message.source.auth_groups.include?(@admin) || sig.group.nil?
175
168
  next if sig.requirement == 'private' && message.is_public?
176
169
  next if sig.requirement == 'public' && message.is_private?
177
170
  params = Hash.new
178
171
  sig.params.size.times do |i|
179
172
  params[sig.params[i].to_sym] = res[0][i]
180
- Logger.log("Signature params: #{sig.params[i].to_sym} = #{res[0][i]}")
173
+ Logger.info("Signature params: #{sig.params[i].to_sym} = #{res[0][i]}")
181
174
  end
182
175
  if(@plugins.has_key?(sig.plugin.to_sym))
183
176
  begin
184
- Timeout::timeout(@timeout) do
185
- @plugins[sig.plugin.to_sym].send(sig.values[:method], message, params)
186
- end
187
- rescue Timeout::Error => boom
188
- Logger.log('Timeout reached while waiting for plugin to complete task')
177
+ Pool << lambda{ @plugins[sig.plugin.to_sym].send(sig.values[:method], message, params) }
189
178
  rescue Object => boom
190
- Logger.log("Plugin threw exception while attempting to process message: #{boom}\n#{boom.backtrace.join("\n")}")
179
+ Logger.warn("Plugin threw exception while attempting to process message: #{boom}\n#{boom.backtrace.join("\n")}")
191
180
  end
192
181
  end
193
182
  end
194
183
  end
195
184
  else
196
- Logger.log("Message failed to match any known trigger", 15)
185
+ Logger.info("Message failed to match any known trigger")
197
186
  end
198
187
  end
199
-
188
+
200
189
  end
201
190
 
202
191
  end
@@ -3,22 +3,24 @@
3
3
  'mod_spox/Exceptions'].each{|f|require f}
4
4
  module ModSpox
5
5
  class Plugin
6
- def initialize(pipeline)
7
- raise Exceptions::BotException.new('Plugin creation failed to supply message pipeline') unless pipeline.is_a?(Pipeline)
8
- @pipeline = pipeline
6
+ include Models
7
+ def initialize(args)
8
+ @pipeline = args[:pipeline]
9
+ @plugin_module = args[:plugin_module]
10
+ raise Exceptions::BotException.new('Plugin creation failed to supply message pipeline') unless @pipeline.is_a?(Pipeline)
9
11
  @pipeline.hook_plugin(self)
10
12
  end
11
-
13
+
12
14
  # Called before the object is destroyed by the ModSpox::PluginManager
13
15
  def destroy
14
- Logger.log("Destroy method for plugin #{name} has not been defined.", 15)
16
+ Logger.info("Destroy method for plugin #{name} has not been defined.")
15
17
  end
16
-
18
+
17
19
  # Returns the name of the class
18
20
  def name
19
21
  self.class.name.to_s.gsub(/^.+:/, '')
20
22
  end
21
-
23
+
22
24
  # target:: target for message
23
25
  # message:: string message
24
26
  # This is a helper method that will send an outgoing Privmsg
@@ -26,7 +28,7 @@ module ModSpox
26
28
  def reply(target, message)
27
29
  @pipeline << Messages::Outgoing::Privmsg.new(target, message)
28
30
  end
29
-
31
+
30
32
  # Returns the nick model of the bot
31
33
  def me
32
34
  nick = Models::Nick.filter(:botnick => true).first
@@ -36,6 +38,35 @@ module ModSpox
36
38
  raise Exception.new("Fatal Error: I don't know who I am.")
37
39
  end
38
40
  end
39
-
41
+
42
+ # Returns constant given from plugin module. Raises ModSpox::Exceptions::InvalidType
43
+ # exception if constant is not found within the module
44
+ # Note: Use _ for depth (ie: Foo::Bar::Fee if Fee is wanted give: :Foo_Bar_Fee)
45
+ def plugin_const(const)
46
+ klass = @plugin_module
47
+ begin
48
+ const.to_s.split('_').each do |part|
49
+ klass = klass.const_get(part.to_sym)
50
+ end
51
+ rescue NameError => boom
52
+ raise ModSpox::Exceptions::InvalidType.new("Requested constant has not been defined within the plugins module (#{const}): #{boom}")
53
+ end
54
+ if(klass.nil?)
55
+ raise ModSpox::Exceptions::InvalidType.new("Requested constant has not been defined within the plugins module (#{const})")
56
+ else
57
+ return klass
58
+ end
59
+ end
60
+
61
+ def add_sig(args)
62
+ raise ModSpox::Exceptions::InvalidType.new('You must provide a hash for creating new signatures') unless args.is_a?(Hash)
63
+ sig = Signature.find_or_create(:signature => args[:sig], :plugin => name, :method => args[:method].to_s)
64
+ sig.description = args[:desc] if args.has_key?(:desc)
65
+ sig.group_id = args[:group].pk if args.has_key?(:group)
66
+ sig.requirement = args[:req] if args.has_key?(:req)
67
+ sig.params = args[:params] if args.has_key?(:params)
68
+ sig.save
69
+ end
70
+
40
71
  end
41
72
  end