Class: Cinch::Target
Overview
Instance Attribute Summary collapse
-
#bot ⇒ Bot
readonly
-
#name ⇒ String
readonly
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
-
#action(text)
Invoke an action (/me) in/to the target.
-
#concretize ⇒ Object
-
#ctcp(message)
Send a CTCP to the target.
-
#eql?(other) ⇒ Boolean
-
#initialize(name, bot) ⇒ Target
constructor
A new instance of Target.
-
#notice(text)
Sends a NOTICE to the target.
-
#safe_action(text)
Like #action, but remove any non-printable characters from
text
. -
#safe_notice(text) ⇒ Object
Like #safe_msg but for notices.
-
#safe_privmsg(*args) ⇒ Object
deprecated
Deprecated.
-
#safe_send(text, notice = false)
(also: #safe_msg)
Like #send, but remove any non-printable characters from
text
. -
#send(text, notice = false)
(also: #msg, #privmsg)
Sends a PRIVMSG to the target.
Constructor Details
#initialize(name, bot) ⇒ Target
Returns a new instance of Target.
10 11 12 13 |
# File 'lib/cinch/target.rb', line 10 def initialize(name, bot) @name = name @bot = bot end |
Instance Attribute Details
Instance Method Details
#<=>(other) ⇒ -1, ...
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/cinch/target.rb', line 157 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)
This method returns an undefined value.
Invoke an action (/me) in/to the target.
114 115 116 |
# File 'lib/cinch/target.rb', line 114 def action(text) @bot.irc.send("PRIVMSG #@name :\001ACTION #{text}\001") end |
#concretize ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/cinch/target.rb', line 142 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)
This method returns an undefined value.
Send a CTCP to the target.
138 139 140 |
# File 'lib/cinch/target.rb', line 138 def ctcp() send "\001#{}\001" end |
#eql?(other) ⇒ Boolean
151 152 153 |
# File 'lib/cinch/target.rb', line 151 def eql?(other) self == other end |
#notice(text)
This method returns an undefined value.
Sends a NOTICE to the target.
20 21 22 |
# File 'lib/cinch/target.rb', line 20 def notice(text) send(text, true) end |
#safe_action(text)
This method returns an undefined value.
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.
130 131 132 |
# File 'lib/cinch/target.rb', line 130 def safe_action(text) action(Cinch::Helpers.Sanitize(text)) end |
#safe_notice(text) ⇒ Object
Like #safe_msg but for notices.
105 106 107 |
# File 'lib/cinch/target.rb', line 105 def safe_notice(text) safe_send(text, true) end |
#safe_privmsg(*args) ⇒ Object
93 94 95 |
# File 'lib/cinch/target.rb', line 93 def safe_send(text, notice = false) send(Cinch::Helpers.sanitize(text), notice) end |
#safe_send(text, notice = false) Also known as: safe_msg
This method returns an undefined value.
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.
78 79 80 |
# File 'lib/cinch/target.rb', line 78 def safe_send(text, notice = false) send(Cinch::Helpers.sanitize(text), notice) end |
#send(text, notice = false) Also known as: msg, privmsg
The aliases msg
and privmsg
are deprecated and will be
removed in a future version.
This method returns an undefined value.
Sends a PRIVMSG to the target.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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. || "" split_end = @bot.config. || "" command = notice ? "NOTICE" : "PRIVMSG" prefix = ":#{@bot.mask} #{command} #{@name} :" text.lines.map(&:chomp).each do |line| splitted = (line, prefix, split_start, split_end) splitted[0, (@bot.config. || splitted.size)].each do |string| @bot.irc.send("#{command} #@name :#{string}") end end end |