Class | Irc::BasicUserMessage |
In: |
lib/rbot/message.rb
|
Parent: | Object |
base user message class, all user messages derive from this (a user message is defined as having a source hostmask, a target nick/channel and a message part)
replied | -> | replied? |
ignored | -> | ignored? |
in_thread | -> | in_thread? |
bot | [R] | associated bot |
ignored | [RW] | should the message be ignored? |
in_thread | [RW] | set this to true if the method that delegates the message is run in a thread |
logmessage | [RW] | contents of the message (for logging purposes) |
message | [RW] | contents of the message (stripped of initial/final format codes) |
plainmessage | [RW] | contents of the message (stripped of all formatting) |
replied | [RW] | has the message been replied to/handled by a plugin? |
server | [R] | associated server |
source | [R] | User that originated the message |
target | [R] | User/Channel message was sent to |
time | [R] | when the message was received |
instantiate a new Message
bot: | associated bot class |
server: | Server where the message took place |
source: | User that sent the message |
target: | User/Channel is destined for |
message: | actual message |
# File lib/rbot/message.rb, line 179 179: def initialize(bot, server, source, target, message) 180: @msg_wants_id = false unless defined? @msg_wants_id 181: 182: @time = Time.now 183: @bot = bot 184: @source = source 185: @address = false 186: @prefixed = false 187: @target = target 188: @message = message || "" 189: @replied = false 190: @server = server 191: @ignored = false 192: @in_thread = false 193: 194: @identified = false 195: if @msg_wants_id && @server.capabilities["identify-msg""identify-msg"] 196: if @message =~ /^([-+])(.*)/ 197: @identified = ($1=="+") 198: @message = $2 199: else 200: warning "Message does not have identification" 201: end 202: end 203: @logmessage = @message.dup 204: @plainmessage = BasicUserMessage.strip_formatting(@message) 205: @message = BasicUserMessage.strip_initial_formatting(@message) 206: 207: if target && target == @bot.myself 208: @address = true 209: end 210: 211: end
# File lib/rbot/message.rb, line 264 264: def BasicUserMessage.strip_formatting(string) 265: string.gsub(FormattingRx,"") 266: end
# File lib/rbot/message.rb, line 259 259: def BasicUserMessage.strip_initial_formatting(string) 260: return "" unless string 261: ret = string.gsub(/^#{FormattingRx}|#{FormattingRx}$/,"") 262: end
strip mIRC colour escapes from a string
# File lib/rbot/message.rb, line 252 252: def BasicUserMessage.stripcolour(string) 253: return "" unless string 254: ret = string.gsub(ColorRx, "") 255: #ret.tr!("\x00-\x1f", "") 256: ret 257: end
returns true if the message was addressed to the bot. This includes any private message to the bot, or any public message which looks like it‘s addressed to the bot, e.g. "bot: foo", "bot, foo", a kick message when bot was kicked etc.
# File lib/rbot/message.rb, line 241 241: def address? 242: return @address 243: end
Was the message from an identified user?
# File lib/rbot/message.rb, line 233 233: def identified? 234: return @identified 235: end
# File lib/rbot/message.rb, line 150 150: def inspect(fields=nil) 151: ret = self.__to_s__[0..-2] 152: ret << ' bot=' << @bot.__to_s__ 153: ret << ' server=' << server.to_s 154: ret << ' time=' << time.to_s 155: ret << ' source=' << source.to_s 156: ret << ' target=' << target.to_s 157: ret << ' message=' << message.inspect 158: ret << ' logmessage=' << logmessage.inspect 159: ret << ' plainmessage=' << plainmessage.inspect 160: ret << fields if fields 161: ret << ' (identified)' if identified? 162: if address? 163: ret << ' (addressed to me' 164: ret << ', with prefix' if prefixed? 165: ret << ')' 166: end 167: ret << ' (replied)' if replied? 168: ret << ' (ignored)' if ignored? 169: ret << ' (in thread)' if in_thread? 170: ret << '>' 171: end
returns true if the messaged was addressed to the bot via the address prefix. This can be used to tell appart "!do this" from "botname, do this"
# File lib/rbot/message.rb, line 247 247: def prefixed? 248: return @prefixed 249: end
Access the user@host of the source
# File lib/rbot/message.rb, line 221 221: def sourceaddress 222: "#{@source.user}@#{@source.host}" rescue @source.to_s 223: end