Class: Irc::BasicUserMessage
- Defined in:
- lib/rbot/message.rb,
lib/rbot/core/utils/extends.rb
Overview
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)
Direct Known Subclasses
InviteMessage, JoinMessage, KickMessage, ModeChangeMessage, MotdMessage, NamesMessage, NickMessage, QuitMessage, TopicMessage, UnknownMessage, UserMessage, WelcomeMessage
Instance Attribute Summary collapse
-
#bot ⇒ Object
readonly
associated bot.
-
#ignored ⇒ Object
(also: #ignored?)
should the message be ignored?.
-
#in_thread ⇒ Object
(also: #in_thread?)
set this to true if the method that delegates the message is run in a thread.
-
#logmessage ⇒ Object
contents of the message (for logging purposes).
-
#message ⇒ Object
contents of the message (stripped of initial/final format codes).
-
#plainmessage ⇒ Object
contents of the message (stripped of all formatting).
-
#replied ⇒ Object
(also: #replied?)
has the message been replied to/handled by a plugin?.
-
#server ⇒ Object
readonly
associated server.
-
#source ⇒ Object
readonly
User that originated the message.
-
#target ⇒ Object
readonly
User/Channel message was sent to.
-
#time ⇒ Object
readonly
when the message was received.
Class Method Summary collapse
- .strip_formatting(string) ⇒ Object
- .strip_initial_formatting(string) ⇒ Object
-
.stripcolour(string) ⇒ Object
strip mIRC colour escapes from a string.
Instance Method Summary collapse
-
#address? ⇒ Boolean
returns true if the message was addressed to the bot.
-
#botuser ⇒ Object
Access the botuser corresponding to the source, if any.
-
#identified? ⇒ Boolean
Was the message from an identified user?.
-
#initialize(bot, server, source, target, message) ⇒ BasicUserMessage
constructor
- 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.
- #inspect(fields = nil) ⇒ Object
-
#parse_channel_list(string) ⇒ Object
We extend the BasicUserMessage class with a method that parses a string which is a channel list as matched by IN_CHAN(_LIST) and co.
-
#recurse_depth ⇒ Object
The recurse depth of a message, for fake messages.
-
#recurse_depth=(val) ⇒ Object
Set the recurse depth of a message, for fake messages.
-
#sourceaddress ⇒ Object
Access the user@host of the source.
-
#sourcenick ⇒ Object
Access the nick of the source.
Constructor Details
#initialize(bot, server, source, target, message) ⇒ BasicUserMessage
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
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/rbot/message.rb', line 171 def initialize(bot, server, source, target, ) @msg_wants_id = false unless defined? @msg_wants_id @time = Time.now @bot = bot @source = source @address = false @target = target @message = || "" @replied = false @server = server @ignored = false @in_thread = false @identified = false if @msg_wants_id && @server.capabilities[:"identify-msg"] if @message =~ /^([-+])(.*)/ @identified = ($1=="+") @message = $2 else warning "Message does not have identification" end end @logmessage = @message.dup @plainmessage = BasicUserMessage.strip_formatting(@message) @message = BasicUserMessage.strip_initial_formatting(@message) if target && target == @bot.myself @address = true end end |
Instance Attribute Details
#bot ⇒ Object (readonly)
associated bot
111 112 113 |
# File 'lib/rbot/message.rb', line 111 def bot @bot end |
#ignored ⇒ Object Also known as: ignored?
should the message be ignored?
139 140 141 |
# File 'lib/rbot/message.rb', line 139 def ignored @ignored end |
#in_thread ⇒ Object Also known as: in_thread?
set this to true if the method that delegates the message is run in a thread
143 144 145 |
# File 'lib/rbot/message.rb', line 143 def in_thread @in_thread end |
#logmessage ⇒ Object
contents of the message (for logging purposes)
129 130 131 |
# File 'lib/rbot/message.rb', line 129 def @logmessage end |
#message ⇒ Object
contents of the message (stripped of initial/final format codes)
126 127 128 |
# File 'lib/rbot/message.rb', line 126 def @message end |
#plainmessage ⇒ Object
contents of the message (stripped of all formatting)
132 133 134 |
# File 'lib/rbot/message.rb', line 132 def @plainmessage end |
#replied ⇒ Object Also known as: replied?
has the message been replied to/handled by a plugin?
135 136 137 |
# File 'lib/rbot/message.rb', line 135 def replied @replied end |
#server ⇒ Object (readonly)
associated server
114 115 116 |
# File 'lib/rbot/message.rb', line 114 def server @server end |
#source ⇒ Object (readonly)
User that originated the message
120 121 122 |
# File 'lib/rbot/message.rb', line 120 def source @source end |
#target ⇒ Object (readonly)
User/Channel message was sent to
123 124 125 |
# File 'lib/rbot/message.rb', line 123 def target @target end |
#time ⇒ Object (readonly)
when the message was received
117 118 119 |
# File 'lib/rbot/message.rb', line 117 def time @time end |
Class Method Details
.strip_formatting(string) ⇒ Object
249 250 251 |
# File 'lib/rbot/message.rb', line 249 def BasicUserMessage.strip_formatting(string) string.gsub(FormattingRx,"") end |
.strip_initial_formatting(string) ⇒ Object
244 245 246 247 |
# File 'lib/rbot/message.rb', line 244 def BasicUserMessage.strip_initial_formatting(string) return "" unless string ret = string.gsub(/^#{FormattingRx}|#{FormattingRx}$/,"") end |
.stripcolour(string) ⇒ Object
strip mIRC colour escapes from a string
237 238 239 240 241 242 |
# File 'lib/rbot/message.rb', line 237 def BasicUserMessage.stripcolour(string) return "" unless string ret = string.gsub(ColorRx, "") #ret.tr!("\x00-\x1f", "") ret end |
Instance Method Details
#address? ⇒ Boolean
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.
232 233 234 |
# File 'lib/rbot/message.rb', line 232 def address? return @address end |
#botuser ⇒ Object
Access the botuser corresponding to the source, if any
218 219 220 |
# File 'lib/rbot/message.rb', line 218 def botuser source.botuser rescue @bot.auth.everyone end |
#identified? ⇒ Boolean
Was the message from an identified user?
224 225 226 |
# File 'lib/rbot/message.rb', line 224 def identified? return @identified end |
#inspect(fields = nil) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/rbot/message.rb', line 146 def inspect(fields=nil) ret = self.__to_s__[0..-2] ret << ' bot=' << @bot.__to_s__ ret << ' server=' << server.to_s ret << ' time=' << time.to_s ret << ' source=' << source.to_s ret << ' target=' << target.to_s ret << ' message=' << .inspect ret << ' logmessage=' << .inspect ret << ' plainmessage=' << .inspect ret << fields if fields ret << ' (identified)' if identified? ret << ' (addressed to me)' if address? ret << ' (replied)' if replied? ret << ' (ignored)' if ignored? ret << ' (in thread)' if in_thread? ret << '>' end |
#parse_channel_list(string) ⇒ Object
We extend the BasicUserMessage class with a method that parses a string which is a channel list as matched by IN_CHAN(_LIST) and co. The method returns an array of channel names, where ‘private’ or ‘pvt’ is replaced by the Symbol :“?”, ‘here’ is replaced by the channel of the message or by :“?” (depending on whether the message target is the bot or a Channel), and ‘anywhere’ and ‘everywhere’ are replaced by Symbol :*
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/rbot/core/utils/extends.rb', line 345 def parse_channel_list(string) return [:*] if [:anywhere, :everywhere].include? string.to_sym string.scan( /(?:^|,?(?:\s+and)?\s+)(?:in|on\s+)?(#{Regexp::Irc::GEN_CHAN}|here|private|pvt)/ ).map { |chan_ar| chan = chan_ar.first case chan.to_sym when :private, :pvt :"?" when :here case self.target when Channel self.target.name else :"?" end else chan end }.uniq end |
#recurse_depth ⇒ Object
The recurse depth of a message, for fake messages. 0 means an original message
369 370 371 372 373 374 |
# File 'lib/rbot/core/utils/extends.rb', line 369 def recurse_depth unless defined? @recurse_depth @recurse_depth = 0 end @recurse_depth end |
#recurse_depth=(val) ⇒ Object
Set the recurse depth of a message, for fake messages. 0 should only be used by original messages
378 379 380 |
# File 'lib/rbot/core/utils/extends.rb', line 378 def recurse_depth=(val) @recurse_depth = val end |
#sourceaddress ⇒ Object
Access the user@host of the source
212 213 214 |
# File 'lib/rbot/message.rb', line 212 def sourceaddress "#{@source.user}@#{@source.host}" rescue @source.to_s end |
#sourcenick ⇒ Object
Access the nick of the source
206 207 208 |
# File 'lib/rbot/message.rb', line 206 def sourcenick @source.nick rescue @source.to_s end |