summaryrefslogtreecommitdiff
path: root/nsa
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2008-08-03 23:11:46 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2008-08-03 23:11:46 +0000
commit19b1b0452d6272215999ddc542993d9f2e19c3b7 (patch)
treee78e603c7e4915445e1a5ab4624ee01a4ce7ea48 /nsa
parentab0fac99e63a1623e73335e0233befdec81e0b89 (diff)
rate limit
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@364 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'nsa')
-rwxr-xr-xnsa37
1 files changed, 37 insertions, 0 deletions
diff --git a/nsa b/nsa
index e49aa37..46d514d 100755
--- a/nsa
+++ b/nsa
@@ -331,11 +331,47 @@ class Irc
end
end
+class Counter
+ include MonitorMixin
+
+ def initialize
+ super
+ @count = 5
+ @ready = new_cond
+
+ Thread.new {
+ begin
+ while true
+ synchronize do
+ if @count < 8
+ @count = @count + 1
+ @ready.signal
+ end
+ end
+ sleep 1
+ end
+ rescue => e
+ puts e.class.to_s+": "+e.message
+ puts e.backtrace
+ end
+ Thread.main.exit
+ }
+ end
+
+ def pop
+ synchronize do
+ @ready.wait_until{ @count > 0 }
+ @count = @count - 1
+ end
+ end
+end
+
Thread.abort_on_exception = true
Dir.chdir( CONFIG['mailin'] + "/new" )
Log.init
+counter = Counter.new
bot = Irc.new
bot.waitUntilOnline
sleep 1
@@ -402,6 +438,7 @@ while (1) do
line = pr + line
channellist = CONFIG['projects'].has_key?(project) ? CONFIG['projects'][project] : CONFIG['projects']['*']
channellist.each do |c|
+ counter.pop
m = /^NOTICE:(.*)/.match c
if m
bot.print "NOTICE #{m[1]} :#{line}"