Class: Cinch::Target
- Inherits:
-
Object
- Object
- Cinch::Target
- Includes:
- Comparable
- Defined in:
- lib/cinch/target.rb
Overview
Instance Attribute Summary (collapse)
-
- (Bot) bot
readonly
-
- (String) name
readonly
Instance Method Summary (collapse)
-
- (-1, ...) <=>(other)
-
- action(text)
Invoke an action (/me) in/to the target.
-
- (Object) concretize
-
- ctcp(message)
Send a CTCP to the target.
-
- (Boolean) eql?(other)
-
- (Target) initialize(name, bot)
constructor
A new instance of Target.
-
- msg(text, notice = false)
(also: #send, #privmsg)
Sends a PRIVMSG to the target.
-
- notice(text)
Sends a NOTICE to the target.
-
- safe_action(text)
Like #action, but remove any non-printable characters from
text. -
- safe_msg(text, notice = false)
(also: #safe_privmsg, #safe_send)
Like #msg, but remove any non-printable characters from
text. -
- safe_notice(text)
Like #safe_msg but for notices.
Constructor Details
- (Target) initialize(name, bot)
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
- (-1, ...) <=>(other)
139 140 141 142 143 144 145 146 147 148 149 150 |
# 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)
This method returns an undefined value.
Invoke an action (/me) in/to the target.
97 98 99 |
# File 'lib/cinch/target.rb', line 97 def action(text) @bot.irc.send("PRIVMSG #@name :\001ACTION #{text}\001") end |
- (Object) concretize
124 125 126 127 128 129 130 |
# 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)
This method returns an undefined value.
Send a CTCP to the target.
120 121 122 |
# File 'lib/cinch/target.rb', line 120 def ctcp() send "\001#{}\001" end |
- (Boolean) eql?(other)
133 134 135 |
# File 'lib/cinch/target.rb', line 133 def eql?(other) self == other end |
- msg(text, notice = false) Also known as: send, privmsg
This method returns an undefined value.
Sends a PRIVMSG to the target.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cinch/target.rb', line 30 def msg(text, notice = false) text = text.to_s split_start = @bot.config. || "" split_end = @bot.config. || "" 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. || 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 |
- 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) msg(text, true) end |
- safe_action(text)
Handle mIRC color codes more gracefully.
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.
112 113 114 |
# File 'lib/cinch/target.rb', line 112 def safe_action(text) action(Cinch::Utilities::String.filter_string(text)) end |
- safe_msg(text, notice = false) Also known as: safe_privmsg, safe_send
Handle mIRC color codes more gracefully.
This method returns an undefined value.
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.
75 76 77 |
# File 'lib/cinch/target.rb', line 75 def safe_msg(text, notice = false) msg(Cinch::Utilities::String.filter_string(text), notice) end |
- safe_notice(text)
Handle mIRC color codes more gracefully.
This method returns an undefined value.
Like #safe_msg but for notices.
88 89 90 |
# File 'lib/cinch/target.rb', line 88 def safe_notice(text) safe_msg(text, true) end |