@return [Channel] The channel in which this message was sent
# File lib/cinch/message.rb, line 90 def channel @channel ||= begin case command when "INVITE", RPL_CHANNELMODEIS.to_s, RPL_BANLIST.to_s @bot.channel_manager.find_ensured(params[1]) when RPL_NAMEREPLY.to_s @bot.channel_manager.find_ensured(params[2]) else if params.first.start_with?("#") @bot.channel_manager.find_ensured(params.first) elsif numeric_reply? and params[1].start_with?("#") @bot.channel_manager.find_ensured(params[1]) end end end end
@return [Boolean] true if this message was sent in a channel
# File lib/cinch/message.rb, line 74 def channel? !!channel end
@return [Boolean] true if the message is an CTCP message
# File lib/cinch/message.rb, line 79 def ctcp? params.last =~ /\0001.+\0001/ end
@return [Array<String>, nil]
# File lib/cinch/message.rb, line 125 def ctcp_args return unless ctcp? ctcp_message.split(" ")[1..-1] end
@return [String, nil] the command part of an CTCP message
# File lib/cinch/message.rb, line 84 def ctcp_command return unless ctcp? ctcp_message.split(" ").first end
@return [String, nil] the CTCP message, without 001 control characters
# File lib/cinch/message.rb, line 118 def ctcp_message return unless ctcp? params.last =~ /\0001(.+)\0001/ $1 end
Reply to a CTCP message
@return [void]
# File lib/cinch/message.rb, line 174 def ctcp_reply(answer) return unless ctcp? user.notice "\0001#{ctcp_command} #{answer}\0001" end
@return [Number, nil] the numeric error code, if any
# File lib/cinch/message.rb, line 69 def error @error ||= (command.to_i if numeric_reply? && command[/[45]\d\d/]) end
@return [Boolean] true if the message describes an error
# File lib/cinch/message.rb, line 64 def error? !!error end
@api private @return [MatchData]
# File lib/cinch/message.rb, line 109 def match(regexp, type) if type == :ctcp @matches[:ctcp][regexp] ||= ctcp_message.match(regexp) else @matches[:other][regexp] ||= message.to_s.match(regexp) end end
@return [String, nil]
# File lib/cinch/message.rb, line 131 def message @message ||= begin if error? error.to_s elsif regular_command? params.last end end end
@return [Boolean] true if the message is an numeric reply (as opposed to a command)
# File lib/cinch/message.rb, line 26 def numeric_reply? !!(@numeric_reply ||= @command.match(/^\d{3}$/)) end
@api private @return [void]
# File lib/cinch/message.rb, line 32 def parse match = @raw.match(/(^:(\S+) )?(\S+)(.*)/) _, @prefix, @command, raw_params = match.captures raw_params.strip! if match = raw_params.match(/(?:^:| :)(.*)$/) @params = match.pre_match.split(" ") @params << match[1] else @params = raw_params.split(" ") end end
Like reply, but using {Channel#safe_send}/{User#safe_send} instead
@param (see reply) @return (see reply)
# File lib/cinch/message.rb, line 163 def safe_reply(text, prefix = false) text = text.to_s if channel && prefix text = "#{user.nick}: #{text}" end (channel || user).safe_send(text) end
@return [String, nil]
# File lib/cinch/message.rb, line 57 def server return unless @prefix return if @prefix.match(/[@!]/) @server ||= @prefix[/^(\S+)/, 1] end
@return [String]
# File lib/cinch/message.rb, line 180 def to_s "#<Cinch::Message @raw=#{raw.chomp.inspect} @params=#{@params.inspect} channel=#{channel.inspect} user=#{user.inspect}>" end
@return [User] The user who sent this message
# File lib/cinch/message.rb, line 46 def user return unless @prefix nick = @prefix[/^(\S+)!/, 1] user = @prefix[/^\S+!(\S+)@/, 1] host = @prefix[/@(\S+)$/, 1] return nil if nick.nil? @user ||= @bot.user_manager.find_ensured(user, nick, host) end
Generated with the Darkfish Rdoc Generator 2.