Parent

Included Modules

Class/Module Index [+]

Quicksearch

Cinch::Target

@since 2.0.0

Attributes

bot[R]

@return [Bot]

name[R]

@return [String]

Public Class Methods

new(name, bot) click to toggle source
# File lib/cinch/target.rb, line 10
def initialize(name, bot)
  @name = name
  @bot  = bot
end

Public Instance Methods

<=>(other) click to toggle source

@param [Target, String] @return [-1, 0, 1, nil]

# File lib/cinch/target.rb, line 139
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
action(text) click to toggle source

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 97
def action(text)
  @bot.irc.send("PRIVMSG #@name :\0001ACTION #{text}\0001")
end
concretize() click to toggle source
# File lib/cinch/target.rb, line 124
def concretize
  if @bot.isupport["CHANTYPES"].include?(@name[0])
    @bot.channel_list.find_ensured(@name)
  else
    @bot.user_list.find_ensured(@name)
  end
end
ctcp(message) click to toggle source

Send a CTCP to the target.

@param [to_s] message the ctcp message @return [void]

# File lib/cinch/target.rb, line 120
def ctcp(message)
  send "\0001#{message}\0001"
end
eql?(other) click to toggle source

@return [Boolean]

# File lib/cinch/target.rb, line 133
def eql?(other)
  self == other
end
msg(text, notice = false) click to toggle source

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

# File lib/cinch/target.rb, line 30
def msg(text, notice = false)
  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
Also aliased as: send, privmsg
notice(text) click to toggle source

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
privmsg(text, notice = false) click to toggle source
Alias for: msg
safe_action(text) click to toggle source

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.

@param (see action) @return (see action) @see action @todo Handle mIRC color codes more gracefully.

# File lib/cinch/target.rb, line 112
def safe_action(text)
  action(Cinch::Utilities::String.filter_string(text))
end
safe_msg(text, notice = false) click to toggle source

Like {msg}, 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.

@return (see msg) @param (see msg) @see msg @todo Handle mIRC color codes more gracefully.

# File lib/cinch/target.rb, line 75
def safe_msg(text, notice = false)
  msg(Cinch::Utilities::String.filter_string(text), notice)
end
Also aliased as: safe_privmsg, safe_send
safe_notice(text) click to toggle source

Like {safe_msg} but for notices.

@return (see safe_msg) @param (see safe_msg) @see safe_notice @see notice @todo (see safe_msg)

# File lib/cinch/target.rb, line 88
def safe_notice(text)
  safe_msg(text, true)
end
safe_privmsg(text, notice = false) click to toggle source
Alias for: safe_msg
safe_send(text, notice = false) click to toggle source
Alias for: safe_msg
send(text, notice = false) click to toggle source
Alias for: msg

[Validate]

Generated with the Darkfish Rdoc Generator 2.