blur 2.1.3 → 2.1.6
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/executables/blur +16 -15
- data/library/blur/callbacks.rb +12 -16
- data/library/blur/channel.rb +11 -8
- data/library/blur/client.rb +36 -43
- data/library/blur/handling.rb +140 -113
- data/library/blur/network/connection.rb +24 -28
- data/library/blur/network/isupport.rb +38 -32
- data/library/blur/network.rb +87 -14
- data/library/blur/script.rb +21 -12
- data/library/blur/script_cache.rb +12 -10
- data/library/blur/user.rb +43 -26
- data/library/blur/version.rb +3 -3
- data/library/blur.rb +16 -14
- metadata +8 -10
- data/library/blur/enhancements.rb +0 -39
- data/library/blur/logging.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c4add65cc3b256a41629f69bb62065d523f60a5cd934d8b4c1045b326113ce6
|
4
|
+
data.tar.gz: f55fbec4a5863465d61f110ceeb1fe3b7f89d6a6d9fc659ac30907ef7921e510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05bc91b4a941bfe212e42d9a0c56d6e7969aa01e9cde2fa86946dc0f24244b462de299683d06875e2ea3bdad7e32280afd869cac6874d0fd7ef1f3d9bfa10d63
|
7
|
+
data.tar.gz: 9ca64c3952d10ccb6c9dce8a51723da4b81643b46d2090aa72b72886965d8973da540a6b9da477254493baf99d1ad2174b7c5129557f963fb08db892ce42a632
|
data/executables/blur
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require_relative '../library/blur'
|
5
5
|
|
6
6
|
require 'optparse'
|
7
7
|
|
8
8
|
options = {
|
9
9
|
verbose: false,
|
10
|
-
environment: 'development',
|
11
10
|
config_path: 'config.yml'
|
12
11
|
}
|
13
12
|
|
14
13
|
OptionParser.new do |opts|
|
15
|
-
opts.banner = "Usage:
|
14
|
+
opts.banner = "Usage: #{$PROGRAM_NAME} [-c <config>] [-e <env>]"
|
16
15
|
|
17
|
-
opts.separator
|
18
|
-
opts.separator
|
16
|
+
opts.separator ''
|
17
|
+
opts.separator 'Specific options:'
|
19
18
|
|
20
19
|
opts.on '-v', '--[no-]verbose', 'Enable verbose logging' do |verbose|
|
21
20
|
options[:verbose] = verbose
|
@@ -41,22 +40,24 @@ end.parse!
|
|
41
40
|
|
42
41
|
begin
|
43
42
|
require 'blur'
|
44
|
-
rescue LoadError =>
|
43
|
+
rescue LoadError => e
|
45
44
|
puts 'Ruby was unable to load the blur library!'
|
46
45
|
puts
|
47
46
|
puts "Please ensure that you've installed it using the following command:"
|
48
47
|
puts 'gem install blur'
|
49
|
-
raise
|
50
|
-
exit 1
|
48
|
+
raise e
|
51
49
|
end
|
52
50
|
|
51
|
+
puts "Blur #{Blur.version}"
|
52
|
+
|
53
53
|
config_path = File.expand_path options[:config_path]
|
54
|
-
|
55
|
-
fail "Configuration file `#{config_path}' is not readable"
|
56
|
-
exit 1
|
57
|
-
end
|
54
|
+
puts "Loading configuration file `#{config_path}' .."
|
58
55
|
|
59
|
-
|
60
|
-
|
56
|
+
raise "Configuration file `#{config_path}' is not readable" unless File.readable? config_path
|
57
|
+
|
58
|
+
EM.run do
|
59
|
+
@client = Blur::Client.new options
|
60
|
+
@client.connect
|
61
|
+
end
|
61
62
|
|
62
63
|
# vim: syntax=ruby
|
data/library/blur/callbacks.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Blur
|
4
4
|
module Callbacks
|
@@ -16,14 +16,12 @@ module Blur
|
|
16
16
|
# @return [true, false] True if any callbacks were invoked, nil otherwise
|
17
17
|
def emit name, *args
|
18
18
|
# Trigger callbacks in scripts before triggering events in the client.
|
19
|
-
|
19
|
+
notify_scripts name, *args
|
20
20
|
|
21
21
|
matching_callbacks = callbacks[name]
|
22
22
|
return false unless matching_callbacks&.any?
|
23
23
|
|
24
|
-
|
25
|
-
matching_callbacks.each { |callback| callback.call *args }
|
26
|
-
end
|
24
|
+
matching_callbacks.each { |callback| callback.call *args }
|
27
25
|
end
|
28
26
|
|
29
27
|
# Add a new event callback.
|
@@ -37,20 +35,18 @@ module Blur
|
|
37
35
|
protected
|
38
36
|
|
39
37
|
def notify_scripts name, *args
|
40
|
-
scripts = @scripts.values.select{|script| script.class.events.key? name }
|
38
|
+
scripts = @scripts.values.select { |script| script.class.events.key? name }
|
41
39
|
scripts.each do |script|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
script.__send__ method, *args
|
48
|
-
end
|
40
|
+
script.class.events[name].each do |method|
|
41
|
+
if method.is_a? Proc
|
42
|
+
method.call script, *args
|
43
|
+
else
|
44
|
+
script.__send__ method, *args
|
49
45
|
end
|
50
|
-
rescue => exception
|
51
|
-
STDERR.puts "#{exception.class}: #{exception.message}"
|
52
|
-
STDERR.puts nil, 'Backtrace:', '---', exception.backtrace
|
53
46
|
end
|
47
|
+
rescue StandardError => e
|
48
|
+
warn "#{e.class}: #{e.message}"
|
49
|
+
warn nil, 'Backtrace:', '---', e.backtrace
|
54
50
|
end
|
55
51
|
end
|
56
52
|
end
|
data/library/blur/channel.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Blur
|
4
4
|
# The +Channel+ class is used for encapsulating a channel and its properties.
|
5
5
|
#
|
6
6
|
# Users inside the channel is stored in the {#channels} attribute.
|
7
7
|
#
|
8
|
-
# Modes can be set for a channel, but Blur is not
|
8
|
+
# Modes can be set for a channel, but Blur is not
|
9
9
|
# {http://www.irc.org/tech_docs/005.html ISupport}-compliant yet.
|
10
10
|
#
|
11
11
|
# @todo make so that channels *and* users belongs to the network, and not
|
@@ -26,8 +26,8 @@ module Blur
|
|
26
26
|
# Instantiate a user with a nickname, a network and a user list.
|
27
27
|
def initialize name, network = nil
|
28
28
|
@name = name
|
29
|
-
@users
|
30
|
-
@modes =
|
29
|
+
@users = []
|
30
|
+
@modes = ''
|
31
31
|
@network = network
|
32
32
|
end
|
33
33
|
|
@@ -39,9 +39,9 @@ module Blur
|
|
39
39
|
|
40
40
|
modes.each_char do |char|
|
41
41
|
case char
|
42
|
-
when
|
42
|
+
when '+'
|
43
43
|
addition = true
|
44
|
-
when
|
44
|
+
when '-'
|
45
45
|
addition = false
|
46
46
|
else
|
47
47
|
addition ? @modes.concat(char) : @modes.delete!(char)
|
@@ -58,9 +58,12 @@ module Blur
|
|
58
58
|
|
59
59
|
# Convert it to a debug-friendly format.
|
60
60
|
def inspect
|
61
|
-
|
61
|
+
"#<#{self.class.name}:0x#{object_id.to_s 16} " \
|
62
|
+
"@name=#{@name.inspect} " \
|
63
|
+
"@topic=#{@topic.inspect} " \
|
64
|
+
"@users=#{@users.inspect}>"
|
62
65
|
end
|
63
|
-
|
66
|
+
|
64
67
|
# Called when YAML attempts to save the object, which happens when a
|
65
68
|
# scripts cache contains this user and the script is unloaded.
|
66
69
|
def to_yaml options = {}
|
data/library/blur/client.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative './handling'
|
4
4
|
|
5
5
|
module Blur
|
6
6
|
# The +Client+ class is the controller of the low-level access.
|
@@ -10,13 +10,9 @@ module Blur
|
|
10
10
|
class Client
|
11
11
|
include Callbacks
|
12
12
|
include Handling
|
13
|
-
include Logging
|
14
|
-
|
15
|
-
# Client error.
|
16
|
-
Error = Class.new StandardError
|
17
13
|
|
18
14
|
# The default environment.
|
19
|
-
ENVIRONMENT = ENV['BLUR_ENV'] || 'development'
|
15
|
+
ENVIRONMENT = ENV['BLUR_ENV'] || 'development'
|
20
16
|
|
21
17
|
# The default configuration.
|
22
18
|
DEFAULT_CONFIG = {
|
@@ -25,9 +21,9 @@ module Blur
|
|
25
21
|
'scripts_dir' => 'scripts/',
|
26
22
|
'networks' => []
|
27
23
|
},
|
28
|
-
'scripts' => {}
|
24
|
+
'scripts' => {}
|
29
25
|
}.freeze
|
30
|
-
|
26
|
+
|
31
27
|
# @return [Array] a list of instantiated networks.
|
32
28
|
attr_accessor :networks
|
33
29
|
# @return [Hash] client configuration.
|
@@ -49,12 +45,10 @@ module Blur
|
|
49
45
|
@scripts = {}
|
50
46
|
@networks = []
|
51
47
|
@config_path = options[:config_path]
|
52
|
-
@environment = options[:environment]
|
48
|
+
@environment = options[:environment] || ENVIRONMENT
|
53
49
|
@verbose = options[:verbose] == true
|
54
50
|
|
55
|
-
unless @config_path
|
56
|
-
raise ConfigError, 'missing config file path in :config_path option'
|
57
|
-
end
|
51
|
+
raise ConfigError, 'missing config file path in :config_path option' unless @config_path
|
58
52
|
|
59
53
|
load_config!
|
60
54
|
|
@@ -68,23 +62,25 @@ module Blur
|
|
68
62
|
|
69
63
|
trap 2, &method(:quit)
|
70
64
|
end
|
71
|
-
|
65
|
+
|
72
66
|
# Connect to each network available that is not already connected, then
|
73
67
|
# proceed to start the run-loop.
|
74
68
|
def connect
|
75
69
|
networks = @networks.reject &:connected?
|
76
|
-
|
77
|
-
EventMachine.run do
|
78
|
-
load_scripts!
|
79
|
-
networks.each &:connect
|
80
70
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
71
|
+
load_scripts!
|
72
|
+
networks.each &:connect
|
73
|
+
|
74
|
+
EventMachine.error_handler do |exception|
|
75
|
+
message_pattern = /^.*?:(\d+):/
|
76
|
+
backtrace = exception.backtrace.first
|
77
|
+
error_line = backtrace.match(message_pattern)[1].to_i + 1
|
78
|
+
|
79
|
+
puts "#{exception.message} on line #{error_line.to_s}"
|
80
|
+
puts exception.backtrace.join "\n"
|
85
81
|
end
|
86
82
|
end
|
87
|
-
|
83
|
+
|
88
84
|
# Is called when a command have been received and parsed, this distributes
|
89
85
|
# the command to the loader, which then further distributes it to events
|
90
86
|
# and scripts.
|
@@ -92,26 +88,23 @@ module Blur
|
|
92
88
|
# @param [Network] network the network that received the command.
|
93
89
|
# @param [Network::Command] command the received command.
|
94
90
|
def got_message network, message
|
95
|
-
if @verbose
|
96
|
-
|
97
|
-
end
|
91
|
+
puts "← #{message.command.to_s.ljust(8, ' ')} #{message.parameters.map(&:inspect).join ' '}" if @verbose
|
92
|
+
|
98
93
|
name = :"got_#{message.command.downcase}"
|
99
94
|
|
100
|
-
if respond_to? name
|
101
|
-
__send__ name, network, message
|
102
|
-
end
|
95
|
+
__send__ name, network, message if respond_to? name
|
103
96
|
end
|
104
|
-
|
97
|
+
|
105
98
|
# Called when a network connection is either closed, or terminated.
|
106
99
|
def network_connection_closed network
|
107
100
|
emit :connection_close, network
|
108
101
|
end
|
109
|
-
|
102
|
+
|
110
103
|
# Try to gracefully disconnect from each network, unload all scripts and
|
111
104
|
# exit properly.
|
112
105
|
#
|
113
106
|
# @param [optional, Symbol] signal The signal received by the system, if any.
|
114
|
-
def quit
|
107
|
+
def quit _signal = :SIGINT
|
115
108
|
@networks.each do |network|
|
116
109
|
network.transmit :QUIT, 'Got SIGINT?'
|
117
110
|
network.disconnect
|
@@ -161,11 +154,11 @@ module Blur
|
|
161
154
|
# @raise [Exception] if there was any problems loading the file
|
162
155
|
def load_script_file file_path
|
163
156
|
load file_path, true
|
164
|
-
rescue Exception =>
|
157
|
+
rescue Exception => e
|
165
158
|
warn "The script `#{file_path}' failed to load"
|
166
|
-
warn "#{
|
159
|
+
warn "#{e.class}: #{e.message}"
|
167
160
|
warn ''
|
168
|
-
warn 'Backtrace:', '---',
|
161
|
+
warn 'Backtrace:', '---', e.backtrace
|
169
162
|
end
|
170
163
|
|
171
164
|
# Instantiates each +SuperScript+ in the +Blur.scripts+ list by manually
|
@@ -194,7 +187,7 @@ module Blur
|
|
194
187
|
# This method will call #unloaded on the instance of each loaded script to
|
195
188
|
# give it a chance to clean up any resources.
|
196
189
|
def unload_scripts!
|
197
|
-
@scripts.each do |
|
190
|
+
@scripts.each do |_name, script|
|
198
191
|
script.__send__ :unloaded if script.respond_to? :unloaded
|
199
192
|
end.clear
|
200
193
|
|
@@ -209,14 +202,14 @@ module Blur
|
|
209
202
|
def load_config!
|
210
203
|
config = YAML.load_file @config_path
|
211
204
|
|
212
|
-
|
213
|
-
|
214
|
-
@config.deeper_merge! DEFAULT_CONFIG
|
215
|
-
|
216
|
-
emit :config_load
|
217
|
-
else
|
218
|
-
raise Error, "No configuration found for specified environment `#{@environment}'"
|
205
|
+
unless config.key? @environment
|
206
|
+
raise ClientError, "No configuration found for specified environment `#{@environment}'"
|
219
207
|
end
|
208
|
+
|
209
|
+
@config = config[@environment]
|
210
|
+
@config.deeper_merge! DEFAULT_CONFIG
|
211
|
+
|
212
|
+
emit :config_load
|
220
213
|
end
|
221
214
|
end
|
222
215
|
end
|