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
@@ -2,9 +2,9 @@ class Banner < ModSpox::Plugin
2
2
 
3
3
  include Models
4
4
  include Messages::Outgoing
5
-
5
+
6
6
  def initialize(pipeline)
7
- super(pipeline)
7
+ super
8
8
  admin = Group.find_or_create(:name => 'banner')
9
9
  Signature.find_or_create(:signature => 'ban (\S+)', :plugin => name, :method => 'default_ban', :group_id => admin.pk,
10
10
  :description => 'Kickban given nick from current channel').params = [:nick]
@@ -36,22 +36,31 @@ class Banner < ModSpox::Plugin
36
36
  @pipeline.hook(self, :mode_check, :Incoming_Mode)
37
37
  @pipeline.hook(self, :join_check, :Incoming_Join)
38
38
  @pipeline.hook(self, :who_check, :Incoming_Who)
39
- @pipeline.hook(self, :get_action, :Internal_TimerResponse)
39
+ @pipeline.hook(self, :process_ban, :Banner_Ban)
40
40
  BanRecord.create_table unless BanRecord.table_exists?
41
41
  BanMask.create_table unless BanMask.table_exists?
42
42
  BanNickExempt.create_table unless BanNickExempt.table_exists?
43
43
  BanModeExempt.create_table unless BanModeExempt.table_exists?
44
44
  BanSourceExempt.create_table unless BanSourceExempt.table_exists?
45
- @actions = []
46
- @up_sync = Mutex.new
47
- @timer_sync = Mutex.new
48
- updater
45
+ load_timer
46
+ @time = Object::Time.now
49
47
  end
50
-
48
+
51
49
  def destroy
52
- do_update
50
+ reset_time
51
+ end
52
+
53
+ def process_ban(message)
54
+ ban(message.nick, message.channel, message.time, message.message, message.invite?, message.display_time?)
55
+ end
56
+
57
+ def reset_time
58
+ elapsed = Object::Time.now.to_i - @time.to_i
59
+ BanRecord.filter('remaining > 0').update("remaining = remaining - #{elapsed}")
60
+ BanMask.filter('bantime > 0').update("bantime = bantime - #{elapsed}")
61
+ @time = Object::Time.now
53
62
  end
54
-
63
+
55
64
  # message:: ModSpox::Messages::Incoming::Privmsg
56
65
  # params:: parameters
57
66
  # Perform a simple ban with default values
@@ -60,7 +69,7 @@ class Banner < ModSpox::Plugin
60
69
  params[:channel] = message.target.name
61
70
  full_ban(message, params)
62
71
  end
63
-
72
+
64
73
  # message:: ModSpox::Messages::Incoming::Privmsg
65
74
  # params:: parameters
66
75
  # Ban given nick in given channel
@@ -68,14 +77,14 @@ class Banner < ModSpox::Plugin
68
77
  params[:time] = 86400
69
78
  full_ban(message, params)
70
79
  end
71
-
80
+
72
81
  # message:: ModSpox::Messages::Incoming::Privmsg
73
82
  # params:: parameters
74
83
  # Ban nick in given channel for given time providing given message
75
84
  def full_ban(message, params)
76
85
  nick = Helpers.find_model(params[:nick], false)
77
- channel = Channel.filter(:name => params[:channel]).first
78
- if(!me.is_op?(message.target))
86
+ channel = Channel.locate(params[:channel])
87
+ if(!me.is_op?(channel))
79
88
  reply(message.replyto, "Error: I'm not a channel operator")
80
89
  elsif(!nick)
81
90
  reply(message.replyto, "#{message.source.nick}: Failed to find nick #{params[:nick]}")
@@ -85,7 +94,7 @@ class Banner < ModSpox::Plugin
85
94
  ban(nick, channel, params[:time], params[:message])
86
95
  end
87
96
  end
88
-
97
+
89
98
  # nick:: ModSpox::Models::Nick to ban
90
99
  # channel:: ModSpox::Models::Channel to ban nick from
91
100
  # time:: number of seconds ban should last
@@ -102,17 +111,27 @@ class Banner < ModSpox::Plugin
102
111
  elsif(check_exempt(nick, channel))
103
112
  raise BanExemption.new("This nick is exempt from bans: #{nick.nick}")
104
113
  else
105
- mask = nick.source.nil? || nick.source.empty? ? "#{nick.nick}!*@*" : "*!*@#{nick.address}"
106
- BanRecord.new(:nick_id => nick.pk, :bantime => time.to_i, :remaining => time.to_i,
107
- :invite => invite, :channel_id => channel.pk, :mask => mask).save
114
+ reset_time
115
+ mask = nick.address.nil? || nick.address.empty? ? "#{nick.nick}!*@*" : "*!*@#{nick.address}"
116
+ record = BanRecord.filter(:nick_id => nick.pk, :channel_id => channel.pk, :mask => mask, :removed => false).first
117
+ if(record)
118
+ record.bantime = record.bantime + time.to_i
119
+ record.remaining = record.remaining + time.to_i
120
+ record.save
121
+ else
122
+ record = BanRecord.new(:nick_id => nick.pk, :bantime => time.to_i, :remaining => time.to_i,
123
+ :invite => invite, :channel_id => channel.pk, :mask => mask)
124
+ record.save
125
+ end
126
+ @pipeline << Messages::Internal::TimerAdd.new(self, record.remaining, nil, true){ clear_record(record.pk, record.remaining) }
127
+ reset_time
108
128
  message = reason ? reason : 'no soup for you!'
109
129
  message = "#{message} (Duration: #{Helpers.format_seconds(time.to_i)})" if show_time
110
130
  @pipeline << ChannelMode.new(channel, '+b', mask)
111
131
  @pipeline << Kick.new(nick, channel, message)
112
- updater
113
132
  end
114
133
  end
115
-
134
+
116
135
  # mask:: mask to match against source (Regexp)
117
136
  # channel:: ModSpox::Models::Channel to ban from
118
137
  # message:: kick message
@@ -120,11 +139,14 @@ class Banner < ModSpox::Plugin
120
139
  # Bans all users who's source matches the given mask
121
140
  def mask_ban(mask, channel, message, time)
122
141
  raise NotInChannel.new("I am not in channel: #{channel.name}") unless me.channels.include?(channel)
123
- BanMask.new(:mask => mask, :channel_id => channel.pk, :message => message, :bantime => time.to_i, :stamp => Object::Time.now).save
142
+ reset_time
143
+ record = BanMask.new(:mask => mask, :channel_id => channel.pk, :message => message, :bantime => time.to_i, :stamp => Object::Time.now)
144
+ record.save
124
145
  check_masks
125
- updater
146
+ @pipeline << Messages::Internal::TimerAdd.new(self, record.bantime, nil, true){ record.destroy }
147
+ reset_time
126
148
  end
127
-
149
+
128
150
  # message:: ModSpox::Messages::Incoming::Privmsg
129
151
  # params:: parameters
130
152
  # Set a ban on any nick with a source match given regex
@@ -136,22 +158,21 @@ class Banner < ModSpox::Plugin
136
158
  reply(message.replyto, "Okay")
137
159
  rescue Object => boom
138
160
  reply(message.replyto, "Error: Failed to ban mask. Reason: #{boom}")
139
- Logger.log("ERROR: #{boom} #{boom.backtrace.join("\n")}")
161
+ Logger.warn("ERROR: #{boom} #{boom.backtrace.join("\n")}")
140
162
  end
141
163
  else
142
164
  reply(message.replyto, "Error: No record of channel: #{params[:channel]}")
143
- end
165
+ end
144
166
  end
145
-
167
+
146
168
  # message:: ModSpox::Messages::Incoming::Privmsg
147
169
  # params:: parameters
148
170
  # List all ban masks
149
171
  def mask_list(message, params)
150
- updater
151
172
  if(BanMask.all.size > 0)
152
173
  reply(message.replyto, "Masks currently banned:")
153
174
  BanMask.all.each do |mask|
154
- reply(message.replyto, "\2ID:\2 #{mask.pk} \2Mask:\2 #{mask.mask} \2Time:\2 #{Helpers.format_seconds(mask.bantime.to_i)} \2Channel:\2 #{mask.channel.name}")
175
+ reply(message.replyto, "\2ID:\2 #{mask.pk} \2Mask:\2 #{mask.mask} \2Time:\2 #{Helpers.format_seconds(mask.bantime.to_i - (Object::Time.now.to_i - @time.to_i))} \2Channel:\2 #{mask.channel.name}")
155
176
  end
156
177
  else
157
178
  reply(message.replyto, "No ban masks currently enabled")
@@ -165,43 +186,41 @@ class Banner < ModSpox::Plugin
165
186
  mask = BanMask[params[:id].to_i]
166
187
  if(mask)
167
188
  mask.destroy
168
- updater
169
189
  reply(message.replyto, 'Okay')
170
190
  else
171
191
  reply(message.replyto, "\2Error:\2 Failed to find ban mask with ID: #{params[:id]}")
172
192
  end
173
193
  end
174
-
194
+
175
195
  # message:: ModSpox::Messages::Incoming::Privmsg
176
196
  # params:: parameters
177
- # List all currently active bans originating from the bot
197
+ # List all currently active bans originating from the bot
178
198
  def ban_list(message, params)
179
- updater
180
199
  set = BanRecord.filter(:removed => false)
181
200
  if(set.size > 0)
182
201
  reply(message.replyto, "Currently active bans:")
183
202
  set.each do |record|
184
- reply(message.replyto, "\2ID:\2 #{record.pk} \2Nick:\2 #{record.nick.nick} \2Channel:\2 #{record.channel.name} \2Initial time:\2 #{Helpers.format_seconds(record.bantime.to_i)} \2Time remaining:\2 #{Helpers.format_seconds(record.remaining.to_i)}")
203
+ remains = record.remaining.to_i - (Object::Time.now.to_i - @time.to_i)
204
+ remains = 0 unless remains > 0
205
+ reply(message.replyto, "\2ID:\2 #{record.pk} \2Nick:\2 #{record.nick.nick} \2Channel:\2 #{record.channel.name} \2Initial time:\2 #{Helpers.format_seconds(record.bantime.to_i)} \2Time remaining:\2 #{Helpers.format_seconds(remains)}")
185
206
  end
186
207
  else
187
208
  reply(message.replyto, "No bans currently active")
188
209
  end
189
210
  end
190
-
211
+
191
212
  # message:: ModSpox::Messages::Incoming::Privmsg
192
213
  # params:: parameters
193
214
  # Remove given ban
194
215
  def ban_remove(message, params)
195
216
  record = BanRecord[params[:id].to_i]
196
217
  if(record)
197
- record.update_with_params(:remaining => 0)
198
- updater
199
- reply(message.replyto, 'Okay')
218
+ clear_record(record.pk, nil)
200
219
  else
201
220
  reply(message.replyto, "\2Error:\2 Failed to find ban record with ID: #{params[:id]}")
202
- end
221
+ end
203
222
  end
204
-
223
+
205
224
  # Check all enabled ban masks and ban any matches found
206
225
  def check_masks
207
226
  masks = BanMask.map_masks
@@ -217,24 +236,23 @@ class Banner < ModSpox::Plugin
217
236
  end
218
237
  unless match.nil?
219
238
  begin
220
- ban(nick, channel, match[:bantime], match[:message])
239
+ ban(nick, channel, match[:bantime], match[:message])
221
240
  rescue Object => boom
222
- Logger.log("Mask based ban failed. Reason: #{boom}")
241
+ Logger.warn("Mask based ban failed. Reason: #{boom}")
223
242
  end
224
243
  end
225
244
  end
226
245
  else
227
- Logger.log("Ban masks will not be processed due to lack of operator status")
246
+ Logger.info("Ban masks will not be processed due to lack of operator status")
228
247
  end
229
248
  end
230
249
  end
231
-
250
+
232
251
  # nick:: ModSpox::Models::Nick
233
252
  # channel:: ModSpox::Models::Channel
234
253
  # Check if the nick in the channel matches any ban masks
235
254
  def mask_check(nick, channel)
236
255
  return unless me.is_op?(channel)
237
- updater
238
256
  match = nil
239
257
  BanMask.filter(:channel_id => channel.pk).each do |bm|
240
258
  if(nick.source =~ /#{bm.mask}/)
@@ -245,108 +263,69 @@ class Banner < ModSpox::Plugin
245
263
  begin
246
264
  ban(nick, channel, match.bantime, match.message)
247
265
  rescue Object => boom
248
- Logger.log("Mask based ban failed. Reason: #{boom}")
266
+ Logger.warn("Mask based ban failed. Reason: #{boom}")
249
267
  end
250
268
  end
251
269
  end
252
-
270
+
253
271
  # message:: ModSpox::Messages::Incoming::Mode
254
272
  # Check for mode changes. Remove pending ban removals if
255
273
  # done manually
256
274
  def mode_check(message)
257
275
  if(message.target.is_a?(String) && message.source != me)
258
276
  if(message.mode == '-b')
259
- update = false
260
277
  BanRecord.filter(:mask => message.target, :channel_id => message.channel.pk).each do |match|
261
- match.update_vaules(:remaining => 0)
262
- match.update_with_params(:removed => true)
263
- update = true
278
+ match.remaining = 0
279
+ match.removed = true
280
+ match.save
264
281
  end
265
- updater if update
266
282
  end
267
283
  end
268
284
  if(message.target == me && message.mode == '+o')
269
285
  check_masks
270
- updater
286
+ BanRecord.filter('remaining < 1 AND removed = ?', false).each do |record|
287
+ clear_record(record.pk, nil)
288
+ end
271
289
  end
272
290
  end
273
-
291
+
274
292
  # message:: ModSpox::Messages::Incoming::Join
275
293
  # Check is nick is banned
276
294
  def join_check(message)
277
295
  mask_check(message.nick, message.channel)
278
296
  end
279
-
297
+
280
298
  # message:: ModSpox::Messages::Incoming::Who
281
299
  # Check if we updated any addresses
282
300
  def who_check(message)
283
301
  check_masks
284
302
  end
285
-
286
- # message:: ModSpox::Messages::Internal::TimerResponse
287
- # Store any timer actions we have registered
288
- def get_action(message)
289
- if(message.action_added? && message.origin == self)
290
- @actions << message.action
291
- elsif(message.action_removed? && @actions.include?(message.action))
292
- @actions.delete(message.action)
293
- end
294
- end
295
-
296
- # Update all BanMask and BanRecords
297
- def updater
298
- @up_sync.synchronize do
299
- unless(@actions.empty?)
300
- @actions.each{|a|@pipeline << Messages::Internal::TimerRemove.new(a)}
301
- Logger.log("Waiting for actions to become empty")
302
- sleep(0.01) until @actions.empty?
303
- Logger.log("Actions has now become empty")
304
- end
305
- do_update
303
+
304
+ def load_timer
305
+ BanRecord.filter('removed = ? AND remaining > 0', false).each do |record|
306
+ @pipeline << Messages::Internal::TimerAdd.new(self, record.remaining, nil, true){ clear_record(record.pk, record.remaining) }
307
+ end
308
+ BanMask.filter('bantime > 0').each do |record|
309
+ @pipeline << Messages::Internal::TimerAdd.new(self, record.bantime, nil, true){ record.destroy }
306
310
  end
307
311
  end
308
-
309
- # Completes update
310
- def do_update
311
- @timer_sync.synchronize do
312
- begin
313
- time = @sleep.nil? ? 0 : (Object::Time.now - @sleep).to_i
314
- if(time > 0)
315
- BanRecord.filter('remaining > ?', 0).update("remaining = remaining - #{time}")
316
- BanMask.filter('bantime > ?', 0).update("bantime = bantime - #{time}")
317
- end
318
- BanRecord.filter('remaining <= ?', 0).filter('removed = ?', false).each do |record|
319
- if(me.is_op?(record.channel))
320
- @pipeline << ChannelMode.new(record.channel, '-b', record.mask)
321
- record.update_with_params(:removed => true)
322
- @pipeline << Invite.new(record.nick, record.channel) if record.invite
323
- end
324
- end
325
- BanMask.filter('bantime < ?', 1).destroy
326
- next_ban_record = BanRecord.filter('remaining > ?', 0).order(:remaining).first
327
- next_mask_record = BanMask.filter('bantime > ?', 0).order(:bantime).first
328
- if(next_ban_record && next_mask_record)
329
- time = next_ban_record.bantime < next_mask_record.bantime ? next_ban_record.bantime : next_mask_record.bantime
330
- elsif(next_ban_record)
331
- time = next_ban_record.bantime
332
- elsif(next_mask_record)
333
- time = next_mask_record.bantime
334
- else
335
- time = nil
336
- end
337
- Logger.log("Time left to sleep is now: #{time}")
338
- unless(time.nil?)
339
- @sleep = Object::Time.now
340
- @pipeline << Messages::Internal::TimerAdd.new(self, time, nil, true){ do_update }
341
- else
342
- @sleep = nil
343
- end
344
- rescue Object => boom
345
- Logger.log("Updating encountered an unexpected error: #{boom}")
312
+
313
+ def clear_record(id, slept=nil)
314
+ record = BanRecord[id]
315
+ return if !record || record.removed
316
+ if(!slept.nil? && (record.remaining - slept).to_i > 0)
317
+ record.remaining = record.remaining - slept
318
+ else
319
+ record.remaining = 0
320
+ if(me.is_op?(record.channel))
321
+ @pipeline << ChannelMode.new(record.channel, '-b', record.mask)
322
+ record.removed = true
323
+ @pipeline << Invite.new(record.nick, record.channel) if record.invite
346
324
  end
347
325
  end
326
+ record.save
348
327
  end
349
-
328
+
350
329
  # message:: ModSpox::Messages::Incoming::Privmsg
351
330
  # params:: parameters
352
331
  # Add ban exemption for a given mode
@@ -366,7 +345,7 @@ class Banner < ModSpox::Plugin
366
345
  end
367
346
  reply message.replyto, response
368
347
  end
369
-
348
+
370
349
  # message:: ModSpox::Messages::Incoming::Privmsg
371
350
  # params:: parameters
372
351
  # Add ban exemption for a given nick
@@ -375,7 +354,7 @@ class Banner < ModSpox::Plugin
375
354
  nick = Helpers.find_model(params[:nick])
376
355
  unless(nick.is_a?(Models::Nick))
377
356
  reply message.replyto, "\2Error:\2 Failed to find record of: #{params[:nick]}"
378
- return
357
+ return
379
358
  end
380
359
  channel = params[:channel] ? Helpers.find_model(params[:channel]) : nil
381
360
  if(channel)
@@ -411,10 +390,10 @@ class Banner < ModSpox::Plugin
411
390
  end
412
391
  reply message.replyto, response
413
392
  end
414
-
393
+
415
394
  # message:: ModSpox::Messages::Incoming::Privmsg
416
395
  # params:: parameters
417
- # List given type of current ban exemptions
396
+ # List given type of current ban exemptions
418
397
  def exempt_list(message, params)
419
398
  output = []
420
399
  if(params[:type] == 'nick')
@@ -470,7 +449,7 @@ class Banner < ModSpox::Plugin
470
449
  end
471
450
  reply message.replyto, response
472
451
  end
473
-
452
+
474
453
  # nick:: ModSpox::Models::Nick
475
454
  # channel:: ModSpox::Models::Channel
476
455
  # Check if nick is currently exempt from bans
@@ -484,114 +463,148 @@ class Banner < ModSpox::Plugin
484
463
  end
485
464
  return false
486
465
  end
487
-
466
+
488
467
  class BanRecord < Sequel::Model
489
468
  set_schema do
490
469
  primary_key :id
491
470
  timestamp :stamp, :null => false
492
471
  integer :bantime, :null => false, :default => 1
493
472
  integer :remaining, :null => false, :default => 1
494
- text :mask, :null => false
473
+ varchar :mask, :null => false
495
474
  boolean :invite, :null => false, :default => false
496
475
  boolean :removed, :null => false, :default => false
497
- foreign_key :channel_id, :null => false, :table => :channels
498
- foreign_key :nick_id, :null => false, :table => :nicks
476
+ foreign_key :channel_id, :null => false, :table => :channels, :key => :id
477
+ foreign_key :nick_id, :null => false, :table => :nicks, :key => :id
499
478
  end
500
-
479
+
501
480
  before_create do
502
- update_values(:stamp => Time.now)
481
+ update_values(:stamp => Object::Time.now)
503
482
  end
504
-
483
+
505
484
  def channel
506
485
  ModSpox::Models::Channel[channel_id]
507
486
  end
508
-
487
+
509
488
  def nick
510
489
  ModSpox::Models::Nick[nick_id]
511
490
  end
512
491
  end
513
-
492
+
514
493
  class BanMask < Sequel::Model
515
494
  set_schema do
516
495
  primary_key :id
517
- text :mask, :unique => true, :null => false
496
+ varchar :mask, :unique => true, :null => false
518
497
  timestamp :stamp, :null => false
519
498
  integer :bantime, :null => false, :default => 1
520
499
  text :message
521
- foreign_key :channel_id, :null => false, :table => :channels
500
+ foreign_key :channel_id, :null => false, :table => :channels, :key => :id
522
501
  end
523
-
502
+
524
503
  def channel
525
504
  ModSpox::Models::Channel[channel_id]
526
505
  end
527
-
506
+
528
507
  def self.map_masks
529
508
  masks = {}
530
509
  BanMask.all.each do |mask|
531
- Logger.log("Processing mask for channel: #{mask.channel.name}")
510
+ Logger.info("Processing mask for channel: #{mask.channel.name}")
532
511
  masks[mask.channel.name] = [] unless masks.has_key?(mask.channel.name)
533
512
  masks[mask.channel.name] << {:mask => mask.mask, :message => mask.message, :bantime => mask.bantime, :channel => mask.channel}
534
513
  end
535
514
  return masks
536
515
  end
537
516
  end
538
-
517
+
539
518
  class BanNickExempt < Sequel::Model
540
519
  set_schema do
541
520
  primary_key :id
542
- foreign_key :nick_id, :table => :nicks, :null => false
543
- foreign_key :channel_id, :table => :channels
521
+ foreign_key :nick_id, :table => :nicks, :null => false, :key => :id
522
+ foreign_key :channel_id, :table => :channels, :key => :id
544
523
  end
545
-
524
+
546
525
  def nick
547
526
  return Models::Nick[nick_id]
548
527
  end
549
-
528
+
550
529
  def channel
551
530
  return Models::Channel[channel_id]
552
531
  end
553
532
  end
554
-
533
+
555
534
  class BanSourceExempt < Sequel::Model
556
535
  set_schema do
557
536
  primary_key :id
558
537
  varchar :source, :null => false
559
- foreign_key :channel_id, :table => :channels
538
+ foreign_key :channel_id, :table => :channels, :key => :id
560
539
  end
561
-
540
+
562
541
  def channel
563
542
  return Models::Channel[channel_id]
564
543
  end
565
-
544
+
566
545
  def mask
567
546
  return values[:source] ? Marshal.load(values[:source].unpack('m')[0]) : nil
568
547
  end
569
-
548
+
570
549
  def mask=(val)
571
550
  update_values(:source => [Marshal.dump(val)].pack('m'))
572
551
  end
573
-
552
+
574
553
  end
575
-
554
+
576
555
  class BanModeExempt < Sequel::Model
577
556
  set_schema do
578
557
  primary_key :id
579
558
  varchar :mode, :null => false
580
- foreign_key :channel_id, :table => :channels, :unique => true
559
+ foreign_key :channel_id, :table => :channels, :key => :id
560
+ index [:channel_id, :mode]
581
561
  end
582
-
562
+
583
563
  def channel
584
564
  return Models::Channel[channel_id]
585
- end
565
+ end
586
566
  end
587
-
567
+
588
568
  class NotOperator < Exceptions::BotException
589
569
  end
590
-
570
+
591
571
  class NotInChannel < Exceptions::BotException
592
572
  end
593
-
573
+
594
574
  class BanExemption < Exceptions::BotException
595
575
  end
596
576
 
577
+ class Ban
578
+ # Nick to be kicked
579
+ attr_reader :nick
580
+ # Channel to be kicked from
581
+ attr_reader :channel
582
+ # Type of ban: :ban, :kick, :kickban
583
+ attr_reader :type
584
+ # Ban time (0 for no ban)
585
+ attr_reader :time
586
+ # Message to display in kick
587
+ attr_reader :message
588
+ def initialize(nick, channel, type=:kickban, message=nil, time=30, invite=false, display_time=false)
589
+ @nick = nick
590
+ @channel = channel
591
+ raise ModSpox::Exceptions::InvalidType.new('Ban requires a valid type (:ban, :kick, :kickban)') unless [:kick, :ban, :kickban].include?(type)
592
+ @type = type
593
+ @time = time.to_i
594
+ @message = message
595
+ @display_time = display_time ? true : false
596
+ @invite = invite ? true : false
597
+ end
598
+
599
+ # Display ban time in kick message
600
+ def display_time?
601
+ return @display_time
602
+ end
603
+
604
+ # Invite user to channel after ban expiration
605
+ def invite?
606
+ return @invite
607
+ end
608
+ end
609
+
597
610
  end
@@ -9,17 +9,18 @@ class Helper < ModSpox::Plugin
9
9
  Signature.find_or_create(:signature => 'help (\S+)', :plugin => name, :method => 'plugin_help',
10
10
  :description => 'Display help information from given plugin').params = [:plugin]
11
11
  end
12
-
12
+
13
13
  def default_help(message, params)
14
14
  plugins = Signature.select(:plugin).map(:plugin)
15
15
  plugins.uniq!
16
- reply message.replyto, "Plugins currently available for help: #{plugins.join(', ')}"
16
+ reply message.replyto, "Plugins currently available for help: #{plugins.sort.join(', ')}"
17
17
  reply message.replyto, "Request help on a plugin: !help Plugin"
18
18
  end
19
-
19
+
20
20
  def plugin_help(message, params)
21
- sigs = Signature.filter(:plugin => params[:plugin])
22
- if(sigs.count > 0)
21
+ sigs = []
22
+ Signature.all.each{|s| sigs << s if s.plugin.downcase == params[:plugin].downcase}
23
+ if(sigs.size > 0)
23
24
  output = []
24
25
  output << "Available triggers for plugin: \2#{params[:plugin]}\2"
25
26
  sigs.each do |sig|
@@ -30,9 +31,19 @@ class Helper < ModSpox::Plugin
30
31
  help << "\2Description:\2 #{sig.description}" if sig.description
31
32
  output << help.join(' ')
32
33
  end
33
- reply message.source, output
34
+ if(message.is_dcc?)
35
+ reply message.replyto, output
36
+ else
37
+ reply message.source, output
38
+ end
34
39
  else
35
- reply message.replyto, "\2Error:\2 No triggers found for plugin named: #{params[:plugin]}"
40
+ Signature.all.each{|s| sigs << s.plugin if /#{s.signature.gsub(/\s.*$/, '')}/ =~ params[:plugin]}
41
+ if(sigs.count > 0)
42
+ sigs.uniq!
43
+ reply message.replyto, "Possible plugin matches for \2#{params[:plugin]}\2: #{sigs.sort.join(', ')}"
44
+ else
45
+ reply message.replyto, "\2Error:\2 No triggers found for plugin named: #{params[:plugin]}"
46
+ end
36
47
  end
37
48
  end
38
49