diff options
author | Peter Palfrader <peter@palfrader.org> | 2008-08-03 23:11:46 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2008-08-03 23:11:46 +0000 |
commit | 19b1b0452d6272215999ddc542993d9f2e19c3b7 (patch) | |
tree | e78e603c7e4915445e1a5ab4624ee01a4ce7ea48 | |
parent | ab0fac99e63a1623e73335e0233befdec81e0b89 (diff) |
rate limit
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@364 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
-rwxr-xr-x | nsa | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -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}" |