blur 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/library/blur.rb +1 -1
- data/library/blur/client.rb +4 -3
- data/library/blur/handling.rb +10 -0
- data/library/blur/network.rb +16 -5
- data/library/blur/network/connection.rb +2 -2
- data/library/blur/network/user.rb +2 -2
- data/library/blur/script.rb +17 -17
- data/library/blur/script/cache.rb +1 -1
- metadata +2 -2
data/library/blur.rb
CHANGED
data/library/blur/client.rb
CHANGED
@@ -46,7 +46,7 @@ module Blur
|
|
46
46
|
|
47
47
|
Dir.glob("#{script_path}/scripts/*.rb").each do |path|
|
48
48
|
script = Script.new path
|
49
|
-
script.
|
49
|
+
script.__client = self
|
50
50
|
|
51
51
|
@scripts << script
|
52
52
|
end
|
@@ -84,9 +84,10 @@ module Blur
|
|
84
84
|
rescue StandardError => exception
|
85
85
|
if network.connected?
|
86
86
|
network.disconnect
|
87
|
-
emit :connection_terminated, network
|
88
87
|
end
|
89
88
|
|
89
|
+
emit :connection_terminated, network
|
90
|
+
|
90
91
|
puts "#{"Network error" ^ :red} (#{exception.class.name}): #{exception.message}"
|
91
92
|
end
|
92
93
|
end
|
@@ -104,7 +105,7 @@ module Blur
|
|
104
105
|
begin
|
105
106
|
script.__send__ name, *args if script.respond_to? name
|
106
107
|
rescue Exception => exception
|
107
|
-
puts ("#{File.basename script.
|
108
|
+
puts ("#{File.basename script.__path}:#{exception.line}" ^ :bold) + ": #{"error:" ^ :red} #{exception.message}"
|
108
109
|
end
|
109
110
|
end
|
110
111
|
end
|
data/library/blur/handling.rb
CHANGED
@@ -23,6 +23,8 @@ module Blur
|
|
23
23
|
if channel = network.channel_by_name(name)
|
24
24
|
users.each do |user|
|
25
25
|
user.channel = channel
|
26
|
+
user.network = network
|
27
|
+
|
26
28
|
channel.users << user
|
27
29
|
end
|
28
30
|
else
|
@@ -77,6 +79,13 @@ module Blur
|
|
77
79
|
else
|
78
80
|
# Odd… this shouldn't happen
|
79
81
|
end
|
82
|
+
else # This is a private message
|
83
|
+
user = Network::User.new command.sender.nickname
|
84
|
+
user.name = command.sender.username
|
85
|
+
user.host = command.sender.hostname
|
86
|
+
user.network = network
|
87
|
+
|
88
|
+
emit :private_message, user, message
|
80
89
|
end
|
81
90
|
end
|
82
91
|
|
@@ -89,6 +98,7 @@ module Blur
|
|
89
98
|
user.name = command.sender.username
|
90
99
|
user.host = command.sender.hostname
|
91
100
|
user.channel = channel
|
101
|
+
user.network = network
|
92
102
|
|
93
103
|
channel.users << user
|
94
104
|
|
data/library/blur/network.rb
CHANGED
@@ -4,13 +4,21 @@ module Blur
|
|
4
4
|
class Network
|
5
5
|
class ConnectionError < StandardError; end
|
6
6
|
|
7
|
-
attr_accessor :options, :channels, :delegate, :connection
|
7
|
+
attr_accessor :options, :channels, :dialogues, :delegate, :connection
|
8
8
|
|
9
9
|
def connected?; @connection.established? end
|
10
|
+
|
11
|
+
def host
|
12
|
+
@options[:hostname]
|
13
|
+
end
|
14
|
+
|
15
|
+
def port
|
16
|
+
@options[:port] ||= secure? ? 6697 : 6667
|
17
|
+
end
|
10
18
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
19
|
+
def secure?
|
20
|
+
@options[:secure] == true
|
21
|
+
end
|
14
22
|
|
15
23
|
def initialize options = {}
|
16
24
|
@options = options
|
@@ -45,7 +53,7 @@ module Blur
|
|
45
53
|
|
46
54
|
def connect
|
47
55
|
@connection.establish
|
48
|
-
@connection.enable_ssl OpenSSL::SSL::VERIFY_NONE if
|
56
|
+
@connection.enable_ssl OpenSSL::SSL::VERIFY_NONE if secure?
|
49
57
|
|
50
58
|
transmit :PASS, @options[:password] if @options[:password]
|
51
59
|
transmit :NICK, @options[:nickname]
|
@@ -54,6 +62,9 @@ module Blur
|
|
54
62
|
|
55
63
|
def disconnect
|
56
64
|
@connection.terminate
|
65
|
+
|
66
|
+
@channels.each { |channel| channel.users.clear }
|
67
|
+
@channels.clear
|
57
68
|
end
|
58
69
|
|
59
70
|
def transmit name, *arguments
|
@@ -18,11 +18,11 @@ module Blur
|
|
18
18
|
@socket = TCPSocket.new @host, @port
|
19
19
|
end
|
20
20
|
|
21
|
-
def enable_ssl
|
21
|
+
def enable_ssl verification
|
22
22
|
@secure = true
|
23
23
|
|
24
24
|
context = OpenSSL::SSL::SSLContext.new
|
25
|
-
context.set_params verify_mode:
|
25
|
+
context.set_params verify_mode: verification
|
26
26
|
|
27
27
|
sslsocket = OpenSSL::SSL::SSLSocket.new @socket, context
|
28
28
|
sslsocket.sync = true
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Blur
|
4
4
|
class Network
|
5
5
|
class User
|
6
|
-
attr_accessor :nick, :name, :host, :modes, :channel
|
6
|
+
attr_accessor :nick, :name, :host, :modes, :channel, :network
|
7
7
|
|
8
8
|
def self.map_mode name, character
|
9
9
|
define_method(:"#{name}?") { @modes.include? character.to_s }
|
@@ -41,7 +41,7 @@ module Blur
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def say message
|
44
|
-
@
|
44
|
+
@network.say self, message
|
45
45
|
end
|
46
46
|
|
47
47
|
def inspect
|
data/library/blur/script.rb
CHANGED
@@ -2,25 +2,25 @@
|
|
2
2
|
|
3
3
|
module Blur
|
4
4
|
class Script < Module
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :__name, :__author, :__version, :__path, :__client
|
6
6
|
|
7
|
-
def evaluated?; @
|
7
|
+
def evaluated?; @__evaluated end
|
8
8
|
|
9
9
|
def initialize path
|
10
|
-
@
|
11
|
-
@
|
10
|
+
@__path = path
|
11
|
+
@__evaluated = false
|
12
12
|
|
13
|
-
if evaluate and @
|
14
|
-
cache.load if Cache.exists? @
|
13
|
+
if evaluate and @__evaluated
|
14
|
+
cache.load if Cache.exists? @__name
|
15
15
|
|
16
16
|
__send__ :loaded if respond_to? :loaded
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def Script name, version = [1,0], author = nil, &block
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
21
|
+
@__name = name
|
22
|
+
@__author = author
|
23
|
+
@__version = version
|
24
24
|
|
25
25
|
instance_eval &block
|
26
26
|
|
@@ -28,31 +28,31 @@ module Blur
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def unload!
|
31
|
-
cache.save if @
|
31
|
+
cache.save if @__cache
|
32
32
|
__send__ :unloaded if respond_to? :unloaded
|
33
33
|
|
34
|
-
@
|
34
|
+
@__cache = nil
|
35
35
|
end
|
36
36
|
|
37
37
|
def script name
|
38
|
-
@
|
38
|
+
@__client.scripts.find { |script| script.__name == name }
|
39
39
|
end
|
40
40
|
|
41
41
|
def cache
|
42
|
-
@
|
42
|
+
@__cache ||= Cache.new self
|
43
43
|
end
|
44
44
|
|
45
45
|
def inspect
|
46
|
-
%{#<#{self.class.name} @name=#{@
|
46
|
+
%{#<#{self.class.name} @name=#{@__name.inspect} @version=#{@__version.inspect} @author=#{@__author.inspect}>}
|
47
47
|
end
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
51
|
def evaluate
|
52
|
-
module_eval File.read(@
|
53
|
-
@
|
52
|
+
module_eval File.read(@__path), File.basename(@__path), 0
|
53
|
+
@__evaluated = true
|
54
54
|
rescue Exception => exception
|
55
|
-
puts "#{File.basename(@
|
55
|
+
puts "#{File.basename(@__path) ^ :bold}:#{exception.line.to_s ^ :bold}: #{"error:" ^ :red} #{exception.message ^ :bold}"
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: blur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.5.
|
5
|
+
version: 1.5.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mikkel Kroman
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: executables
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-14 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|