summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorYaohan Chen <yaohan.chen@gmail.com>2007-12-19 12:55:46 +0000
committerYaohan Chen <yaohan.chen@gmail.com>2007-12-19 12:55:46 +0000
commitc92d77d927b51c651b4c0146eb8cfd3627fe0e5a (patch)
treeb1e2183d90d6642946ffd52420d4a02017ca1b85 /data
parente275b12c6eb6ab820902c3d79691a7c3ad02ec3a (diff)
linkbot.rb:
+ strip embedded formatting code in nicknames + update patterns when the configuration is changed
Diffstat (limited to 'data')
-rw-r--r--data/rbot/plugins/linkbot.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/data/rbot/plugins/linkbot.rb b/data/rbot/plugins/linkbot.rb
index 6a5cafbc..a47f4b49 100644
--- a/data/rbot/plugins/linkbot.rb
+++ b/data/rbot/plugins/linkbot.rb
@@ -28,13 +28,17 @@ class LinkBot < Plugin
Config.register Config::ArrayValue.new('linkbot.message_patterns',
:default => ['^<(\S+?)@(\S+?)>\s+(.*)$', '^\((\S+?)@(\S+?)\)\s+(.*)$'],
- :desc => "List of regexp which match linkbot messages; each regexp needs to have three captures, which in order are the nickname of the original speaker, network, and original message")
+ :desc => "List of regexp which match linkbot messages; each regexp needs to have three captures, which in order are the nickname of the original speaker, network, and original message",
+ :on_change => proc {|bot, v| bot.plugins['linkbot'].update_patterns})
# TODO use template strings instead of regexp for user friendliness
# Initialize the plugin
def initialize
super
-
+ update_patterns
+ end
+
+ def update_patterns
@message_patterns = @bot.config['linkbot.message_patterns'].map {|p|
Regexp.new(p)
}
@@ -48,13 +52,15 @@ class LinkBot < Plugin
return unless m.kind_of?(PrivMessage)
# Now we know that _m_ is a PRIVMSG from a linkbot. Let's split it
# in nick, network, message
- message = BasicUserMessage.stripcolour m.message
- if @message_patterns.any? {|p| message =~ p}
+ if @message_patterns.any? {|p| m.message =~ p}
# if the regexp doesn't contain all parts, the default values get used
new_nick = $1 || 'unknown_nick'
network = $2 || 'unknown_network'
message = $3 || 'unknown_message'
-
+ # strip any formatting codes in the new_nick. some people configure their linkbots
+ # to embed these codes in nicknames (such as to\B\Bm), to avoid triggering the
+ # person's highlight
+ new_nick.gsub! /[#{Bold}#{Underline}#{Reverse}#{Italic}#{NormalText}]/, ''
debug "#{m.sourcenick} reports that #{new_nick} said #{message.inspect} on #{network}"
# One way to pass the new message back to the bot is to create a PrivMessage
# and delegate it to the plugins