class Cinch::Target
@since 2.0.0
Attributes
@return [Bot]
@return [String]
Public Class Methods
# File lib/cinch/target.rb, line 10 def initialize(name, bot) @name = name @bot = bot end
Public Instance Methods
@param [Target, String] other @return [-1, 0, 1, nil]
# File lib/cinch/target.rb, line 173 def <=>(other) casemapping = @bot.irc.isupport["CASEMAPPING"] left = @name.irc_downcase(casemapping) if other.is_a?(Target) left <=> other.name.irc_downcase(casemapping) elsif other.is_a?(String) left <=> other.irc_downcase(casemapping) else nil end end
Invoke an action (/me) in/to the target.
@param [#to_s] text the message to send @return [void] @see safe_action
# File lib/cinch/target.rb, line 130 def action(text) @bot.irc.send("PRIVMSG #@name :\001ACTION #{text}\001") end
# File lib/cinch/target.rb, line 158 def concretize if @bot.isupport["CHANTYPES"].include?(@name[0]) @bot.channel_list.find_ensured(@name) else @bot.user_list.find_ensured(@name) end end
Send a CTCP to the target.
@param [#to_s] message the ctcp message @return [void]
# File lib/cinch/target.rb, line 154 def ctcp(message) send "\001#{message}\001" end
@return [Boolean]
# File lib/cinch/target.rb, line 167 def eql?(other) self == other end
Sends a NOTICE to the target.
@param [#to_s] text the message to send @return [void] @see safe_notice
# File lib/cinch/target.rb, line 20 def notice(text) msg(text, true) end
Like {#action}, but remove any non-printable characters from `text`. The purpose of this method is to send text from untrusted sources, like other users or feeds.
Note: this will *break* any mIRC color codes embedded in the string. For more fine-grained control, use {Helpers#Sanitize} and {Formatting.unformat} directly.
@param (see action
) @return (see action
) @see action
# File lib/cinch/target.rb, line 146 def safe_action(text) action(Cinch::Helpers.Sanitize(text)) end
Like {#safe_msg} but for notices.
@return (see safe_msg
) @param (see safe_msg
) @see safe_notice
@see notice
# File lib/cinch/target.rb, line 121 def safe_notice(text) safe_msg(text, true) end
Like {#send}, but remove any non-printable characters from `text`. The purpose of this method is to send text of untrusted sources, like other users or feeds.
Note: this will *break* any mIRC color codes embedded in the string. For more fine-grained control, use {Helpers#Sanitize} and {Formatting.unformat} directly.
@return (see send
) @param (see send
) @see send
# File lib/cinch/target.rb, line 94 def safe_send(text, notice = false) send(Cinch::Helpers.sanitize(text), notice) end
Sends a PRIVMSG to the target.
@param [#to_s] text the message to send @param [Boolean] notice Use NOTICE instead of PRIVMSG? @return [void] @see safe_msg
@note The aliases `msg` and `privmsg` are deprecated and will be
removed in a future version.
# File lib/cinch/target.rb, line 32 def send(text, notice = false) # TODO deprecate `notice` argument, put splitting into own # method text = text.to_s split_start = @bot.config.message_split_start || "" split_end = @bot.config.message_split_end || "" command = notice ? "NOTICE" : "PRIVMSG" text.split(/\r\n|\r|\n/).each do |line| maxlength = 510 - (":" + " #{command} " + " :").size maxlength = maxlength - @bot.mask.to_s.length - @name.to_s.length maxlength_without_end = maxlength - split_end.bytesize if line.bytesize > maxlength splitted = [] while line.bytesize > maxlength_without_end pos = line.rindex(/\s/, maxlength_without_end) r = pos || maxlength_without_end splitted << line.slice!(0, r) + split_end.tr(" ", "\u00A0") line = split_start.tr(" ", "\u00A0") + line.lstrip end splitted << line splitted[0, (@bot.config.max_messages || splitted.size)].each do |string| string.tr!("\u00A0", " ") # clean string from any non-breaking spaces @bot.irc.send("#{command} #@name :#{string}") end else @bot.irc.send("#{command} #@name :#{line}") end end end