blur 1.4 → 1.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.
- data/library/blur.rb +1 -2
- data/library/blur/client.rb +28 -1
- data/library/blur/enhancements.rb +5 -1
- data/library/blur/handling.rb +3 -1
- data/library/blur/network/channel.rb +1 -1
- data/library/blur/network/connection.rb +2 -0
- data/library/blur/network/user.rb +2 -2
- data/library/blur/script.rb +54 -0
- data/library/blur/script/cache.rb +52 -0
- metadata +5 -2
data/library/blur.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'pp'
|
4
3
|
require 'yaml'
|
5
4
|
require 'socket'
|
6
5
|
require 'ostruct'
|
@@ -8,7 +7,7 @@ require 'ostruct'
|
|
8
7
|
Dir.glob("#{File.dirname __FILE__}/blur/**/*.rb").each &method(:require)
|
9
8
|
|
10
9
|
module Blur
|
11
|
-
class << Version = [1,4]
|
10
|
+
class << Version = [1,4,1]
|
12
11
|
def to_s; join '.' end
|
13
12
|
end
|
14
13
|
|
data/library/blur/client.rb
CHANGED
@@ -10,6 +10,7 @@ module Blur
|
|
10
10
|
|
11
11
|
def initialize options
|
12
12
|
@options = options
|
13
|
+
@scripts = []
|
13
14
|
@networks = []
|
14
15
|
@callbacks = {}
|
15
16
|
@connected = true
|
@@ -18,6 +19,7 @@ module Blur
|
|
18
19
|
@networks.<< Network.new options
|
19
20
|
end
|
20
21
|
|
22
|
+
load_scripts
|
21
23
|
trap 2, &method(:quit)
|
22
24
|
end
|
23
25
|
|
@@ -41,6 +43,23 @@ module Blur
|
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
46
|
+
def load_scripts
|
47
|
+
script_path = File.dirname $0
|
48
|
+
|
49
|
+
Dir.glob("#{script_path}/scripts/*.rb").each do |path|
|
50
|
+
script = Script.new path
|
51
|
+
script.client = self
|
52
|
+
|
53
|
+
@scripts << script
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def unload_scripts
|
58
|
+
@scripts.each do |script|
|
59
|
+
script.unload!
|
60
|
+
end.clear
|
61
|
+
end
|
62
|
+
|
44
63
|
def quit signal
|
45
64
|
@networks.each do |network|
|
46
65
|
network.transmit :QUIT, "Got SIGINT?"
|
@@ -64,7 +83,7 @@ module Blur
|
|
64
83
|
network.transcieve
|
65
84
|
sleep 0.05
|
66
85
|
rescue StandardError => exception
|
67
|
-
puts "
|
86
|
+
puts "\e[1m\e[31merror:\e[39m #{exception.message}\e[0m"
|
68
87
|
|
69
88
|
network.disconnect if network.connected?
|
70
89
|
@networks.delete network
|
@@ -79,6 +98,14 @@ module Blur
|
|
79
98
|
@callbacks[name].each do |callback|
|
80
99
|
callback.call *args
|
81
100
|
end if @callbacks[name]
|
101
|
+
|
102
|
+
@scripts.each do |script|
|
103
|
+
begin
|
104
|
+
script.__send__ name, *args if script.respond_to? name
|
105
|
+
rescue Exception => exception
|
106
|
+
puts "\e[1m#{File.basename script.path}:#{exception.line}: \e[31merror:\e[39m #{exception.message}\e[0m"
|
107
|
+
end
|
108
|
+
end
|
82
109
|
end
|
83
110
|
|
84
111
|
def catch name, &block
|
data/library/blur/handling.rb
CHANGED
@@ -52,11 +52,13 @@ module Blur
|
|
52
52
|
# Someone send a message
|
53
53
|
def got_privmsg network, command
|
54
54
|
return if command.sender.is_a? String # Ignore all server privmsgs
|
55
|
-
|
56
55
|
name, message = command.params
|
57
56
|
|
58
57
|
if channel = network.channel_by_name(name)
|
59
58
|
if user = channel.user_by_nick(command.sender.nickname)
|
59
|
+
user.name = command.sender.username
|
60
|
+
user.host = command.sender.hostname
|
61
|
+
|
60
62
|
emit :message, user, channel, message
|
61
63
|
else
|
62
64
|
# Odd… this shouldn't happen
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Blur
|
4
|
+
class Script < Module
|
5
|
+
attr_accessor :name, :author, :version, :path, :client
|
6
|
+
|
7
|
+
def evaluated?; @evaluated end
|
8
|
+
|
9
|
+
def initialize path
|
10
|
+
@path = path
|
11
|
+
@evaluated = false
|
12
|
+
|
13
|
+
if evaluate and @evaluated
|
14
|
+
cache.load if Cache.exists? @name
|
15
|
+
|
16
|
+
__send__ :loaded if respond_to? :loaded
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def Script name, version = [1,0], author = nil, &block
|
21
|
+
@name = name
|
22
|
+
@author = author
|
23
|
+
@version = version
|
24
|
+
|
25
|
+
instance_eval &block
|
26
|
+
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def unload!
|
31
|
+
@cache.save if @cache
|
32
|
+
|
33
|
+
__send__ :unloaded if respond_to? :unloaded
|
34
|
+
end
|
35
|
+
|
36
|
+
def cache
|
37
|
+
@cache ||= Cache.new self
|
38
|
+
end
|
39
|
+
|
40
|
+
def inspect
|
41
|
+
%{#<#{self.class.name} @name=#{@name.inspect} @version=#{@version.inspect} @author=#{@author.inspect}>}
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def evaluate
|
47
|
+
if module_eval File.read(@path), File.basename(@path), 0
|
48
|
+
@evaluated = true
|
49
|
+
end
|
50
|
+
rescue Exception => exception
|
51
|
+
puts "\e[1m#{File.basename @path}:#{exception.line}: \e[31merror:\e[39m #{exception.message}\e[0m"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Blur
|
4
|
+
class Script < Module
|
5
|
+
class Cache
|
6
|
+
|
7
|
+
def self.path
|
8
|
+
%{#{File.dirname File.expand_path $0}/cache}
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.exists? name
|
12
|
+
File.exists? "#{path}/#{name}.yml"
|
13
|
+
end
|
14
|
+
|
15
|
+
def [] key; @hash[key] ||= {} end
|
16
|
+
def []= key, value; @hash[key] = value end
|
17
|
+
|
18
|
+
def initialize script
|
19
|
+
@hash = {}
|
20
|
+
@script = script
|
21
|
+
end
|
22
|
+
|
23
|
+
def save
|
24
|
+
directory = File.dirname path
|
25
|
+
|
26
|
+
unless File.directory? directory
|
27
|
+
Dir.mkdir directory
|
28
|
+
end
|
29
|
+
|
30
|
+
File.open path, ?w do |file|
|
31
|
+
YAML.dump @hash, file
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def load
|
36
|
+
if yaml = YAML.load_file(path)
|
37
|
+
@hash = yaml
|
38
|
+
end
|
39
|
+
rescue
|
40
|
+
File.unlink path
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_s; @hash end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def path
|
48
|
+
%{#{Cache.path}/#{@script.name}.yml}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 4
|
8
|
-
|
8
|
+
- 1
|
9
|
+
version: 1.4.1
|
9
10
|
platform: ruby
|
10
11
|
authors:
|
11
12
|
- Mikkel Kroman
|
@@ -13,7 +14,7 @@ autorequire:
|
|
13
14
|
bindir: executables
|
14
15
|
cert_chain: []
|
15
16
|
|
16
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-18 00:00:00 +01:00
|
17
18
|
default_executable:
|
18
19
|
dependencies: []
|
19
20
|
|
@@ -34,6 +35,8 @@ files:
|
|
34
35
|
- library/blur/network/connection.rb
|
35
36
|
- library/blur/network/user.rb
|
36
37
|
- library/blur/network.rb
|
38
|
+
- library/blur/script/cache.rb
|
39
|
+
- library/blur/script.rb
|
37
40
|
- library/blur.rb
|
38
41
|
has_rdoc: true
|
39
42
|
homepage:
|