Class Irc::BasicUserMessage
In: lib/rbot/message.rb
Parent: Object
BasicUserMessage JoinMessage NamesMessage WhoisMessage ModeChangeMessage KickMessage MotdMessage QuitMessage BanlistMessage UserMessage NoSuchTargetMessage TopicMessage NickMessage WelcomeMessage UnknownMessage InviteMessage PartMessage NetmaskList UserList ArrayOf ChannelList Netmask User\n[lib/rbot/botuser.rb\nlib/rbot/irc.rb] Channel Singleton RfcCasemap StrictRfcCasemap AsciiCasemap Casemap PrivMessage NoticeMessage TokyoCabinet::BDB CIBDB Btree CIBtree Socket MessageQueue QueueRing Client DBHash\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] DBTree\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] Server NetmaskDb Bot\n[lib/rbot/botuser.rb\nlib/rbot/config.rb\nlib/rbot/ircbot.rb\nlib/rbot/language.rb\nlib/rbot/message.rb\nlib/rbot/messagemapper.rb\nlib/rbot/plugins.rb\nlib/rbot/rbotconfig.rb\nlib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] lib/rbot/ircsocket.rb lib/rbot/rfc2812.rb lib/rbot/registry/tc.rb lib/rbot/irc.rb lib/rbot/maskdb.rb lib/rbot/message.rb lib/rbot/messagemapper.rb lib/rbot/botuser.rb lib/rbot/registry/tc.rb (null) BotConfig PKGConfig ServerOrCasemap Irc dot/m_35_0.png

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)

Methods

External Aliases

replied -> replied?
ignored -> ignored?
in_thread -> in_thread?

Attributes

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

Public Class methods

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

[Source]

     # 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

[Source]

     # File lib/rbot/message.rb, line 264
264:     def BasicUserMessage.strip_formatting(string)
265:       string.gsub(FormattingRx,"")
266:     end

[Source]

     # 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

[Source]

     # 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

Public Instance methods

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.

[Source]

     # File lib/rbot/message.rb, line 241
241:     def address?
242:       return @address
243:     end

Access the botuser corresponding to the source, if any

[Source]

     # File lib/rbot/message.rb, line 227
227:     def botuser
228:       source.botuser rescue @bot.auth.everyone
229:     end

Was the message from an identified user?

[Source]

     # File lib/rbot/message.rb, line 233
233:     def identified?
234:       return @identified
235:     end

[Source]

     # 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"

[Source]

     # File lib/rbot/message.rb, line 247
247:     def prefixed?
248:       return @prefixed
249:     end

Access the user@host of the source

[Source]

     # File lib/rbot/message.rb, line 221
221:     def sourceaddress
222:       "#{@source.user}@#{@source.host}" rescue @source.to_s
223:     end

Access the nick of the source

[Source]

     # File lib/rbot/message.rb, line 215
215:     def sourcenick
216:       @source.nick rescue @source.to_s
217:     end

[Validate]