]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
ircsocket: tunable IRC penalty
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 12 Dec 2008 19:59:34 +0000 (20:59 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 12 Dec 2008 20:40:20 +0000 (21:40 +0100)
lib/rbot/ircbot.rb
lib/rbot/ircsocket.rb

index 6fc92589bfd8bf64756e7511874f51317499a7c4..2400f612d4b2d1c71977098280cde6aff14b36ed 100644 (file)
@@ -395,6 +395,13 @@ class Bot
         bot.set_default_send_options :truncate_text => v.dup
       },
       :desc => "When truncating overlong messages (see send.overlong) or when sending too many lines per message (see send.max_lines) replace the end of the last line with this text")
+    Config.register Config::IntegerValue.new('send.penalty_pct',
+      :default => 100,
+      :validate => Proc.new { |v| v >= 0 },
+      :on_change => Proc.new { |bot, v|
+        bot.socket.penalty_pct = v
+      },
+      :desc => "Percentage of IRC penalty to consider when sending messages to prevent being disconnected for excess flood. Set to 0 to disable penalty control.")
 
     @argv = params[:argv]
     @run_dir = params[:run_dir] || Dir.pwd
@@ -581,7 +588,7 @@ class Bot
         debug "server.list is now #{@config['server.list'].inspect}"
     end
 
-    @socket = Irc::Socket.new(@config['server.list'], @config['server.bindhost'], :ssl => @config['server.ssl'])
+    @socket = Irc::Socket.new(@config['server.list'], @config['server.bindhost'], :ssl => @config['server.ssl'], :penalty_pct =>@config['send.penalty_pct'])
     @client = Client.new
 
     @plugins.scan
index 9adca6badb67ad5f27ecfface080db869353c902..36a223f9d52cc456efc1179835d143184e51f2ee 100644 (file)
@@ -246,6 +246,9 @@ module Irc
     # normalized uri of the current server
     attr_reader :server_uri
 
+    # penalty multiplier (percent)
+    attr_accessor :penalty_pct
+
     # default trivial filter class
     class IdentityFilter
         def in(x)
@@ -276,6 +279,7 @@ module Irc
       @lines_sent = 0
       @lines_received = 0
       @ssl = opts[:ssl]
+      @penalty_pct = opts[:penalty_pct] || 100
     end
 
     def connected?
@@ -433,7 +437,7 @@ module Irc
           @sock.syswrite actual
           @last_send = now
           @flood_send = now if @flood_send < now
-          @flood_send += message.irc_send_penalty if penalty
+          @flood_send += message.irc_send_penalty*@penalty_pct/100.0 if penalty
           @lines_sent += 1
         end
       rescue Exception => e