cinch 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,10 +12,8 @@ profits flourish.
12
12
  Cinch will do all of the hard work for you, so you can spend time creating cool
13
13
  plugins and extensions to wow your internet peers.
14
14
 
15
- If you'd like to test your own Cinch experiments you can do so in the
16
- \#cinch-bots IRC channel on
17
- [irc.freenode.org](irc://irc.freenode.org/cinch-bots). For general
18
- support, join [#cinch](irc://irc.freenode.org/cinch).
15
+ For general support, join [#cinch](irc://irc.freenode.org/cinch) but
16
+ please don't bring any bots.
19
17
 
20
18
  Installation
21
19
  ------------
@@ -156,11 +154,6 @@ on :message, /hello/ do |m|
156
154
  end
157
155
  ```
158
156
 
159
- Authors
160
- -------
161
-
162
- * [Dominik Honnef](http://dominik.honnef.co)
163
-
164
157
  Contribute
165
158
  ----------
166
159
 
@@ -175,11 +168,3 @@ of supporting Ruby versions below 1.9.1.
175
168
  Fork the project, implement your awesome feature in its own branch, and send
176
169
  a pull request to one of the Cinch collaborators. We'll be more than happy
177
170
  to check it out.
178
-
179
- ### Contributors
180
- - darix <darix [at] nordisch.org> (wrote the message splitting algorithm)
181
- - robgleeson (thanks for testing, contributing a lot of ideas,
182
- discussing design decisions etc)
183
- - Emil Loer (http://github.com/thedjinn) for improving the handling of
184
- unexpected disconnects and reconnects.
185
- - Check the list of authors for smaller contributions
@@ -430,5 +430,5 @@ Default value
430
430
  : `10`
431
431
 
432
432
  Description
433
- : Give up connecting after his amount of seconds.
433
+ : Give up connecting after this amount of seconds.
434
434
 
@@ -1,6 +1,54 @@
1
1
  # @title What has changed?
2
2
  # @markup kramdown
3
3
 
4
+ # What has changed in 2.2?
5
+
6
+ ## Getting rid of CP1252 in favour of UTF-8
7
+
8
+ In versions before 2.2, when using the `irc` encoding (the default),
9
+ Cinch would use CP1252 for outgoing messages, only falling back to
10
+ UTF-8 if a message wouldn't fit into CP1252. This is a so called
11
+ hybrid encoding, which is used by X-Chat and the like.
12
+
13
+ This encoding, however, is based on the state of 10 years ago, where
14
+ the most popular IRC clients, such as mIRC, weren't capable of
15
+ handling UTF-8. Nowadays, there are more clients that support UTF-8
16
+ than there are clients that can deal with this hybrid encoding, or
17
+ CP1252 itself. That's why, from now on, we will always use UTF-8.
18
+
19
+ If you depend on outgoing messages being encoded in CP1252, please see
20
+ {file:docs/encodings.md} on how to change the encoding.
21
+
22
+ ## API improvements
23
+
24
+ ### New methods
25
+
26
+ - {Cinch::Channel#remove} has been added to support the non-standard
27
+ REMOVE command, a friendlier alternative to kicking people.
28
+
29
+ - {Cinch::Helpers.sanitize} and {Cinch::Formatting.unformat} have been
30
+ added to help with removing unprintable characters and mIRC
31
+ formatting codes from strings.
32
+
33
+ ### Deprecated methods
34
+
35
+ In order to reduce the amount of aliases, the following ones have been
36
+ deprecated and will be removed in a future release:
37
+
38
+ - {Cinch::Channel#msg}
39
+ - {Cinch::Channel#privmsg}
40
+ - {Cinch::Target#msg}
41
+ - {Cinch::Target#privmsg}
42
+ - {Cinch::Target#safe_msg}
43
+ - {Cinch::Target#safe_privmsg}
44
+ - {Cinch::User#whois}
45
+ - {Cinch::Helpers#Color}
46
+
47
+ Additionally, the following method is deprecated and will be removed
48
+ in the future:
49
+
50
+ - {Cinch::Channel#to_str}
51
+
4
52
  # What has changed in 2.1?
5
53
  1. Color stripping
6
54
  1. Per group hooks
@@ -11,12 +59,13 @@
11
59
 
12
60
  ## Color stripping
13
61
 
14
- The new method {Cinch::Utilities::String.strip_colors} allows removal
15
- of mIRC color codes from messages.
62
+ The new method <del>`Cinch::Utilities::String.strip_colors`</del>
63
+ {Cinch::Formatting.unformat} allows removal of mIRC color codes from
64
+ messages.
16
65
 
17
66
  Additionally, a new match option called `strip_colors` makes it
18
67
  possible to automatically and temporarily strip color codes before
19
- attemping to match a message.
68
+ attempting to match a message.
20
69
 
21
70
  ## Per group hooks
22
71
 
@@ -4,7 +4,7 @@
4
4
  # Checking if a user is online
5
5
 
6
6
  Cinch by itself tries to keep track of the online state of users.
7
- Whenever it sees someone speak, change his nick or be in a channel the
7
+ Whenever it sees someone speak, change their nick or be in a channel the
8
8
  bot is also in, it'll set the user to being online. And when a user
9
9
  quits, gets killed or cannot be whoised/contacted, its state will be
10
10
  set to offline.
@@ -5,6 +5,8 @@ require 'cinch'
5
5
  #
6
6
  # Enable with !autovoice on
7
7
  # Disable with !autovoice off
8
+ #
9
+ # It starts out disabled.
8
10
 
9
11
  bot = Cinch::Bot.new do
10
12
  configure do |c|
@@ -12,8 +14,6 @@ bot = Cinch::Bot.new do
12
14
  c.server = "irc.freenode.org"
13
15
  c.verbose = true
14
16
  c.channels = ["#cinch-bots"]
15
-
16
- @autovoice = true
17
17
  end
18
18
 
19
19
  on :join do |m|
@@ -15,7 +15,7 @@ bot = Cinch::Bot.new do
15
15
  # or "No results found" otherwise
16
16
  def google(query)
17
17
  url = "http://www.google.com/search?q=#{CGI.escape(query)}"
18
- res = Nokogiri::HTML(open(url)).at("h3.r")
18
+ res = Nokogiri.parse(open(url).read).at("h3.r")
19
19
 
20
20
  title = res.text
21
21
  link = res.at('a')[:href]
@@ -1,18 +1,18 @@
1
1
  require 'cinch'
2
2
 
3
+ # Who should be able to access these plugins
4
+ $admin = "injekt"
5
+
3
6
  bot = Cinch::Bot.new do
4
7
  configure do |c|
5
8
  c.server = "irc.freenode.org"
6
9
  c.nick = "CinchBot"
7
10
  c.channels = ["#cinch-bots"]
8
-
9
- # Who should be able to access these plugins
10
- @admin = "injekt"
11
11
  end
12
12
 
13
13
  helpers do
14
14
  def is_admin?(user)
15
- true if user.nick == @admin
15
+ true if user.nick == $admin
16
16
  end
17
17
  end
18
18
 
@@ -8,29 +8,29 @@ class Memo < Struct.new(:nick, :channel, :text, :time)
8
8
  end
9
9
  end
10
10
 
11
+ $memos = {}
12
+
11
13
  bot = Cinch::Bot.new do
12
14
  configure do |c|
13
15
  c.server = "irc.freenode.org"
14
16
  c.channels = ["#cinch-bots"]
15
-
16
- @memos = {}
17
17
  end
18
18
 
19
19
  on :message do |m|
20
- if @memos.has_key?(m.user.nick)
21
- m.user.send @memos.delete(m.user.nick).to_s
20
+ if $memos.has_key?(m.user.nick)
21
+ m.user.send $memos.delete(m.user.nick).to_s
22
22
  end
23
23
  end
24
24
 
25
25
  on :message, /^!memo (.+?) (.+)/ do |m, nick, message|
26
- if @memos.key?(nick)
26
+ if $memos.key?(nick)
27
27
  m.reply "There's already a memo for #{nick}. You can only store one right now"
28
28
  elsif nick == m.user.nick
29
29
  m.reply "You can't leave memos for yourself.."
30
30
  elsif nick == bot.nick
31
31
  m.reply "You can't leave memos for me.."
32
32
  else
33
- @memos[nick] = Memo.new(m.user.nick, m.channel, message, Time.now)
33
+ $memos[nick] = Memo.new(m.user.nick, m.channel, message, Time.now)
34
34
  m.reply "Added memo for #{nick}"
35
35
  end
36
36
  end
@@ -6,17 +6,17 @@ class Seen < Struct.new(:who, :where, :what, :time)
6
6
  end
7
7
  end
8
8
 
9
+ $users = {}
10
+
9
11
  bot = Cinch::Bot.new do
10
12
  configure do |c|
11
13
  c.server = 'irc.freenode.org'
12
14
  c.channels = ["#cinch-bots"]
13
-
14
- @users = {}
15
15
  end
16
16
 
17
17
  # Only log channel messages
18
18
  on :channel do |m|
19
- @users[m.user.nick] = Seen.new(m.user.nick, m.channel, m.message, Time.new)
19
+ $users[m.user.nick] = Seen.new(m.user.nick, m.channel, m.message, Time.new)
20
20
  end
21
21
 
22
22
  on :channel, /^!seen (.+)/ do |m, nick|
@@ -24,8 +24,8 @@ bot = Cinch::Bot.new do
24
24
  m.reply "That's me!"
25
25
  elsif nick == m.user.nick
26
26
  m.reply "That's you!"
27
- elsif @users.key?(nick)
28
- m.reply @users[nick].to_s
27
+ elsif $users.key?(nick)
28
+ m.reply $users[nick].to_s
29
29
  else
30
30
  m.reply "I haven't seen #{nick}"
31
31
  end
@@ -9,7 +9,7 @@ class Google
9
9
 
10
10
  def search(query)
11
11
  url = "http://www.google.com/search?q=#{CGI.escape(query)}"
12
- res = Nokogiri::HTML(open(url)).at("h3.r")
12
+ res = Nokogiri.parse(open(url).read).at("h3.r")
13
13
 
14
14
  title = res.text
15
15
  link = res.at('a')[:href]
@@ -5,8 +5,8 @@ class Nickchange
5
5
  listen_to :nick
6
6
 
7
7
  def listen(m)
8
- # This will send a PM to the user who changed his nick and inform
9
- # him of his old nick.
8
+ # This will send a PM to the user who changed their nick and inform
9
+ # them of their old nick.
10
10
  m.reply "Your old nick was: #{m.user.last_nick}" ,true
11
11
  end
12
12
  end
@@ -1,6 +1,5 @@
1
1
  require 'cinch/version'
2
2
  require 'cinch/utilities/kernel'
3
- require 'cinch/utilities/string'
4
3
  require 'cinch/utilities/deprecation'
5
4
  require 'cinch/utilities/encoding'
6
5
  require 'cinch/bot'
@@ -332,6 +332,21 @@ module Cinch
332
332
  @bot.irc.send("KICK #@name #{user} :#{reason}")
333
333
  end
334
334
 
335
+ # Removes a user from the channel.
336
+ #
337
+ # This uses the REMOVE command, which is a non-standardized
338
+ # extension. Unlike a kick, it makes a user part. This prevents
339
+ # auto-rejoin scripts from firing and might also be perceived as
340
+ # less aggressive by some. Not all IRC networks support this
341
+ # command.
342
+ #
343
+ # @param [User] user the user to remove
344
+ # @param [String] reason a reason for the removal
345
+ # @return [void]
346
+ def remove(user, reason = nil)
347
+ @bot.irc.send("REMOVE #@name #{user} :#{reason}")
348
+ end
349
+
335
350
  # Sets or unsets modes. Most of the time you won't need this but
336
351
  # use setter methods like {Channel#invite_only=}.
337
352
  #
@@ -388,17 +403,34 @@ module Cinch
388
403
  @users.clear
389
404
  end
390
405
 
391
- def msg(text, notice = false)
406
+ # @note The aliases `msg` and `privmsg` are deprecated and will be
407
+ # removed in a future version.
408
+ def send(text, notice = false)
409
+ # TODO deprecate 'notice' argument
392
410
  text = text.to_s
393
411
  if @modes["c"]
394
412
  # Remove all formatting and colors if the channel doesn't
395
413
  # allow colors.
396
- text.gsub!(/[\x02\x1F\x16\x0F]|\x03\d{2}(,\d{2})?/, "")
414
+ text = Cinch::Formatting.unformat(text)
397
415
  end
398
416
  super(text, notice)
399
417
  end
400
- alias_method :send, :msg
401
- alias_method :privmsg, :msg
418
+ alias_method :msg, :send # deprecated
419
+ alias_method :privmsg, :send # deprecated
420
+ undef_method(:msg) # yardoc hack
421
+ undef_method(:privmsg) # yardoc hack
422
+
423
+ # @deprecated
424
+ def msg(*args)
425
+ Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Channel#msg", "Channel#send")
426
+ send(*args)
427
+ end
428
+
429
+ # @deprecated
430
+ def privmsg(*args)
431
+ Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Channel#privmsg", "Channel#send")
432
+ send(*args)
433
+ end
402
434
 
403
435
  # @return [Fixnum]
404
436
  def hash
@@ -406,10 +438,19 @@ module Cinch
406
438
  end
407
439
 
408
440
  # @return [String]
441
+ # @note The alias `to_str` is deprecated and will be removed in a
442
+ # future version. Channel objects should not be treated like
443
+ # strings.
409
444
  def to_s
410
445
  @name
411
446
  end
412
- alias_method :to_str, :to_s
447
+ alias_method :to_str, :to_s # deprecated
448
+ undef_method(:to_str) # yardoc hack
449
+
450
+ def to_str
451
+ Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Channel#to_str", "Channel#to_s")
452
+ to_s
453
+ end
413
454
 
414
455
  # @return [String]
415
456
  def inspect
@@ -1,6 +1,6 @@
1
1
  module Cinch
2
- # This module can be used for adding colors and formatting to
3
- # messages.
2
+ # This module can be used for adding and removing colors and
3
+ # formatting to/from messages.
4
4
  #
5
5
  # The format codes used are those defined by mIRC, which are also
6
6
  # the ones supported by most clients.
@@ -74,7 +74,7 @@ module Cinch
74
74
  # When supplying two colors, the first will be used for the
75
75
  # foreground and the second for the background.
76
76
  # @param [String] string The string to format.
77
- # @return [String] The formatted string
77
+ # @return [String] the formatted string
78
78
  # @since 2.0.0
79
79
  # @raise [ArgumentError] When passing more than two colors as arguments.
80
80
  # @see Helpers#Format Helpers#Format for easier access to this method.
@@ -110,5 +110,16 @@ module Cinch
110
110
  string.gsub!(/#{Attributes[:reset]}/, Attributes[:reset] + prepend)
111
111
  return prepend + string + append
112
112
  end
113
+
114
+ # Deletes all mIRC formatting codes from the string. This strips
115
+ # formatting for bold, underline and so on, as well as color
116
+ # codes. This does include removing the numeric arguments.
117
+ #
118
+ # @param [String] string The string to filter
119
+ # @return [String] The filtered string
120
+ # @since 2.2.0
121
+ def self.unformat(string)
122
+ string.gsub(/[\x02\x0f\x16\x1f\x12]|\x03(\d{1,2}(,\d{1,2})?)?/, '')
123
+ end
113
124
  end
114
125
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  module Cinch
2
3
  # The Helpers module contains a number of methods whose purpose is
3
4
  # to make writing plugins easier by hiding parts of the API. The
@@ -182,7 +183,48 @@ module Cinch
182
183
  def Format(*settings, string)
183
184
  Formatting.format(*settings, string)
184
185
  end
185
- alias_method :Color, :Format
186
+ alias_method :Color, :Format # deprecated
187
+ undef_method(:Color) # yardoc hack
188
+
189
+ def Color(*args)
190
+ Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Helpers.Color", "Helpers.Format")
191
+ Format(*args)
192
+ end
193
+
194
+ # (see .sanitize)
195
+ def Sanitize(string)
196
+ Cinch::Helpers.sanitize(string)
197
+ end
198
+
199
+ # Deletes all characters in the ranges 0–8, 10–31 as well as the
200
+ # character 127, that is all non-printable characters and
201
+ # newlines.
202
+ #
203
+ # This method is useful for filtering text from external sources
204
+ # before sending it to IRC.
205
+ #
206
+ # Note that this method does not gracefully handle mIRC color
207
+ # codes, because it will leave the numeric arguments behind. If
208
+ # your text comes from IRC, you may want to filter it through
209
+ # {#Unformat} first. If you want to send sanitized input that
210
+ # includes your own formatting, first use this method, then add
211
+ # your formatting.
212
+ #
213
+ # There exist methods for sending messages that automatically
214
+ # call this method, namely {Target#safe_msg},
215
+ # {Target#safe_notice}, and {Target#safe_action}.
216
+ #
217
+ # @param [String] string The string to filter
218
+ # @return [String] The filtered string
219
+ # @since 2.2.0
220
+ def self.sanitize(string)
221
+ string.gsub(/[\x00-\x08\x10-\x1f\x7f]/, '')
222
+ end
223
+
224
+ # (see Formatting.unformat)
225
+ def Unformat(string)
226
+ Formatting.unformat(string)
227
+ end
186
228
 
187
229
  # @endgroup
188
230
  end
@@ -632,7 +632,7 @@ module Cinch
632
632
  def on_313(msg, events)
633
633
  # RPL_WHOISOPERATOR
634
634
  user = User(msg.params[1])
635
- @whois_updates[user].merge!({:oper? => true})
635
+ update_whois(user, {:oper? => true})
636
636
  end
637
637
 
638
638
  def on_317(msg, events)
@@ -648,21 +648,21 @@ module Cinch
648
648
  # RPL_ENDOFWHOIS
649
649
  user = User(msg.params[1])
650
650
 
651
- if @whois_updates[user]
652
- if @whois_updates[user].empty? && !user.attr(:unknown?, true, true)
653
- user.end_of_whois(nil)
654
- else
655
- user.end_of_whois(@whois_updates[user])
656
- end
657
- @whois_updates.delete user
651
+ if @whois_updates[user].nil? ||
652
+ (@whois_updates[user].empty? && !user.attr(:unknown?, true, true))
653
+ user.end_of_whois(nil)
654
+ return
658
655
  end
656
+
657
+ user.end_of_whois(@whois_updates[user])
658
+ @whois_updates.delete user
659
659
  end
660
660
 
661
661
  def on_319(msg, events)
662
662
  # RPL_WHOISCHANNELS
663
663
  user = User(msg.params[1])
664
664
  channels = msg.params[2].scan(/[#{@isupport["CHANTYPES"].join}][^ ]+/o).map {|c| Channel(c) }
665
- @whois_updates[user].merge!({:channels => channels})
665
+ update_whois(user, {:channels => channels})
666
666
  end
667
667
 
668
668
  def on_324(msg, events)
@@ -685,8 +685,7 @@ module Cinch
685
685
  # RPL_WHOISACCOUNT
686
686
  user = User(msg.params[1])
687
687
  authname = msg.params[2]
688
-
689
- @whois_updates[user].merge!({:authname => authname})
688
+ update_user(user, {:authname => authname})
690
689
  end
691
690
 
692
691
  def on_331(msg, events)
@@ -851,7 +850,7 @@ module Cinch
851
850
 
852
851
  def on_671(msg, events)
853
852
  user = User(msg.params[1])
854
- @whois_updates[user].merge!({:secure? => true})
853
+ update_whois(user, {:secure? => true})
855
854
  end
856
855
 
857
856
  # @since 2.0.0
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require "time"
3
- require "cinch/utilities/string"
3
+ require "cinch/formatting"
4
4
 
5
5
  module Cinch
6
6
  # This class serves two purposes. For one, it simply
@@ -149,7 +149,7 @@ module Cinch
149
149
  end
150
150
 
151
151
  if strip_colors
152
- text = Cinch::Utilities::String.strip_colors(text)
152
+ text = Cinch::Formatting.unformat(text)
153
153
  end
154
154
 
155
155
  @matches[type][regexp] ||= text.match(regexp)
@@ -226,7 +226,6 @@ module Cinch
226
226
  end
227
227
 
228
228
  def parse_params(raw_params)
229
- raw_params = raw_params.strip
230
229
  params = []
231
230
  if match = raw_params.match(/(?:^:| :)(.*)$/)
232
231
  params = match.pre_match.split(" ")
@@ -250,12 +249,19 @@ module Cinch
250
249
 
251
250
  def parse_channel
252
251
  # has to be called after parse_params
252
+ return nil if @params.empty?
253
+
253
254
  case @command
254
255
  when "INVITE", Constants::RPL_CHANNELMODEIS.to_s, Constants::RPL_BANLIST.to_s
255
256
  @bot.channel_list.find_ensured(@params[1])
256
257
  when Constants::RPL_NAMEREPLY.to_s
257
258
  @bot.channel_list.find_ensured(@params[2])
258
259
  else
260
+ # Note that this will also find channels for messages that
261
+ # don't actually include a channel parameter. For example
262
+ # `QUIT :#sometext` will be interpreted as a channel. The
263
+ # alternative to the currently used heuristic would be to
264
+ # hardcode a list of commands that provide a channel argument.
259
265
  chantypes = @bot.irc.isupport["CHANTYPES"]
260
266
  if chantypes.include?(@params.first[0])
261
267
  @bot.channel_list.find_ensured(@params.first)
@@ -1,3 +1,5 @@
1
+ require "cinch/exceptions"
2
+
1
3
  module Cinch
2
4
  # @api private
3
5
  # @since 1.1.0
@@ -8,11 +10,11 @@ module Cinch
8
10
  # A mapping describing which modes require parameters
9
11
  def self.parse_modes(modes, params, param_modes = {})
10
12
  if modes.size == 0
11
- raise InvalidModeString, 'Empty mode string'
13
+ raise Exceptions::InvalidModeString, 'Empty mode string'
12
14
  end
13
15
 
14
16
  if modes[0] !~ /[+-]/
15
- raise InvalidModeString, "Malformed modes string: %s" % modes
17
+ raise Exceptions::InvalidModeString, "Malformed modes string: %s" % modes
16
18
  end
17
19
 
18
20
  changes = []
@@ -23,7 +25,7 @@ module Cinch
23
25
  modes.each_char do |ch|
24
26
  if ch =~ /[+-]/
25
27
  if count == 0
26
- raise InvalidModeString, 'Empty mode sequence: %s' % modes
28
+ raise Exceptions::InvalidModeString, 'Empty mode sequence: %s' % modes
27
29
  end
28
30
 
29
31
  direction = case ch
@@ -39,7 +41,7 @@ module Cinch
39
41
  if params.size > 0
40
42
  param = params.shift
41
43
  else
42
- raise InvalidModeString, 'Not enough parameters: %s' % ch.inspect
44
+ raise Exceptions::InvalidModeString, 'Not enough parameters: %s' % ch.inspect
43
45
  end
44
46
  end
45
47
  changes << [direction, ch, param]
@@ -48,11 +50,11 @@ module Cinch
48
50
  end
49
51
 
50
52
  if params.size > 0
51
- raise InvalidModeString, 'Too many parameters: %s %s' % [modes, params].inspect
53
+ raise Exceptions::InvalidModeString, 'Too many parameters: %s %s' % [modes, params]
52
54
  end
53
55
 
54
56
  if count == 0
55
- raise InvalidModeString, 'Empty mode sequence: %r' % modes
57
+ raise Exceptions::InvalidModeString, 'Empty mode sequence: %s' % modes
56
58
  end
57
59
 
58
60
  return changes
@@ -27,7 +27,11 @@ module Cinch
27
27
  # @param [Boolean] notice Use NOTICE instead of PRIVMSG?
28
28
  # @return [void]
29
29
  # @see #safe_msg
30
- def msg(text, notice = false)
30
+ # @note The aliases `msg` and `privmsg` are deprecated and will be
31
+ # removed in a future version.
32
+ def send(text, notice = false)
33
+ # TODO deprecate `notice` argument, put splitting into own
34
+ # method
31
35
  text = text.to_s
32
36
  split_start = @bot.config.message_split_start || ""
33
37
  split_end = @bot.config.message_split_end || ""
@@ -58,25 +62,55 @@ module Cinch
58
62
  end
59
63
  end
60
64
  end
61
- alias_method :send, :msg
62
- alias_method :privmsg, :msg
65
+ alias_method :msg, :send # deprecated
66
+ alias_method :privmsg, :send # deprecated
67
+ undef_method(:msg) # yardoc hack
68
+ undef_method(:privmsg) # yardoc hack
69
+
70
+ # @deprecated
71
+ def msg(*args)
72
+ Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Target#msg", "Target#send")
73
+ send(*args)
74
+ end
75
+
76
+ # @deprecated
77
+ def privmsg(*args)
78
+ Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Target#privmsg", "Target#send")
79
+ send(*args)
80
+ end
63
81
 
64
- # Like {#msg}, but remove any non-printable characters from
82
+ # Like {#send}, but remove any non-printable characters from
65
83
  # `text`. The purpose of this method is to send text of untrusted
66
84
  # sources, like other users or feeds.
67
85
  #
68
86
  # Note: this will **break** any mIRC color codes embedded in the
69
- # string.
87
+ # string. For more fine-grained control, use
88
+ # {Helpers#Sanitize} and
89
+ # {Formatting.unformat} directly.
70
90
  #
71
- # @return (see #msg)
72
- # @param (see #msg)
73
- # @see #msg
74
- # @todo Handle mIRC color codes more gracefully.
75
- def safe_msg(text, notice = false)
76
- msg(Cinch::Utilities::String.filter_string(text), notice)
91
+ # @return (see #send)
92
+ # @param (see #send)
93
+ # @see #send
94
+ def safe_send(text, notice = false)
95
+ send(Cinch::Helpers.sanitize(text), notice)
96
+ end
97
+ alias_method :safe_msg, :safe_send # deprecated
98
+ alias_method :safe_privmsg, :safe_msg # deprecated
99
+ undef_method(:safe_msg) # yardoc hack
100
+ undef_method(:safe_privmsg) # yardoc hack
101
+
102
+ # @deprecated
103
+ def safe_msg(*args)
104
+ Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Target#safe_msg", "Target#safe_send")
105
+ send(*args)
77
106
  end
78
- alias_method :safe_privmsg, :safe_msg
79
- alias_method :safe_send, :safe_msg
107
+
108
+ # @deprecated
109
+ def safe_privmsg(*args)
110
+ Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "Target#safe_privmsg", "Target#safe_send")
111
+ send(*args)
112
+ end
113
+
80
114
 
81
115
  # Like {#safe_msg} but for notices.
82
116
  #
@@ -84,7 +118,6 @@ module Cinch
84
118
  # @param (see #safe_msg)
85
119
  # @see #safe_notice
86
120
  # @see #notice
87
- # @todo (see #safe_msg)
88
121
  def safe_notice(text)
89
122
  safe_msg(text, true)
90
123
  end
@@ -103,14 +136,15 @@ module Cinch
103
136
  # untrusted sources, like other users or feeds.
104
137
  #
105
138
  # Note: this will **break** any mIRC color codes embedded in the
106
- # string.
139
+ # string. For more fine-grained control, use
140
+ # {Helpers#Sanitize} and
141
+ # {Formatting.unformat} directly.
107
142
  #
108
143
  # @param (see #action)
109
144
  # @return (see #action)
110
145
  # @see #action
111
- # @todo Handle mIRC color codes more gracefully.
112
146
  def safe_action(text)
113
- action(Cinch::Utilities::String.filter_string(text))
147
+ action(Cinch::Helpers.Sanitize(text))
114
148
  end
115
149
 
116
150
  # Send a CTCP to the target.
@@ -239,7 +239,9 @@ module Cinch
239
239
  # received, the object will be set back to synced.
240
240
  #
241
241
  # @return [void]
242
- def whois
242
+ # @note The alias `whois` is deprecated and will be removed in a
243
+ # future version.
244
+ def refresh
243
245
  return if @in_whois
244
246
  @data.keys.each do |attr|
245
247
  unsync attr
@@ -252,7 +254,14 @@ module Cinch
252
254
  @bot.irc.send "WHOIS #@name #@name"
253
255
  end
254
256
  end
255
- alias_method :refresh, :whois
257
+ alias_method :whois, :refresh # deprecated
258
+ undef_method(:whois) # yardoc hack
259
+
260
+ # @deprecated
261
+ def whois
262
+ Cinch::Utilities::Deprecation.print_deprecation("2.2.0", "User#whois", "User#refresh")
263
+ refresh
264
+ end
256
265
 
257
266
  # @param [Hash, nil] values A hash of values gathered from WHOIS,
258
267
  # or `nil` if no data was returned
@@ -463,7 +472,7 @@ module Cinch
463
472
  @last_nick, @name = @name, new_nick
464
473
  # Unsync authname because some networks tie authentication to
465
474
  # the nick, so the user might not be authenticated anymore after
466
- # changing his nick
475
+ # changing their nick
467
476
  unsync(:authname)
468
477
  @bot.user_list.update_nick(self)
469
478
  end
@@ -7,12 +7,12 @@ module Cinch
7
7
  class UserList < CachedList
8
8
  # Finds or creates a user.
9
9
  # @overload find_ensured(nick)
10
- # Finds or creates a user based on his nick.
10
+ # Finds or creates a user based on their nick.
11
11
  #
12
12
  # @param [String] nick The user's nickname
13
13
  # @return [User]
14
14
  # @overload find_ensured(user, nick, host)
15
- # Finds or creates a user based on his nick but already
15
+ # Finds or creates a user based on their nick but already
16
16
  # setting user and host.
17
17
  #
18
18
  # @param [String] user The username
@@ -1,10 +1,14 @@
1
1
  module Cinch
2
- # @since 2.0.0
3
- # @api private
4
2
  module Utilities
3
+ # @since 2.0.0
4
+ # @api private
5
5
  module Deprecation
6
- def self.print_deprecation(version, method)
7
- $stderr.puts "Deprecation warning: Beginning with version #{version}, #{method} should not be used anymore."
6
+ def self.print_deprecation(version, method, instead = nil)
7
+ s = "Deprecation warning: Beginning with version #{version}, #{method} should not be used anymore."
8
+ if instead != nil
9
+ s << " Use ${instead} instead."
10
+ end
11
+ $stderr.puts s
8
12
  $stderr.puts caller
9
13
  end
10
14
  end
@@ -1,7 +1,7 @@
1
1
  module Cinch
2
- # @since 2.0.0
3
- # @api private
4
2
  module Utilities
3
+ # @since 2.0.0
4
+ # @api private
5
5
  module Encoding
6
6
  def self.encode_incoming(string, encoding)
7
7
  string = string.dup
@@ -27,27 +27,10 @@ module Cinch
27
27
  def self.encode_outgoing(string, encoding)
28
28
  string = string.dup
29
29
  if encoding == :irc
30
- # If your text contains only characters that fit inside the CP1252
31
- # code page (aka Windows Latin-1), the entire line will be sent
32
- # that way. mIRC users should see it correctly. XChat users who
33
- # are using UTF-8 will also see it correctly, because it will fail
34
- # UTF-8 validation and will be assumed to be CP1252, even by older
35
- # XChat versions.
36
- #
37
- # If the text doesn't fit inside the CP1252 code page, (for example if you
38
- # type Eastern European characters, or Russian) it will be sent as UTF-8. Only
39
- # UTF-8 capable clients will be able to see these characters correctly
40
- #
41
- # (from http://xchat.org/encoding/#hybrid)
42
- begin
43
- string.encode!("CP1252")
44
- rescue ::Encoding::UndefinedConversionError
45
- end
46
- else
47
- string.encode!(encoding, {:invalid => :replace, :undef => :replace}).force_encoding("ASCII-8BIT")
30
+ encoding = "UTF-8"
48
31
  end
49
32
 
50
- return string
33
+ return string.encode!(encoding, {:invalid => :replace, :undef => :replace}).force_encoding("ASCII-8BIT")
51
34
  end
52
35
  end
53
36
  end
@@ -1,7 +1,7 @@
1
1
  module Cinch
2
- # @since 2.0.0
3
- # @api private
4
2
  module Utilities
3
+ # @since 2.0.0
4
+ # @api private
5
5
  module Kernel
6
6
  # @return [Object]
7
7
  def self.string_to_const(s)
@@ -1,4 +1,4 @@
1
1
  module Cinch
2
2
  # Version of the library
3
- VERSION = '2.1.0'
3
+ VERSION = '2.2.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-27 00:00:00.000000000 Z
12
+ date: 2014-12-31 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple, friendly DSL for creating IRC bots
15
15
  email:
@@ -69,7 +69,6 @@ files:
69
69
  - lib/cinch/version.rb
70
70
  - lib/cinch/utilities/deprecation.rb
71
71
  - lib/cinch/utilities/kernel.rb
72
- - lib/cinch/utilities/string.rb
73
72
  - lib/cinch/utilities/encoding.rb
74
73
  - lib/cinch/constants.rb
75
74
  - lib/cinch/mode_parser.rb
@@ -1,17 +0,0 @@
1
- module Cinch
2
- # @since 2.0.0
3
- # @api private
4
- module Utilities
5
- module String
6
- # @return [String]
7
- # @todo Handle mIRC color codes more gracefully.
8
- def self.filter_string(string)
9
- string.gsub(/[\x00-\x1f]/, '')
10
- end
11
-
12
- def self.strip_colors(string)
13
- string.gsub(/[\x02\x0f\x16\x1f\x12]|\x03(\d{1,2}(,\d{1,2})?)?/, '')
14
- end
15
- end
16
- end
17
- end