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
@@ -8,10 +8,10 @@
8
8
  module ModSpox
9
9
 
10
10
  class PluginManager
11
-
11
+
12
12
  # Hash of plugins. Defined by class name symbol (i.e. Trivia class: plugins[:Trivia])
13
13
  attr_reader :plugins
14
-
14
+
15
15
  # pipeline:: Pipeline for messages
16
16
  # Create new PluginManager
17
17
  def initialize(pipeline)
@@ -26,7 +26,7 @@ module ModSpox
26
26
  @plugin_lock = Mutex.new
27
27
  load_plugins
28
28
  end
29
-
29
+
30
30
  # message:: Messages::Internal::PluginReload
31
31
  # Destroys and reinitializes plugins
32
32
  def reload_plugins(message=nil)
@@ -36,7 +36,7 @@ module ModSpox
36
36
  FileUtils.remove_file(message.stale)
37
37
  FileUtils.copy(message.fresh, BotConfig[:userpluginpath])
38
38
  do_load(message.stale)
39
- Logger.log("Completed reload of plugin: #{message.stale}")
39
+ Logger.info("Completed reload of plugin: #{message.stale}")
40
40
  else
41
41
  unload_plugins
42
42
  load_plugins
@@ -44,12 +44,12 @@ module ModSpox
44
44
  @pipeline << Messages::Internal::SignaturesUpdate.new
45
45
  end
46
46
  end
47
-
47
+
48
48
  # Destroys plugins
49
49
  def destroy_plugins
50
50
  unload_plugins
51
51
  end
52
-
52
+
53
53
  # message:: Messages::Internal::PluginLoadRequest
54
54
  # Loads a plugin
55
55
  def load_plugin(message)
@@ -62,14 +62,14 @@ module ModSpox
62
62
  end
63
63
  do_load(path)
64
64
  @pipeline << Messages::Internal::PluginLoadResponse.new(message.requester, true)
65
- Logger.log("Loaded new plugin: #{message.path}", 10)
65
+ Logger.info("Loaded new plugin: #{message.path}")
66
66
  rescue Object => boom
67
- Logger.log("Failed to load plugin: #{message.path} Reason: #{boom}", 10)
67
+ Logger.warn("Failed to load plugin: #{message.path} Reason: #{boom}")
68
68
  @pipeline << Messages::Internal::PluginLoadResponse.new(message.requester, false)
69
69
  end
70
70
  @pipeline << Messages::Internal::SignaturesUpdate.new
71
71
  end
72
-
72
+
73
73
  # message:: Messages::Internal::PluginUnloadRequest
74
74
  # Unloads a plugin
75
75
  def unload_plugin(message)
@@ -82,20 +82,20 @@ module ModSpox
82
82
  end
83
83
  File.delete(message.path)
84
84
  @pipeline << Messages::Internal::PluginUnloadResponse.new(message.requester, true)
85
- Logger.log("Unloaded plugin: #{message.path}", 10)
85
+ Logger.info("Unloaded plugin: #{message.path}")
86
86
  rescue Object => boom
87
- Logger.log("Failed to unload plugin: #{message.path} Reason: #{boom}", 10)
87
+ Logger.warn("Failed to unload plugin: #{message.path} Reason: #{boom}")
88
88
  @pipeline << Messages::Internal::PluginUnloadResponse.new(message.requester, false)
89
89
  end
90
90
  @pipeline << Messages::Internal::SignaturesUpdate.new
91
91
  end
92
-
92
+
93
93
  # message:: Messages::Internal::PluginModuleRequest
94
94
  # Sends the plugins module to the requester
95
95
  def send_modules(message)
96
96
  @pipeline << Messages::Internal::PluginModuleResponse.new(message.requester, @plugins_module)
97
97
  end
98
-
98
+
99
99
  # message:: Messages::Internal::PluginRequest
100
100
  # Returns a plugin to requesting object
101
101
  def plugin_request(message)
@@ -106,9 +106,13 @@ module ModSpox
106
106
  end
107
107
  @pipeline << response
108
108
  end
109
-
109
+
110
+ def upgrade_plugins
111
+ @plugins[:PluginLoader].plugin.extras_upgrade
112
+ end
113
+
110
114
  private
111
-
115
+
112
116
  # Loads and initializes plugins
113
117
  def load_plugins
114
118
  @pipeline << Messages::Internal::TimerClear.new
@@ -119,25 +123,29 @@ module ModSpox
119
123
  begin
120
124
  do_load("#{path}/#{file}")
121
125
  rescue Object => boom
122
- Logger.log("Failed to load file: #{path}/#{file}. Reason: #{boom}")
126
+ Logger.warn("Failed to load file: #{path}/#{file}. Reason: #{boom}")
123
127
  end
124
128
  end
125
129
  end
126
130
  end
127
131
  @pipeline << Messages::Internal::SignaturesUpdate.new
128
132
  end
129
-
133
+
130
134
  # Destroys plugins
131
135
  def unload_plugins
136
+ Models::Signature.destroy_all
132
137
  @plugins.each_pair do |sym, holder|
133
- holder.plugin.destroy unless holder.plugin.nil?
134
- @pipeline.unhook_plugin(holder.plugin)
138
+ begin
139
+ holder.plugin.destroy unless holder.plugin.nil?
140
+ @pipeline.unhook_plugin(holder.plugin)
141
+ rescue Object => boom
142
+ Logger.warn("Plugin destruction error: #{boom}")
143
+ end
135
144
  end
136
- Models::Signature.destroy_all
137
145
  @plugins_module = Module.new
138
146
  @pipeline << Messages::Internal::TimerClear.new
139
147
  end
140
-
148
+
141
149
  # path:: path to plugin file
142
150
  # Loads a plugin into the plugin module
143
151
  def do_load(path)
@@ -149,46 +157,46 @@ module ModSpox
149
157
  plugins.each do |plugin|
150
158
  klass = @plugins_module.const_get(plugin)
151
159
  if(@plugins.has_key?(plugin.to_sym))
152
- @plugins[plugin.to_sym].set_plugin(klass.new(@pipeline))
160
+ @plugins[plugin.to_sym].set_plugin(klass.new({:pipeline => @pipeline, :plugin_module => @plugins_module}))
153
161
  else
154
- @plugins[plugin.to_sym] = PluginHolder.new(klass.new(@pipeline))
162
+ @plugins[plugin.to_sym] = PluginHolder.new(klass.new({:pipeline => @pipeline, :plugin_module => @plugins_module}))
155
163
  end
156
- Logger.log("Properly initialized new plugin: #{plugin}", 25)
164
+ Logger.info("Properly initialized new plugin: #{plugin}")
157
165
  end
158
- Logger.log("All plugins found at: #{path} have been loaded")
166
+ Logger.info("All plugins found at: #{path} have been loaded")
159
167
  rescue Object => boom
160
- Logger.log("Plugin loading failed: #{boom}\n#{boom.backtrace.join("\n")}", 25)
161
- Logger.log("All constants loaded from file: #{path} will now be unloaded")
168
+ Logger.warn("Plugin loading failed: #{boom}\n#{boom.backtrace.join("\n")}")
169
+ Logger.warn("All constants loaded from file: #{path} will now be unloaded")
162
170
  do_unload(path)
163
171
  end
164
172
  else
165
173
  raise PluginFileNotFound.new("Failed to find file at: #{path}")
166
174
  end
167
175
  end
168
-
176
+
169
177
  # path:: path to plugin file
170
178
  # Unloads a plugin and all constants from the plugin module
171
179
  def do_unload(path)
172
180
  if(File.exists?(path))
173
181
  discover_plugins(path).each do |plugin|
174
182
  if(@plugins.has_key?(plugin.to_sym))
175
- @plugins[plugin.to_sym].plugin.destroy
183
+ @plugins[plugin.to_sym].plugin.destroy unless @plugins[plugin.to_sym].plugin.nil?
176
184
  @pipeline.unhook_plugin(@plugins[plugin.to_sym].plugin)
177
185
  @plugins[plugin.to_sym].set_plugin(nil)
178
186
  @pipeline << Messages::Internal::TimerClear.new(plugin.to_sym)
179
187
  end
180
- Models::Signature.filter(:plugin => plugin).destroy
188
+ Models::Signature.filter(:plugin => plugin.to_s).destroy
181
189
  end
182
190
  discover_consts(path).each do |const|
183
- Logger.log("Removing constant: #{const}")
191
+ Logger.info("Removing constant: #{const}")
184
192
  @plugins_module.send(:remove_const, const)
185
193
  end
186
- Logger.log("Removed all constants found in file: #{path}")
194
+ Logger.info("Removed all constants found in file: #{path}")
187
195
  else
188
196
  raise PluginFileNotFound.new("Failed to find file at: #{path}")
189
197
  end
190
198
  end
191
-
199
+
192
200
  # path:: path to plugin
193
201
  # Find class names of any plugins within the file at given path
194
202
  def discover_plugins(path)
@@ -203,9 +211,9 @@ module ModSpox
203
211
  return klasses
204
212
  rescue Object => boom
205
213
  return nil
206
- end
214
+ end
207
215
  end
208
-
216
+
209
217
  # path:: path to plugin
210
218
  # Find all constant names in given path
211
219
  def discover_consts(path)
@@ -217,13 +225,13 @@ module ModSpox
217
225
  return nil
218
226
  end
219
227
  end
220
-
228
+
221
229
  class PluginMissing < Exceptions::BotException
222
230
  end
223
-
231
+
224
232
  class PluginFileNotFound < Exceptions::BotException
225
233
  end
226
-
234
+
227
235
  end
228
236
 
229
237
  end
data/lib/mod_spox/Pool.rb CHANGED
@@ -1,178 +1,164 @@
1
1
  ['mod_spox/Logger',
2
2
  'mod_spox/Exceptions',
3
- 'mod_spox/Monitors',
4
- 'timeout'].each{|f|require f}
5
-
3
+ 'timeout',
4
+ 'singleton'].each{|f|require f}
5
+
6
6
  module ModSpox
7
7
 
8
+ class PoolThread
9
+ def initialize(pool, timeout)
10
+ @pool = pool
11
+ @timeout = timeout
12
+ @kill = false
13
+ @thread = Thread.new do
14
+ until @kill do
15
+ begin
16
+ action = nil
17
+ if(Pool.workers > Pool.workers_min)
18
+ Timeout::timeout(60) do
19
+ action = @pool.queue.pop
20
+ end
21
+ else
22
+ action = @pool.queue.pop
23
+ end
24
+ run(action) unless action.nil?
25
+ rescue Timeout::Error => boom
26
+ @kill = true
27
+ rescue Object => boom
28
+ Logger.warn("Pool thread error: #{boom}")
29
+ end
30
+ end
31
+ @pool.remove(self)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def run(action)
38
+ begin
39
+ if(@timeout > 0)
40
+ Timeout::timeout(@timeout) do
41
+ action.call
42
+ end
43
+ else
44
+ action.call
45
+ end
46
+ rescue Timeout::Error => boom
47
+ Logger.warn("Pool worker timed out during execution of action (#{@timeout} sec limit): #{action}")
48
+ rescue Object => boom
49
+ Logger.warn("Pool worker caught an unknown exception: #{boom}")
50
+ end
51
+ end
52
+ end
53
+
8
54
  # The Pool class is used to reduce thread creation. It provides
9
55
  # an easy way to process many actions in an asynchronous manner.
10
56
  class Pool
11
57
 
12
- # Action thread is to perform
13
- attr_reader :proc
14
- # Storage space that the pool will be processing
15
- attr_reader :queue
58
+ include Singleton
59
+
60
+ # Add an action to the pool to be processed
61
+ def Pool.<<(action)
62
+ Pool.instance.add(action)
63
+ end
16
64
 
17
- # Create a new pool
18
- def initialize
19
- @proc = Proc.new{ run_processor }
20
- @queue = PoolQueue.new
65
+ # Alias of Pool.<<(action)
66
+ def Pool.queue(action)
67
+ Pool << action
21
68
  end
22
69
 
23
- # Destroys this pool
24
- def destroy
25
- Pool.remove_pool(self)
70
+ def Pool.workers
71
+ Pool.instance.threads.size
26
72
  end
27
73
 
28
- # Starts the pool
29
- def start_pool
30
- Pool.add_pool(self)
74
+ def Pool.workers_min
75
+ return Pool.instance.min
31
76
  end
32
77
 
33
- private
78
+ def Pool.workers_max
79
+ return Pool.instance.max
80
+ end
34
81
 
35
- def run_processor
36
- begin
37
- processor
38
- rescue Object => boom
39
- Logger.log("Pool encountered an error processing code block: #{boom}", 99)
40
- end
82
+ def remove(pt)
83
+ @threads.delete(pt)
84
+ Logger.info("Pool thread has been removed: #{pt}")
85
+ end
86
+
87
+ def add(action)
88
+ @queue << action
89
+ create_pool_thread if @queue.size > @min
90
+ end
91
+
92
+ # Return maximum number of seconds actions are allowed to process
93
+ def Pool.worker_timeout
94
+ Pool.instance.timeout
41
95
  end
42
96
 
43
- # Action the pool is responsible for. This is the method
44
- # the child class should override
45
- def processor
46
- raise Exceptions::NotImplemented.new('Processor method has not been implemented')
47
- end
48
-
49
- # Running pools
50
- @@pools = Array.new
51
- # Threads running in pool
52
- @@threads = Array.new
53
- # Schedule lock for thread safety
54
- @@schedule_lock = Mutex.new
55
- # Thread creation lock
56
- @@thread_lock = Mutex.new
57
- # Maximum number of seconds a thread may spend waiting for an action
58
- @@max_exec_time = 60
59
- # Maximum number of threads to process Pool
60
- @@max_threads = 10
61
- # Maxium wait time (max time for threads to wait for new action to process)
62
- @@max_wait_time = 20
63
- # Monitor for threads to wait in
64
- @@stop_point = Monitors::Timer.new
65
- # Informs threads to halt
66
- @@kill = false
67
-
68
- # Adds a new thread to the pool
69
- def Pool.add_thread(force=false)
70
- if(force || @@threads.size < @@max_threads)
71
- thr = Thread.new do
72
- Pool.schedule_thread
73
- end
74
- @@threads << thr
75
- end
76
- @@stop_point.wakeup
97
+ # time:: number of seconds actions are allowed
98
+ # Set number of seconds actions are allowed to work
99
+ def Pool.worker_timeout=(time)
100
+ Pool.instance.timeout = time
101
+ end
102
+
103
+ # Set maximum number of workers to process tasks
104
+ def Pool.workers_max=(max)
105
+ Pool.instance.workers_max = max
77
106
  end
78
107
 
79
- # Returns the largest queue size of all available pools
80
- def Pool.max_queue_size
81
- size = 0
82
- @@pools.each do |pool|
83
- size = pool.queue.size if pool.queue.size > size
84
- end
85
- return size
108
+ # Not currently implemented
109
+ def Pool.workers_min=(min)
110
+ Pool.instance.workers_min = min
86
111
  end
87
112
 
88
- # Schedules a thread within the pool
89
- def Pool.schedule_thread
90
- run_pool = nil
91
- @@schedule_lock.synchronize do
92
- @@pools.each do |pool|
93
- run_pool = pool if (run_pool.nil? && pool.queue.size > 0) || (!run_pool.nil? && (run_pool.queue.size < pool.queue.size))
94
- end
95
- end
96
- if(run_pool.nil?)
97
- @@threads.delete(Thread.current)
98
- return
99
- else
100
- begin
101
- Timeout::timeout(@@max_exec_time) do
102
- run_pool.proc.call
103
- end
104
- rescue Timeout::Error => boom
105
- Logger.log("Thread reached maximum execution time (#{@max_exec_time}) processing pool item")
106
- rescue Object => boom
107
- Logger.log("Thread encountered error processing pool item: #{boom}")
108
- end
109
- end
110
- start = Time.now
111
- @@stop_point.wait(@@max_wait_time) if Pool.max_queue_size < 1
112
- if((Time.now - start).to_i < @@max_wait_time)
113
- Pool.schedule_thread
114
- else
115
- @@threads.delete(Thread.current)
116
- @@threads.each do |thread|
117
- @@threads.delete(thread) unless thread.alive?
118
- end
119
- end
113
+ attr_reader :threads
114
+ attr_reader :queue
115
+ attr_reader :min
116
+ attr_reader :max
117
+ attr_reader :timeout
118
+
119
+ def initialize
120
+ @queue = Queue.new
121
+ @threads = []
122
+ @lock = Mutex.new
123
+ @timeout = get_value('pool_timeout', 0).to_i
124
+ @max = Database.type != :pgsql ? 1 : get_value('pool_workers_max', 7).to_i
125
+ @min = Database.type != :pgsql ? 1 : get_value('pool_workers_min', 5).to_i
126
+ @min.times{create_pool_thread}
120
127
  end
121
128
 
122
- # Forces sleeping threads to wake up
123
- def Pool.process
124
- @@thread_lock.synchronize do
125
- Pool.add_thread if Pool.max_queue_size > 0
126
- end
129
+ def create_pool_thread(force=false)
130
+ return nil unless @threads.size < @max || force
131
+ pt = PoolThread.new(self, @timeout)
132
+ @threads << pt
133
+ return pt
127
134
  end
128
135
 
129
- # Adds a Pool to the master Pool list
130
- def Pool.add_pool(pool)
131
- @@pools << pool
136
+ def get_value(n, default)
137
+ m = Models::Config.filter(:name => n).first
138
+ return m.nil? ? default : m.value
132
139
  end
133
140
 
134
- # Removes a Pool from the master Pool list
135
- def Pool.remove_pool(pool)
136
- @@pools.delete(pool)
137
- if(@@pools.empty?)
138
- @@kill = true
139
- @@stop_point.wakeup
140
- sleep(0.1)
141
- @@threads.each{|t| t.kill if t.alive?}
142
- end
141
+ def set_value(n, v)
142
+ m = Models::Config.find_or_create(:name => n)
143
+ m.value = v
144
+ m.save
143
145
  end
144
146
 
145
- # Modified Queue to properly interact with Pool
146
- class PoolQueue < Queue
147
+ def timeout=(v)
148
+ set_value('pool_timeout', v.to_i)
149
+ @timeout = v.to_i
150
+ end
147
151
 
148
- def initialize
149
- super
150
- @lock = Mutex.new
151
- end
152
-
153
- def <<(val)
154
- push(val)
155
- end
156
-
157
- def push(val)
158
- @lock.synchronize do
159
- super
160
- end
161
- Pool.process
162
- end
163
-
164
- def pop
165
- @lock.synchronize do
166
- if(size > 0)
167
- super
168
- else
169
- raise Exceptions::BotException.new("Queue is currently empty")
170
- end
171
- end
172
- end
173
-
152
+ def workers_max=(v)
153
+ set_value('pool_workers_max', v.to_i)
154
+ @max = v.to_i
174
155
  end
175
-
156
+
157
+ def workers_min=(v)
158
+ set_value('pool_workers_min', v.to_i)
159
+ @min = v.to_i
160
+ end
161
+
176
162
  end
177
163
 
178
164
  end