balotelli 0.4.0 → 0.4.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/.codeclimate.yml +4 -3
- data/.travis.yml +1 -0
- data/Gemfile.lock +1 -1
- data/lib/balotelli/base.rb +29 -20
- data/lib/balotelli/config.rb +6 -6
- data/lib/balotelli/core/irc.rb +1 -3
- data/lib/balotelli/core/irc_logger.rb +4 -8
- data/lib/balotelli/core/kick.rb +1 -1
- data/lib/balotelli/core/priv_msg.rb +5 -5
- data/lib/balotelli/core/router.rb +4 -6
- data/lib/balotelli/core/utils.rb +4 -4
- data/lib/balotelli/version.rb +1 -1
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 9bfeedb4c09e7cdac32022e2cc033310c9254c48
         | 
| 4 | 
            +
              data.tar.gz: 9f0af9c1914dc98ae0f61b6487a1ff40f71d3568
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d580a3e378aee126aa667b675d6dec41d78d6c6e018f266bfbcdd7d36bc6cc9103ae33839f2400181b105386f50c312e820e77be570124edc489e34ac60405b9
         | 
| 7 | 
            +
              data.tar.gz: 1687cc8f9f82a8d532fe2706f3812099c785c60e460208054e674ce75be6070de0e5763673b1f08a08cea45d4db4e3bd7376239cc599c89003fb250806092274
         | 
    
        data/.codeclimate.yml
    CHANGED
    
    
    
        data/.travis.yml
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/balotelli/base.rb
    CHANGED
    
    | @@ -32,17 +32,26 @@ module Balotelli | |
| 32 32 | 
             
                end
         | 
| 33 33 |  | 
| 34 34 | 
             
                def get_user_list(channel)
         | 
| 35 | 
            -
                   | 
| 35 | 
            +
                  execute_in_mutex(channel) do
         | 
| 36 | 
            +
                    self.class.names(channel)
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
                  __CACHE__[:user_list][channel]
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                def execute_in_mutex(channel)
         | 
| 36 42 | 
             
                  cv = ConditionVariable.new
         | 
| 37 | 
            -
                  __CVS__. | 
| 38 | 
            -
             | 
| 43 | 
            +
                  if __CVS__.key? channel
         | 
| 44 | 
            +
                    __CVS__[channel] << cv
         | 
| 45 | 
            +
                  else
         | 
| 46 | 
            +
                    __CVS__[channel] = [cv]
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                  yield
         | 
| 39 49 | 
             
                  __MUTEX__.synchronize { cv.wait(__MUTEX__) }
         | 
| 40 | 
            -
                  __CACHE__[:user_list][channel]
         | 
| 41 50 | 
             
                end
         | 
| 42 51 |  | 
| 43 52 | 
             
                def method_missing(method, *args, **params, &block)
         | 
| 44 53 | 
             
                  if method =~ /__([[[:upper:]]_]+)__/
         | 
| 45 | 
            -
                    self.class.instance_variable_get("@#{ | 
| 54 | 
            +
                    self.class.instance_variable_get("@#{Regexp.last_match(1)}".downcase)
         | 
| 46 55 | 
             
                  else
         | 
| 47 56 | 
             
                    super
         | 
| 48 57 | 
             
                  end
         | 
| @@ -57,7 +66,7 @@ module Balotelli | |
| 57 66 |  | 
| 58 67 | 
             
                    @modules = {}
         | 
| 59 68 | 
             
                    @cache = Hash.new { |hash, key| hash[key] = {} }
         | 
| 60 | 
            -
                    @cvs =  | 
| 69 | 
            +
                    @cvs = {}
         | 
| 61 70 | 
             
                  end
         | 
| 62 71 |  | 
| 63 72 | 
             
                  def inherited(subclass)
         | 
| @@ -83,8 +92,8 @@ module Balotelli | |
| 83 92 |  | 
| 84 93 | 
             
                  def mod_match(str, priv = false)
         | 
| 85 94 | 
             
                    if str =~ /\A[^a-zA-Z0-9\s]?(\S+) ?(.*)/
         | 
| 86 | 
            -
                      if (mod = @cache[:modules][ | 
| 87 | 
            -
                        mod.match( | 
| 95 | 
            +
                      if (mod = @cache[:modules][Regexp.last_match(1).downcase])
         | 
| 96 | 
            +
                        mod.match(Regexp.last_match(2), priv)
         | 
| 88 97 | 
             
                      end
         | 
| 89 98 | 
             
                    elsif str == :join
         | 
| 90 99 | 
             
                      match = nil
         | 
| @@ -98,7 +107,6 @@ module Balotelli | |
| 98 107 | 
             
                  end
         | 
| 99 108 |  | 
| 100 109 | 
             
                  def run
         | 
| 101 | 
            -
                    @to_process = false
         | 
| 102 110 | 
             
                    while (str = sgets)
         | 
| 103 111 | 
             
                      process(str)
         | 
| 104 112 | 
             
                    end
         | 
| @@ -108,8 +116,8 @@ module Balotelli | |
| 108 116 |  | 
| 109 117 | 
             
                  def process(str)
         | 
| 110 118 | 
             
                    if str =~ /\APING (.*)\z/
         | 
| 111 | 
            -
                      pong  | 
| 112 | 
            -
                    elsif @on_connect && str =~  | 
| 119 | 
            +
                      pong Regexp.last_match(1)
         | 
| 120 | 
            +
                    elsif @on_connect && str =~ %r{End of \/MOTD command}i
         | 
| 113 121 | 
             
                      instance_eval(&remove_instance_variable(:@on_connect))
         | 
| 114 122 | 
             
                    elsif !(str =~ /(JOIN\s|PRIVMSG\s)/)
         | 
| 115 123 | 
             
                      process_table(str)
         | 
| @@ -120,14 +128,14 @@ module Balotelli | |
| 120 128 |  | 
| 121 129 | 
             
                  def process_message(str)
         | 
| 122 130 | 
             
                    if str =~ Core::Utils::PRIV_MSG_REGEX
         | 
| 123 | 
            -
                      metadata = { user:  | 
| 124 | 
            -
                      priv = !( | 
| 131 | 
            +
                      metadata = { user: Regexp.last_match(1), channel: Regexp.last_match(2), message: Regexp.last_match(3) }
         | 
| 132 | 
            +
                      priv = !(Regexp.last_match(2) =~ /#.+/)
         | 
| 125 133 | 
             
                      if (match = match(metadata[:message], priv)) ||
         | 
| 126 | 
            -
             | 
| 134 | 
            +
                         (match = mod_match(metadata[:message], priv))
         | 
| 127 135 | 
             
                        new_response(str, match, metadata, Core::PrivMsg, priv)
         | 
| 128 136 | 
             
                      end
         | 
| 129 137 | 
             
                    elsif str =~ Core::Utils::JOIN_REGEX
         | 
| 130 | 
            -
                      metadata = { user:  | 
| 138 | 
            +
                      metadata = { user: Regexp.last_match(1), channel: Regexp.last_match(2) }
         | 
| 131 139 | 
             
                      if (match = match(:join)) || (match = mod_match(:join))
         | 
| 132 140 | 
             
                        new_response(str, match, metadata, Core::Join)
         | 
| 133 141 | 
             
                      end
         | 
| @@ -144,13 +152,14 @@ module Balotelli | |
| 144 152 |  | 
| 145 153 | 
             
                  def process_table(string)
         | 
| 146 154 | 
             
                    if @cvs.any? && string =~ (regex = Core::Utils.table_regex(@nick))
         | 
| 147 | 
            -
                      metadata = { channel:  | 
| 148 | 
            -
                      users = @cache[ | 
| 149 | 
            -
                      until (str = sgets) =~  | 
| 155 | 
            +
                      metadata = { channel: Regexp.last_match(2), message: Regexp.last_match(3) }
         | 
| 156 | 
            +
                      users = @cache[:user_list][metadata[:channel]] = metadata[:message]
         | 
| 157 | 
            +
                      until (str = sgets) =~ %r{End of \/NAME}i
         | 
| 150 158 | 
             
                        users << " #{str.match(regex).captures.first}"
         | 
| 151 159 | 
             
                      end
         | 
| 152 | 
            -
                      @cache[ | 
| 153 | 
            -
                      @cvs.shift.signal
         | 
| 160 | 
            +
                      @cache[:user_list][metadata[:channel]] = users.split(' ')
         | 
| 161 | 
            +
                      @cvs[metadata[:channel]].shift.signal
         | 
| 162 | 
            +
                      @cvs.delete(metadata[:channel]) if @cvs[metadata[:channel]].empty?
         | 
| 154 163 | 
             
                    end
         | 
| 155 164 | 
             
                  end
         | 
| 156 165 | 
             
                end
         | 
    
        data/lib/balotelli/config.rb
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            module Balotelli
         | 
| 2 2 | 
             
              module Config
         | 
| 3 | 
            -
                FREENODE = ['chat.freenode.net', 6667]
         | 
| 4 | 
            -
                QUAKENET = ['irc.quakenet.org', 6667]
         | 
| 5 | 
            -
                RIZON = ['irc.rizon.net', 6667]
         | 
| 6 | 
            -
                PIRC = ['irc.pirc.pl', 6667]
         | 
| 7 | 
            -
                MOZNET = ['irc.mozilla.org', 6667]
         | 
| 3 | 
            +
                FREENODE = ['chat.freenode.net'.freeze, 6667].freeze
         | 
| 4 | 
            +
                QUAKENET = ['irc.quakenet.org'.freeze, 6667].freeze
         | 
| 5 | 
            +
                RIZON = ['irc.rizon.net'.freeze, 6667].freeze
         | 
| 6 | 
            +
                PIRC = ['irc.pirc.pl'.freeze, 6667].freeze
         | 
| 7 | 
            +
                MOZNET = ['irc.mozilla.org'.freeze, 6667].freeze
         | 
| 8 8 |  | 
| 9 9 | 
             
                module_function
         | 
| 10 10 |  | 
| 11 | 
            -
                def build(server, name = ('balotelli%03d'  | 
| 11 | 
            +
                def build(server, name = format('balotelli%03d', rand(1000)), pass = nil)
         | 
| 12 12 | 
             
                  const_get(server.upcase).dup.push(name, pass)
         | 
| 13 13 | 
             
                end
         | 
| 14 14 | 
             
              end
         | 
    
        data/lib/balotelli/core/irc.rb
    CHANGED
    
    
| @@ -27,7 +27,6 @@ module Balotelli | |
| 27 27 |  | 
| 28 28 | 
             
                    des.instance_variable_set(:@log_file, log_file)
         | 
| 29 29 | 
             
                    des.instance_variable_set(:@logger, self)
         | 
| 30 | 
            -
             | 
| 31 30 | 
             
                    class << des
         | 
| 32 31 | 
             
                      alias_method :orig_sputs, :sputs
         | 
| 33 32 | 
             
                      private :orig_sputs
         | 
| @@ -37,7 +36,7 @@ module Balotelli | |
| 37 36 | 
             
                        to_log = ">>#{str.inspect}\n"
         | 
| 38 37 | 
             
                        @log_file.info(to_log)
         | 
| 39 38 | 
             
                        if str =~ /\A:?\S+ (#\S+) .*/
         | 
| 40 | 
            -
                          @logger.channel_log( | 
| 39 | 
            +
                          @logger.channel_log(Regexp.last_match(1).downcase, to_log)
         | 
| 41 40 | 
             
                        end
         | 
| 42 41 | 
             
                        str
         | 
| 43 42 | 
             
                      end
         | 
| @@ -50,7 +49,7 @@ module Balotelli | |
| 50 49 | 
             
                        to_log = "<<#{str.inspect}\n"
         | 
| 51 50 | 
             
                        @log_file.info(to_log)
         | 
| 52 51 | 
             
                        if str =~ /\A:?\S+ \S+ (#\S+) .*/
         | 
| 53 | 
            -
                          @logger.channel_log( | 
| 52 | 
            +
                          @logger.channel_log(Regexp.last_match(1).downcase, to_log)
         | 
| 54 53 | 
             
                        end
         | 
| 55 54 | 
             
                        str
         | 
| 56 55 | 
             
                      end
         | 
| @@ -78,16 +77,13 @@ module Balotelli | |
| 78 77 | 
             
                  end
         | 
| 79 78 |  | 
| 80 79 | 
             
                  def new_logger(file_name)
         | 
| 81 | 
            -
                    Logger.new(File.join(dir, file_name), 0, 1.0 / 0)
         | 
| 82 | 
            -
                      .tap do |l|
         | 
| 80 | 
            +
                    Logger.new(File.join(dir, file_name), 0, 1.0 / 0).tap do |l|
         | 
| 83 81 | 
             
                      l.formatter = LOG_FORMAT
         | 
| 84 82 | 
             
                    end
         | 
| 85 83 | 
             
                  end
         | 
| 86 84 |  | 
| 87 85 | 
             
                  def check_dir
         | 
| 88 | 
            -
                    unless File.file?(dir)
         | 
| 89 | 
            -
                      FileUtils.mkdir_p(dir)
         | 
| 90 | 
            -
                    end
         | 
| 86 | 
            +
                    FileUtils.mkdir_p(dir) unless File.file?(dir)
         | 
| 91 87 | 
             
                  end
         | 
| 92 88 | 
             
                end
         | 
| 93 89 | 
             
              end
         | 
    
        data/lib/balotelli/core/kick.rb
    CHANGED
    
    
| @@ -7,11 +7,11 @@ module Balotelli | |
| 7 7 | 
             
                    @user_nick = @user.match(/\A(\S+)!.*/)[1]
         | 
| 8 8 | 
             
                    @channel = metadata[:channel]
         | 
| 9 9 | 
             
                    @content = metadata[:message]
         | 
| 10 | 
            -
                    if privacy
         | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 10 | 
            +
                    @responder = if privacy
         | 
| 11 | 
            +
                                   @user_nick
         | 
| 12 | 
            +
                                 else
         | 
| 13 | 
            +
                                   @channel
         | 
| 14 | 
            +
                                 end
         | 
| 15 15 | 
             
                  end
         | 
| 16 16 | 
             
                end
         | 
| 17 17 | 
             
              end
         | 
| @@ -6,11 +6,9 @@ module Balotelli | |
| 6 6 | 
             
                  end
         | 
| 7 7 |  | 
| 8 8 | 
             
                  def on(route, option = {}, &block)
         | 
| 9 | 
            -
                     | 
| 9 | 
            +
                    raise 'no block given' if block.nil?
         | 
| 10 10 |  | 
| 11 | 
            -
                    if !option.key?(:private) || route == :join
         | 
| 12 | 
            -
                      option[:private] = false
         | 
| 13 | 
            -
                    end
         | 
| 11 | 
            +
                    option[:private] = false if !option.key?(:private) || route == :join
         | 
| 14 12 |  | 
| 15 13 | 
             
                    if option[:private] == :both
         | 
| 16 14 | 
             
                      on(route, option.clone.tap { |o| o[:private] = true }, &block)
         | 
| @@ -21,7 +19,7 @@ module Balotelli | |
| 21 19 | 
             
                    @routes[route] ||= {}
         | 
| 22 20 |  | 
| 23 21 | 
             
                    if @routes[route][option[:private]] && !option[:force]
         | 
| 24 | 
            -
                       | 
| 22 | 
            +
                      raise "Route #{route.inspect}, private: #{option[:private]} already exists"
         | 
| 25 23 | 
             
                    end
         | 
| 26 24 |  | 
| 27 25 | 
             
                    @routes[route][option[:private]] = [block, self]
         | 
| @@ -39,7 +37,7 @@ module Balotelli | |
| 39 37 | 
             
                  end
         | 
| 40 38 |  | 
| 41 39 | 
             
                  def match(str, priv = false)
         | 
| 42 | 
            -
                    if m = @routes.detect { |k, v| match?(str, k) && v[priv] }
         | 
| 40 | 
            +
                    if (m = @routes.detect { |k, v| match?(str, k) && v[priv] })
         | 
| 43 41 | 
             
                      [m[0], m[1][priv], str]
         | 
| 44 42 | 
             
                    end
         | 
| 45 43 | 
             
                  end
         | 
    
        data/lib/balotelli/core/utils.rb
    CHANGED
    
    | @@ -1,9 +1,9 @@ | |
| 1 1 | 
             
            module Balotelli
         | 
| 2 2 | 
             
              module Core
         | 
| 3 3 | 
             
                module Utils
         | 
| 4 | 
            -
                  NICK_REGEX = /\A(\S+) | 
| 5 | 
            -
                  PRIV_MSG_REGEX = /\A:?(\S+) PRIVMSG (\S+) :?(.*) | 
| 6 | 
            -
                  JOIN_REGEX = /\A:?(\S+) JOIN (\S+) | 
| 4 | 
            +
                  NICK_REGEX = /\A(\S+)!.*/
         | 
| 5 | 
            +
                  PRIV_MSG_REGEX = /\A:?(\S+) PRIVMSG (\S+) :?(.*)/
         | 
| 6 | 
            +
                  JOIN_REGEX = /\A:?(\S+) JOIN (\S+)/
         | 
| 7 7 |  | 
| 8 8 | 
             
                  module_function
         | 
| 9 9 |  | 
| @@ -12,7 +12,7 @@ module Balotelli | |
| 12 12 | 
             
                  end
         | 
| 13 13 |  | 
| 14 14 | 
             
                  def table_regex(nick)
         | 
| 15 | 
            -
                    /\A:?(\S+) \d+ #{nick} \S (#\S+) :?(.*) | 
| 15 | 
            +
                    /\A:?(\S+) \d+ #{nick} \S (#\S+) :?(.*)/
         | 
| 16 16 | 
             
                  end
         | 
| 17 17 | 
             
                end
         | 
| 18 18 | 
             
              end
         | 
    
        data/lib/balotelli/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: balotelli
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.4. | 
| 4 | 
            +
              version: 0.4.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Marcin Henryk Bartkowiak
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016- | 
| 11 | 
            +
            date: 2016-08-24 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 109 109 | 
             
                  version: '0'
         | 
| 110 110 | 
             
            requirements: []
         | 
| 111 111 | 
             
            rubyforge_project: 
         | 
| 112 | 
            -
            rubygems_version: 2. | 
| 112 | 
            +
            rubygems_version: 2.6.4
         | 
| 113 113 | 
             
            signing_key: 
         | 
| 114 114 | 
             
            specification_version: 4
         | 
| 115 115 | 
             
            summary: Simple IRC bot framework
         |