rendered paste bodyIndex: lib/rbot/ircbot.rb
===================================================================
--- lib/rbot/ircbot.rb (revision 750)
+++ lib/rbot/ircbot.rb (working copy)
@@ -440,15 +440,15 @@
@plugins = Plugins::pluginmanager
@plugins.bot_associate(self)
setup_plugins_path()
+
+ @socket = IrcSocket.new(@config['server.name'], @config['server.port'], @config['server.bindhost'], @config['server.sendq_delay'], @config['server.sendq_burst'], :ssl => @config['server.ssl'])
+ @client = Client.new
+
@plugins.scan
Utils.set_safe_save_dir("#{botclass}/safe_save")
@httputil = Utils::HttpUtil.new(self)
-
- @socket = IrcSocket.new(@config['server.name'], @config['server.port'], @config['server.bindhost'], @config['server.sendq_delay'], @config['server.sendq_burst'], :ssl => @config['server.ssl'])
- @client = Client.new
-
# Channels where we are quiet
# Array of channels names where the bot should be quiet
# '*' means all channels
Index: lib/rbot/ircsocket.rb
===================================================================
--- lib/rbot/ircsocket.rb (revision 750)
+++ lib/rbot/ircsocket.rb (working copy)
@@ -258,6 +258,10 @@
# max lines to burst
attr_reader :sendq_burst
+ # an optional filter object. if present, we call @filter.in(data) for
+ # all incoming data and @filter.out(data) for all outgoing data
+ attr_accessor :filter
+
# server:: server to connect to
# port:: IRCd port
# host:: optional local host to bind to (ruby 1.7+ required)
@@ -271,6 +275,7 @@
@port = port.to_i
@host = host
@sock = nil
+ @filter = nil
@spooler = false
@lines_sent = 0
@lines_received = 0
@@ -381,6 +386,7 @@
end
begin
reply = @sock.gets
+ reply = @filter.in(reply) if @filter
@lines_received += 1
reply.strip! if reply
debug "RECV: #{reply.inspect}"
@@ -483,7 +489,11 @@
if @sock.nil?
error "SEND attempted on closed socket"
else
- @sock.puts message
+ if @filter
+ @sock.puts @filter.out(message)
+ else
+ @sock.puts message
+ end
@last_send = Time.new
@flood_send += message.irc_send_penalty if penalty
@lines_sent += 1