grinch 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/cinch/formatting.rb +1 -1
 - data/lib/cinch/message.rb +39 -40
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 599ce33b0690279ec66619db60107d39af1085244c24488e99e8b7463a9bf997
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: '097b6c4e200d0bc3ec0c953d39c55c9ff99a948e9ff57c34a95c04be776ddae5'
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 7f58e236d6481c75f145f0792c0629822d173b6780b7ed050c24d997b15816d9360ffe989fc4b10ceb49fff95a255aeb81b4ad128017c046def8e06889f92f40
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 1c1f1b6d39f4d25f9a9ed0a88725d325dd6690e87f446c41a68833d168243144852d1bbd7ae2995089e671157781de3b55d19b528f5fc05a9de2cab6d50363fe
         
     | 
    
        data/lib/cinch/formatting.rb
    CHANGED
    
    | 
         @@ -119,7 +119,7 @@ module Cinch 
     | 
|
| 
       119 
119 
     | 
    
         
             
                # @return [String] The filtered string
         
     | 
| 
       120 
120 
     | 
    
         
             
                # @since 2.2.0
         
     | 
| 
       121 
121 
     | 
    
         
             
                def self.unformat(string)
         
     | 
| 
       122 
     | 
    
         
            -
                  string.gsub(/[\x02\x0f\x16\x1f\x12]|\x03(\d{1,2}(,\d{1,2})?)?/, '')
         
     | 
| 
      
 122 
     | 
    
         
            +
                  string.gsub(/[\x02\x0f\x16\x1d\x1f\x12]|\x03(\d{1,2}(,\d{1,2})?)?/, '')
         
     | 
| 
       123 
123 
     | 
    
         
             
                end
         
     | 
| 
       124 
124 
     | 
    
         
             
              end
         
     | 
| 
       125 
125 
     | 
    
         
             
            end
         
     | 
    
        data/lib/cinch/message.rb
    CHANGED
    
    | 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #  
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require "time"
         
     | 
| 
       3 
4 
     | 
    
         
             
            require "cinch/formatting"
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
         @@ -21,7 +22,7 @@ module Cinch 
     | 
|
| 
       21 
22 
     | 
    
         | 
| 
       22 
23 
     | 
    
         
             
                # @return [Array<String>]
         
     | 
| 
       23 
24 
     | 
    
         
             
                attr_reader :params
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
       25 
26 
     | 
    
         
             
                # @return [Hash]
         
     | 
| 
       26 
27 
     | 
    
         
             
                attr_reader :tags
         
     | 
| 
       27 
28 
     | 
    
         | 
| 
         @@ -87,7 +88,7 @@ module Cinch 
     | 
|
| 
       87 
88 
     | 
    
         
             
                def initialize(msg, bot)
         
     | 
| 
       88 
89 
     | 
    
         
             
                  @raw     = msg
         
     | 
| 
       89 
90 
     | 
    
         
             
                  @bot     = bot
         
     | 
| 
       90 
     | 
    
         
            -
                  @matches = {: 
     | 
| 
      
 91 
     | 
    
         
            +
                  @matches = { ctcp: {}, action: {}, other: {} }
         
     | 
| 
       91 
92 
     | 
    
         
             
                  @events  = []
         
     | 
| 
       92 
93 
     | 
    
         
             
                  @time    = Time.now
         
     | 
| 
       93 
94 
     | 
    
         
             
                  @statusmsg_mode = nil
         
     | 
| 
         @@ -97,13 +98,11 @@ module Cinch 
     | 
|
| 
       97 
98 
     | 
    
         
             
                # @api private
         
     | 
| 
       98 
99 
     | 
    
         
             
                # @return [void]
         
     | 
| 
       99 
100 
     | 
    
         
             
                def parse
         
     | 
| 
       100 
     | 
    
         
            -
                  match = @raw.match( 
     | 
| 
      
 101 
     | 
    
         
            +
                  match = @raw.match(/\A(?:@([^ ]+) )?(?::(\S+) )?(\S+)(.*)/)
         
     | 
| 
       101 
102 
     | 
    
         
             
                  tags, @prefix, @command, raw_params = match.captures
         
     | 
| 
       102 
103 
     | 
    
         | 
| 
       103 
104 
     | 
    
         
             
                  if @bot.irc.network.ngametv?
         
     | 
| 
       104 
     | 
    
         
            -
                    if @prefix != "ngame"
         
     | 
| 
       105 
     | 
    
         
            -
                      @prefix = "%s!%s@%s" % [@prefix, @prefix, @prefix]
         
     | 
| 
       106 
     | 
    
         
            -
                    end
         
     | 
| 
      
 105 
     | 
    
         
            +
                    @prefix = "%s!%s@%s" % [@prefix, @prefix, @prefix] if @prefix != "ngame"
         
     | 
| 
       107 
106 
     | 
    
         
             
                  end
         
     | 
| 
       108 
107 
     | 
    
         | 
| 
       109 
108 
     | 
    
         
             
                  @params  = parse_params(raw_params)
         
     | 
| 
         @@ -168,9 +167,7 @@ module Cinch 
     | 
|
| 
       168 
167 
     | 
    
         
             
                    type = :other
         
     | 
| 
       169 
168 
     | 
    
         
             
                  end
         
     | 
| 
       170 
169 
     | 
    
         | 
| 
       171 
     | 
    
         
            -
                  if strip_colors
         
     | 
| 
       172 
     | 
    
         
            -
                    text = Cinch::Formatting.unformat(text)
         
     | 
| 
       173 
     | 
    
         
            -
                  end
         
     | 
| 
      
 170 
     | 
    
         
            +
                  text = Cinch::Formatting.unformat(text) if strip_colors
         
     | 
| 
       174 
171 
     | 
    
         | 
| 
       175 
172 
     | 
    
         
             
                  @matches[type][regexp] ||= text.match(regexp)
         
     | 
| 
       176 
173 
     | 
    
         
             
                end
         
     | 
| 
         @@ -192,9 +189,7 @@ module Cinch 
     | 
|
| 
       192 
189 
     | 
    
         
             
                # @return [void]
         
     | 
| 
       193 
190 
     | 
    
         
             
                def reply(text, prefix = false)
         
     | 
| 
       194 
191 
     | 
    
         
             
                  text = text.to_s
         
     | 
| 
       195 
     | 
    
         
            -
                  if @channel && prefix
         
     | 
| 
       196 
     | 
    
         
            -
                    text = text.split("\n").map {|l| "#{user.nick}: #{l}"}.join("\n")
         
     | 
| 
       197 
     | 
    
         
            -
                  end
         
     | 
| 
      
 192 
     | 
    
         
            +
                  text = text.split("\n").map { |l| "#{user.nick}: #{l}" }.join("\n") if @channel && prefix
         
     | 
| 
       198 
193 
     | 
    
         | 
| 
       199 
194 
     | 
    
         
             
                  reply_target.send(text)
         
     | 
| 
       200 
195 
     | 
    
         
             
                end
         
     | 
| 
         @@ -205,9 +200,7 @@ module Cinch 
     | 
|
| 
       205 
200 
     | 
    
         
             
                # @return (see #reply)
         
     | 
| 
       206 
201 
     | 
    
         
             
                def safe_reply(text, prefix = false)
         
     | 
| 
       207 
202 
     | 
    
         
             
                  text = text.to_s
         
     | 
| 
       208 
     | 
    
         
            -
                  if channel && prefix
         
     | 
| 
       209 
     | 
    
         
            -
                    text = "#{@user.nick}: #{text}"
         
     | 
| 
       210 
     | 
    
         
            -
                  end
         
     | 
| 
      
 203 
     | 
    
         
            +
                  text = "#{@user.nick}: #{text}" if channel && prefix
         
     | 
| 
       211 
204 
     | 
    
         
             
                  reply_target.safe_send(text)
         
     | 
| 
       212 
205 
     | 
    
         
             
                end
         
     | 
| 
       213 
206 
     | 
    
         | 
| 
         @@ -236,6 +229,7 @@ module Cinch 
     | 
|
| 
       236 
229 
     | 
    
         
             
                # @return [void]
         
     | 
| 
       237 
230 
     | 
    
         
             
                def ctcp_reply(answer)
         
     | 
| 
       238 
231 
     | 
    
         
             
                  return unless ctcp?
         
     | 
| 
      
 232 
     | 
    
         
            +
             
     | 
| 
       239 
233 
     | 
    
         
             
                  @user.notice "\001#{@ctcp_command} #{answer}\001"
         
     | 
| 
       240 
234 
     | 
    
         
             
                end
         
     | 
| 
       241 
235 
     | 
    
         | 
| 
         @@ -248,19 +242,20 @@ module Cinch 
     | 
|
| 
       248 
242 
     | 
    
         
             
                end
         
     | 
| 
       249 
243 
     | 
    
         | 
| 
       250 
244 
     | 
    
         
             
                private
         
     | 
| 
      
 245 
     | 
    
         
            +
             
     | 
| 
       251 
246 
     | 
    
         
             
                def reply_target
         
     | 
| 
       252 
     | 
    
         
            -
                  if @channel.nil? || @statusmsg_mode.nil?
         
     | 
| 
       253 
     | 
    
         
            -
             
     | 
| 
       254 
     | 
    
         
            -
                  end
         
     | 
| 
      
 247 
     | 
    
         
            +
                  return @target if @channel.nil? || @statusmsg_mode.nil?
         
     | 
| 
      
 248 
     | 
    
         
            +
             
     | 
| 
       255 
249 
     | 
    
         
             
                  prefix = @bot.irc.isupport["PREFIX"][@statusmsg_mode]
         
     | 
| 
       256 
     | 
    
         
            -
                   
     | 
| 
      
 250 
     | 
    
         
            +
                  Target.new(prefix + @channel.name, @bot)
         
     | 
| 
       257 
251 
     | 
    
         
             
                end
         
     | 
| 
      
 252 
     | 
    
         
            +
             
     | 
| 
       258 
253 
     | 
    
         
             
                def regular_command?
         
     | 
| 
       259 
254 
     | 
    
         
             
                  !numeric_reply? # a command can only be numeric or "regular"…
         
     | 
| 
       260 
255 
     | 
    
         
             
                end
         
     | 
| 
       261 
256 
     | 
    
         | 
| 
       262 
257 
     | 
    
         
             
                def parse_params(raw_params)
         
     | 
| 
       263 
     | 
    
         
            -
                  params 
     | 
| 
      
 258 
     | 
    
         
            +
                  params = []
         
     | 
| 
       264 
259 
     | 
    
         
             
                  if match = raw_params.match(/(?:^:| :)(.*)$/)
         
     | 
| 
       265 
260 
     | 
    
         
             
                    params = match.pre_match.split(" ")
         
     | 
| 
       266 
261 
     | 
    
         
             
                    params << match[1]
         
     | 
| 
         @@ -268,44 +263,46 @@ module Cinch 
     | 
|
| 
       268 
263 
     | 
    
         
             
                    params = raw_params.split(" ")
         
     | 
| 
       269 
264 
     | 
    
         
             
                  end
         
     | 
| 
       270 
265 
     | 
    
         | 
| 
       271 
     | 
    
         
            -
                   
     | 
| 
      
 266 
     | 
    
         
            +
                  params
         
     | 
| 
       272 
267 
     | 
    
         
             
                end
         
     | 
| 
       273 
     | 
    
         
            -
             
     | 
| 
      
 268 
     | 
    
         
            +
             
     | 
| 
       274 
269 
     | 
    
         
             
                def parse_tags(raw_tags)
         
     | 
| 
       275 
270 
     | 
    
         
             
                  return {} if raw_tags.nil?
         
     | 
| 
       276 
     | 
    
         
            -
             
     | 
| 
      
 271 
     | 
    
         
            +
             
     | 
| 
       277 
272 
     | 
    
         
             
                  def to_symbol(string)
         
     | 
| 
       278 
     | 
    
         
            -
                     
     | 
| 
      
 273 
     | 
    
         
            +
                    string.tr("-", "_").downcase.to_sym
         
     | 
| 
       279 
274 
     | 
    
         
             
                  end
         
     | 
| 
       280 
     | 
    
         
            -
             
     | 
| 
      
 275 
     | 
    
         
            +
             
     | 
| 
       281 
276 
     | 
    
         
             
                  tags = {}
         
     | 
| 
       282 
277 
     | 
    
         
             
                  raw_tags.split(";").each do |tag|
         
     | 
| 
       283 
278 
     | 
    
         
             
                    tag_name, tag_value = tag.split("=")
         
     | 
| 
       284 
     | 
    
         
            -
                    if tag_value 
     | 
| 
       285 
     | 
    
         
            -
                      tag_value = tag_value.split( 
     | 
| 
      
 279 
     | 
    
         
            +
                    if /,/.match?(tag_value)
         
     | 
| 
      
 280 
     | 
    
         
            +
                      tag_value = tag_value.split(",")
         
     | 
| 
       286 
281 
     | 
    
         
             
                    elsif tag_value.nil?
         
     | 
| 
       287 
282 
     | 
    
         
             
                      tag_value = tag_name
         
     | 
| 
       288 
283 
     | 
    
         
             
                    end
         
     | 
| 
       289 
     | 
    
         
            -
                    if tag_name 
     | 
| 
       290 
     | 
    
         
            -
                      vendor, tag_name = tag_name.split( 
     | 
| 
      
 284 
     | 
    
         
            +
                    if %r{/}.match?(tag_name)
         
     | 
| 
      
 285 
     | 
    
         
            +
                      vendor, tag_name = tag_name.split("/")
         
     | 
| 
       291 
286 
     | 
    
         
             
                      tags[to_symbol(vendor)] = {
         
     | 
| 
       292 
     | 
    
         
            -
                        to_symbol(tag_name) => tag_value
         
     | 
| 
      
 287 
     | 
    
         
            +
                        to_symbol(tag_name) => tag_value,
         
     | 
| 
       293 
288 
     | 
    
         
             
                      }
         
     | 
| 
       294 
289 
     | 
    
         
             
                    else
         
     | 
| 
       295 
290 
     | 
    
         
             
                      tags[to_symbol(tag_name)] = tag_value
         
     | 
| 
       296 
291 
     | 
    
         
             
                    end
         
     | 
| 
       297 
292 
     | 
    
         
             
                  end
         
     | 
| 
       298 
     | 
    
         
            -
                   
     | 
| 
      
 293 
     | 
    
         
            +
                  tags
         
     | 
| 
       299 
294 
     | 
    
         
             
                end
         
     | 
| 
       300 
295 
     | 
    
         | 
| 
       301 
296 
     | 
    
         
             
                def parse_user
         
     | 
| 
       302 
297 
     | 
    
         
             
                  return unless @prefix
         
     | 
| 
      
 298 
     | 
    
         
            +
             
     | 
| 
       303 
299 
     | 
    
         
             
                  nick = @prefix[/^(\S+)!/, 1]
         
     | 
| 
       304 
300 
     | 
    
         
             
                  user = @prefix[/^\S+!(\S+)@/, 1]
         
     | 
| 
       305 
301 
     | 
    
         
             
                  host = @prefix[/@(\S+)$/, 1]
         
     | 
| 
       306 
302 
     | 
    
         | 
| 
       307 
303 
     | 
    
         
             
                  return nil if nick.nil?
         
     | 
| 
       308 
     | 
    
         
            -
             
     | 
| 
      
 304 
     | 
    
         
            +
             
     | 
| 
      
 305 
     | 
    
         
            +
                  @bot.user_list.find_ensured(user, nick, host)
         
     | 
| 
       309 
306 
     | 
    
         
             
                end
         
     | 
| 
       310 
307 
     | 
    
         | 
| 
       311 
308 
     | 
    
         
             
                def parse_channel
         
     | 
| 
         @@ -327,9 +324,7 @@ module Cinch 
     | 
|
| 
       327 
324 
     | 
    
         
             
                    if ch.nil? && numeric_reply? && @params.size > 1
         
     | 
| 
       328 
325 
     | 
    
         
             
                      ch, status = privmsg_channel_name(@params[1])
         
     | 
| 
       329 
326 
     | 
    
         
             
                    end
         
     | 
| 
       330 
     | 
    
         
            -
                    if ch
         
     | 
| 
       331 
     | 
    
         
            -
                      return @bot.channel_list.find_ensured(ch), status
         
     | 
| 
       332 
     | 
    
         
            -
                    end
         
     | 
| 
      
 327 
     | 
    
         
            +
                    return @bot.channel_list.find_ensured(ch), status if ch
         
     | 
| 
       333 
328 
     | 
    
         
             
                  end
         
     | 
| 
       334 
329 
     | 
    
         
             
                end
         
     | 
| 
       335 
330 
     | 
    
         | 
| 
         @@ -346,8 +341,9 @@ module Cinch 
     | 
|
| 
       346 
341 
     | 
    
         | 
| 
       347 
342 
     | 
    
         
             
                def parse_server
         
     | 
| 
       348 
343 
     | 
    
         
             
                  return unless @prefix
         
     | 
| 
       349 
     | 
    
         
            -
                  return if @prefix 
     | 
| 
       350 
     | 
    
         
            -
             
     | 
| 
      
 344 
     | 
    
         
            +
                  return if @prefix =~ /[@!]/
         
     | 
| 
      
 345 
     | 
    
         
            +
             
     | 
| 
      
 346 
     | 
    
         
            +
                  @prefix[/^(\S+)/, 1]
         
     | 
| 
       351 
347 
     | 
    
         
             
                end
         
     | 
| 
       352 
348 
     | 
    
         | 
| 
       353 
349 
     | 
    
         
             
                def parse_error
         
     | 
| 
         @@ -366,27 +362,30 @@ module Cinch 
     | 
|
| 
       366 
362 
     | 
    
         
             
                def parse_ctcp_message
         
     | 
| 
       367 
363 
     | 
    
         
             
                  # has to be called after parse_params
         
     | 
| 
       368 
364 
     | 
    
         
             
                  return unless ctcp?
         
     | 
| 
      
 365 
     | 
    
         
            +
             
     | 
| 
       369 
366 
     | 
    
         
             
                  @params.last =~ /\001(.+)\001/
         
     | 
| 
       370 
     | 
    
         
            -
                   
     | 
| 
      
 367 
     | 
    
         
            +
                  Regexp.last_match(1)
         
     | 
| 
       371 
368 
     | 
    
         
             
                end
         
     | 
| 
       372 
369 
     | 
    
         | 
| 
       373 
370 
     | 
    
         
             
                def parse_ctcp_command
         
     | 
| 
       374 
371 
     | 
    
         
             
                  # has to be called after parse_ctcp_message
         
     | 
| 
       375 
372 
     | 
    
         
             
                  return unless ctcp?
         
     | 
| 
      
 373 
     | 
    
         
            +
             
     | 
| 
       376 
374 
     | 
    
         
             
                  @ctcp_message.split(" ").first
         
     | 
| 
       377 
375 
     | 
    
         
             
                end
         
     | 
| 
       378 
376 
     | 
    
         | 
| 
       379 
377 
     | 
    
         
             
                def parse_ctcp_args
         
     | 
| 
       380 
378 
     | 
    
         
             
                  # has to be called after parse_ctcp_message
         
     | 
| 
       381 
379 
     | 
    
         
             
                  return unless ctcp?
         
     | 
| 
      
 380 
     | 
    
         
            +
             
     | 
| 
       382 
381 
     | 
    
         
             
                  @ctcp_message.split(" ")[1..-1]
         
     | 
| 
       383 
382 
     | 
    
         
             
                end
         
     | 
| 
       384 
383 
     | 
    
         | 
| 
       385 
384 
     | 
    
         
             
                def parse_action_message
         
     | 
| 
       386 
385 
     | 
    
         
             
                  # has to be called after parse_ctcp_message
         
     | 
| 
       387 
386 
     | 
    
         
             
                  return nil unless action?
         
     | 
| 
      
 387 
     | 
    
         
            +
             
     | 
| 
       388 
388 
     | 
    
         
             
                  @ctcp_message.split(" ", 2).last
         
     | 
| 
       389 
389 
     | 
    
         
             
                end
         
     | 
| 
       390 
     | 
    
         
            -
             
     | 
| 
       391 
390 
     | 
    
         
             
              end
         
     | 
| 
       392 
391 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: grinch
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - William Woodruff
         
     | 
| 
         @@ -114,7 +114,7 @@ files: 
     | 
|
| 
       114 
114 
     | 
    
         
             
            - lib/cinch/utilities/encoding.rb
         
     | 
| 
       115 
115 
     | 
    
         
             
            - lib/cinch/utilities/kernel.rb
         
     | 
| 
       116 
116 
     | 
    
         
             
            - lib/cinch/version.rb
         
     | 
| 
       117 
     | 
    
         
            -
            homepage: 
         
     | 
| 
      
 117 
     | 
    
         
            +
            homepage: https://github.com/woodruffw/grinch
         
     | 
| 
       118 
118 
     | 
    
         
             
            licenses:
         
     | 
| 
       119 
119 
     | 
    
         
             
            - MIT
         
     | 
| 
       120 
120 
     | 
    
         
             
            metadata: {}
         
     |