diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-02-11 23:34:16 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-02-11 23:48:44 +0100 |
commit | 75c90dfd30d17544b2b86323b3993ac5c3083ca9 (patch) | |
tree | 308c842b544761803fc3ec07fe1f7358a947ebc2 | |
parent | 8115edef0169d95f0ebb64d77364e346e9452099 (diff) |
ircbot: sendmsg filtering
We allow a filter to manipulate the arguments of sendmsg() by running
them through the filters of the :sendmsg group. The DataStream passed to
the filters has four keys:
:text => the message text
:type => the message type (typically, PRIVSMG or NOTICE)
:dest => the destination (typically, a Channel or User)
:options => options passed to sendmsg, merged with the default ones
-rw-r--r-- | lib/rbot/ircbot.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 389494af..f491b212 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -973,8 +973,22 @@ class Bot # Type can be PRIVMSG, NOTICE, etc, but those you should really use the # relevant say() or notice() methods. This one should be used for IRCd # extensions you want to use in modules. - def sendmsg(type, where, original_message, options={}) - opts = @default_send_options.merge(options) + def sendmsg(original_type, original_where, original_message, options={}) + + # filter message with sendmsg filters + ds = DataStream.new original_message.to_s.dup, + :type => original_type, :dest => original_where, + :options => @default_send_options.merge(options) + filters = filter_names(:sendmsg) + filters.each do |fname| + debug "filtering #{ds[:text]} with sendmsg filter #{fname}" + ds.merge! filter(self.global_filter_name(fname, :sendmsg), ds) + end + + opts = ds[:options] + type = ds[:type] + where = ds[:dest] + filtered = ds[:text] # For starters, set up appropriate queue channels and rings mchan = opts[:queue_channel] @@ -995,7 +1009,7 @@ class Bot end end - multi_line = original_message.to_s.gsub(/[\r\n]+/, "\n") + multi_line = filtered.gsub(/[\r\n]+/, "\n") # if target is a channel with nocolor modes, strip colours if where.kind_of?(Channel) and where.mode.any?(*config['server.nocolor_modes']) |