Class: Cinch::Target
Overview
Instance Attribute Summary collapse
- #bot ⇒ Bot readonly
- #name ⇒ String readonly
Instance Method Summary collapse
- #<=>(other) ⇒ -1, ...
-
#action(text) ⇒ void
Invoke an action (/me) in/to the target.
- #concretize ⇒ Object
-
#ctcp(message) ⇒ void
Send a CTCP to the target.
- #eql?(other) ⇒ Boolean
-
#initialize(name, bot) ⇒ Target
constructor
A new instance of Target.
- #msg(*args) ⇒ Object deprecated Deprecated.
-
#notice(text) ⇒ void
Sends a NOTICE to the target.
- #privmsg(*args) ⇒ Object deprecated Deprecated.
-
#safe_action(text) ⇒ void
Like #action, but remove any non-printable characters from ‘text`.
- #safe_msg(*args) ⇒ Object deprecated Deprecated.
-
#safe_notice(text) ⇒ Object
Like #safe_msg but for notices.
- #safe_privmsg(*args) ⇒ Object deprecated Deprecated.
-
#safe_send(text, notice = false) ⇒ void
Like #send, but remove any non-printable characters from ‘text`.
-
#send(text, notice = false) ⇒ void
Sends a PRIVMSG to the target.
Constructor Details
#initialize(name, bot) ⇒ Target
Returns a new instance of Target.
12 13 14 15 |
# File 'lib/cinch/target.rb', line 12 def initialize(name, bot) @name = name @bot = bot end |
Instance Attribute Details
Instance Method Details
#<=>(other) ⇒ -1, ...
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/cinch/target.rb', line 151 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) end end |
#action(text) ⇒ void
This method returns an undefined value.
Invoke an action (/me) in/to the target.
107 108 109 110 |
# File 'lib/cinch/target.rb', line 107 def action(text) line = text.to_s.each_line.first.chomp @bot.irc.send("PRIVMSG #{@name} :\001ACTION #{line}\001") end |
#concretize ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/cinch/target.rb', line 136 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) ⇒ void
This method returns an undefined value.
Send a CTCP to the target.
132 133 134 |
# File 'lib/cinch/target.rb', line 132 def ctcp() send :"\001#{message}\001" end |
#eql?(other) ⇒ Boolean
145 146 147 |
# File 'lib/cinch/target.rb', line 145 def eql?(other) self == other end |
#msg(*args) ⇒ Object
53 54 55 56 |
# File 'lib/cinch/target.rb', line 53 def msg(*args) Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Target#msg", "Target#send") send(*args) end |
#notice(text) ⇒ void
This method returns an undefined value.
Sends a NOTICE to the target.
22 23 24 |
# File 'lib/cinch/target.rb', line 22 def notice(text) send(text, true) end |
#privmsg(*args) ⇒ Object
59 60 61 62 |
# File 'lib/cinch/target.rb', line 59 def privmsg(*args) Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Target#privmsg", "Target#send") send(*args) end |
#safe_action(text) ⇒ void
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.
124 125 126 |
# File 'lib/cinch/target.rb', line 124 def safe_action(text) action(Cinch::Helpers.sanitize(text)) end |
#safe_msg(*args) ⇒ Object
81 82 83 84 |
# File 'lib/cinch/target.rb', line 81 def safe_msg(*args) Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Target#safe_msg", "Target#safe_send") safe_send(*args) end |
#safe_notice(text) ⇒ Object
Like #safe_msg but for notices.
98 99 100 |
# File 'lib/cinch/target.rb', line 98 def safe_notice(text) safe_send(text, true) end |
#safe_privmsg(*args) ⇒ Object
87 88 89 90 |
# File 'lib/cinch/target.rb', line 87 def safe_privmsg(*args) Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Target#safe_privmsg", "Target#safe_send") safe_send(*args) end |
#safe_send(text, notice = false) ⇒ void
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.
76 77 78 |
# File 'lib/cinch/target.rb', line 76 def safe_send(text, notice = false) send(Cinch::Helpers.sanitize(text), notice) end |
#send(text, notice = false) ⇒ void
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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cinch/target.rb', line 34 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 |