From 19b1b0452d6272215999ddc542993d9f2e19c3b7 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sun, 3 Aug 2008 23:11:46 +0000 Subject: rate limit git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@364 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- nsa | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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}" -- cgit v1.2.3