summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/ircbot.rb2
-rw-r--r--lib/rbot/message.rb20
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index a8b5543e..968f35f9 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -929,7 +929,7 @@ class Bot
# if target is a channel with +c or +C modes, strip colours
if where.kind_of?(Channel) and where.mode.any?('c', 'C')
- multi_line.replace(BasicUserMessage.stripcolour(multi_line).gsub(AttributeRx,''))
+ multi_line.replace BasicUserMessage.strip_formatting(multi_line)
end
messages = Array.new
diff --git a/lib/rbot/message.rb b/lib/rbot/message.rb
index abe53ce0..97e3673a 100644
--- a/lib/rbot/message.rb
+++ b/lib/rbot/message.rb
@@ -42,6 +42,8 @@ module Irc
Color = "\003"
ColorRx = /#{Color}\d?\d?(?:,\d\d?)?/
+ FormattingRx = /#{AttributeRx}|#{ColorRx}/
+
# Standard color codes
ColorCode = {
:black => 1,
@@ -120,12 +122,15 @@ module Irc
# User/Channel message was sent to
attr_reader :target
- # contents of the message
+ # contents of the message (stripped of initial/final format codes)
attr_accessor :message
# contents of the message (for logging purposes)
attr_accessor :logmessage
+ # contents of the message (stripped of all formatting)
+ attr_accessor :plainmessage
+
# has the message been replied to/handled by a plugin?
attr_accessor :replied
@@ -151,7 +156,7 @@ module Irc
@source = source
@address = false
@target = target
- @message = BasicUserMessage.stripcolour message
+ @message = message || ""
@replied = false
@server = server
@ignored = false
@@ -167,6 +172,8 @@ module Irc
end
end
@logmessage = @message.dup
+ @plainmessage = BasicUserMessage.strip_formatting(@message)
+ @message = BasicUserMessage.strip_initial_formatting(@message)
if target && target == @bot.myself
@address = true
@@ -219,6 +226,15 @@ module Irc
ret
end
+ def BasicUserMessage.strip_initial_formatting(string)
+ return "" unless string
+ ret = string.gsub(/^#{FormattingRx}|#{FormattingRx}$/,"")
+ end
+
+ def BasicUserMessage.strip_formatting(string)
+ string.gsub(FormattingRx,"")
+ end
+
end
# class for handling welcome messages from the server