This class serves two purposes. For one, it simply represents incoming messages and allows for querying various details (who sent the message, what kind of message it is, etc).
At the same time, it allows *responding* to messages, which means sending messages to either users or channels.
@return [Boolean] true if the message is an action (/me) @since 2.0.0
# File lib/cinch/message.rb, line 130 def action? @ctcp_command == "ACTION" end
Reply to a message with an action.
@param [String] text the action message @return [void]
# File lib/cinch/message.rb, line 192 def action_reply(text) text = text.to_s @target.action(text) end
@return [Boolean] true if this message was sent in a channel
# File lib/cinch/message.rb, line 119 def channel? !@channel.nil? end
@return [Boolean] true if the message is an CTCP message
# File lib/cinch/message.rb, line 124 def ctcp? !!(@params.last =~ /\0001.+\0001/) end
Reply to a CTCP message
@return [void]
# File lib/cinch/message.rb, line 209 def ctcp_reply(answer) return unless ctcp? @user.notice "\0001#{@ctcp_command} #{answer}\0001" end
@return [Boolean] true if the message describes an error
# File lib/cinch/message.rb, line 114 def error? !@error.nil? end
@api private @return [MatchData]
# File lib/cinch/message.rb, line 138 def match(regexp, type, strip_colors) text = "" case type when :ctcp text = ctcp_message when :action text = action_message else text = message.to_s type = :other end if strip_colors text = Cinch::Utilities::String.strip_colors(text) end @matches[type][regexp] ||= text.match(regexp) end
@return [Boolean] true if the message is an numeric reply (as
opposed to a command)
# File lib/cinch/message.rb, line 109 def numeric_reply? !!@command.match(/^\d{3}$/) end
@api private @return [void]
# File lib/cinch/message.rb, line 79 def parse match = @raw.match(/(^:(\S+) )?(\S+)(.*)/) _, @prefix, @command, raw_params = match.captures if @bot.irc.network.ngametv? if @prefix != "ngame" @prefix = "%s!%s@%s" % [@prefix, @prefix, @prefix] end end @params = parse_params(raw_params) @user = parse_user @channel = parse_channel @target = @channel || @user @server = parse_server @error = parse_error @message = parse_message @ctcp_message = parse_ctcp_message @ctcp_command = parse_ctcp_command @ctcp_args = parse_ctcp_args @action_message = parse_action_message end
Like action_reply, but using {Target#safe_action} instead
@param (see action_reply) @return (see action_reply)
# File lib/cinch/message.rb, line 201 def safe_action_reply(text) text = text.to_s @target.safe_action(text) end
Like reply, but using {Target#safe_send} instead
@param (see reply) @return (see reply)
# File lib/cinch/message.rb, line 180 def safe_reply(text, prefix = false) text = text.to_s if channel && prefix text = "#{@user.nick}: #{text}" end @target.safe_send(text) end
Generated with the Darkfish Rdoc Generator 2.