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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15612cf80da241b688e4fc4b1029b58f049756e5
4
- data.tar.gz: 74dc6b66092aa791f7a35f9b6e7a74d7d768a40a
3
+ metadata.gz: 9bfeedb4c09e7cdac32022e2cc033310c9254c48
4
+ data.tar.gz: 9f0af9c1914dc98ae0f61b6487a1ff40f71d3568
5
5
  SHA512:
6
- metadata.gz: d78beaca372105824a6f5893ac216aca69135a1c103dab1eeba0e25fb13fada711c0b511b5c416648f1f6da04bc53b4298e5fc7522666e6da933a8ac055e5b10
7
- data.tar.gz: 43aa8f479f162551a8a940f230f53edc5673f762cea2f0e25045db93ed44ccd9c61bf13fc3f41e4b0c6bc88ac95502183a2401d5a4e34f02fffb6af709c059c7
6
+ metadata.gz: d580a3e378aee126aa667b675d6dec41d78d6c6e018f266bfbcdd7d36bc6cc9103ae33839f2400181b105386f50c312e820e77be570124edc489e34ac60405b9
7
+ data.tar.gz: 1687cc8f9f82a8d532fe2706f3812099c785c60e460208054e674ce75be6070de0e5763673b1f08a08cea45d4db4e3bd7376239cc599c89003fb250806092274
data/.codeclimate.yml CHANGED
@@ -1,4 +1,5 @@
1
- languages:
2
- ruby: true
1
+ engines:
2
+ rubocop:
3
+ enabled: true
3
4
  exclude_paths:
4
- "example.rb"
5
+ - examples/**/*
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ cache: bundler
3
4
  rvm:
4
5
  - 2.3.0
5
6
  - 2.2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- balotelli (0.3.0)
4
+ balotelli (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -32,17 +32,26 @@ module Balotelli
32
32
  end
33
33
 
34
34
  def get_user_list(channel)
35
- self.class.instance_variable_set(:@to_process, :user_list)
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__.push cv
38
- self.class.names(channel)
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("@#{$1}".downcase)
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][$1.downcase])
87
- mod.match($2, priv)
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 $1
112
- elsif @on_connect && str =~ /End of \/MOTD command/i
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: $1, channel: $2, message: $3 }
124
- priv = !($2 =~ /#.+/)
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
- (match = mod_match(metadata[:message], priv))
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: $1, channel: $2 }
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: $2, message: $3 }
148
- users = @cache[@to_process][metadata[:channel]] = metadata[:message]
149
- until (str = sgets) =~ /End of \/NAME/i
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[@to_process][metadata[:channel]] = users.split(' ')
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
@@ -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' % rand(1000)), pass = nil)
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
@@ -20,9 +20,7 @@ module Balotelli
20
20
  sputs("NICK #{@nick}")
21
21
  sputs("USER #{@nick} 0 * :#{@nick}")
22
22
 
23
- if block_given?
24
- instance_variable_set(:@on_connect, block)
25
- end
23
+ instance_variable_set(:@on_connect, block) if block_given?
26
24
  end
27
25
 
28
26
  def sgets
@@ -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($1.downcase, to_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($1.downcase, to_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
@@ -13,7 +13,7 @@ module Balotelli
13
13
  @klass.sputs("KICK #{channel} #{who} #{reason}")
14
14
  end
15
15
 
16
- alias_method :execute, :execute!
16
+ alias execute execute!
17
17
  end
18
18
  end
19
19
  end
@@ -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
- @responder = @user_nick
12
- else
13
- @responder = @channel
14
- end
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
- fail 'no block given' if block.nil?
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
- fail "Route #{route.inspect}, private: #{option[:private]} already exists"
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
@@ -1,9 +1,9 @@
1
1
  module Balotelli
2
2
  module Core
3
3
  module Utils
4
- NICK_REGEX = /\A(\S+)!.*/.freeze
5
- PRIV_MSG_REGEX = /\A:?(\S+) PRIVMSG (\S+) :?(.*)/.freeze
6
- JOIN_REGEX = /\A:?(\S+) JOIN (\S+)/.freeze
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+) :?(.*)/.freeze
15
+ /\A:?(\S+) \d+ #{nick} \S (#\S+) :?(.*)/
16
16
  end
17
17
  end
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module Balotelli
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
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.0
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-02-17 00:00:00.000000000 Z
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.5.1
112
+ rubygems_version: 2.6.4
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Simple IRC bot framework