blur 1.5.3 → 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.
- data/library/blur.rb +27 -5
- data/library/blur/client.rb +56 -38
- data/library/blur/encryption.rb +17 -0
- data/library/blur/encryption/base64.rb +71 -0
- data/library/blur/encryption/fish.rb +80 -0
- data/library/blur/enhancements.rb +22 -0
- data/library/blur/handling.rb +108 -14
- data/library/blur/network.rb +78 -24
- data/library/blur/network/channel.rb +39 -1
- data/library/blur/network/command.rb +34 -1
- data/library/blur/network/connection.rb +53 -57
- data/library/blur/network/user.rb +44 -10
- data/library/blur/script.rb +35 -1
- data/library/blur/script/cache.rb +26 -1
- data/library/blur/script/messageparsing.rb +32 -1
- metadata +64 -14
data/library/blur/script.rb
CHANGED
@@ -1,11 +1,30 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Blur
|
4
|
+
# The +Script+ class is used for encapsulating dynamically loaded ruby scripts.
|
5
|
+
#
|
6
|
+
# The {Script#Script} method is then used to shape the DSL-language to make
|
7
|
+
# writing Blur scripts a breeze.
|
8
|
+
#
|
9
|
+
# @todo add examples in the documentation
|
10
|
+
# @see Script#Script
|
4
11
|
class Script < Module
|
5
|
-
|
12
|
+
# @return the name of the script.
|
13
|
+
attr_accessor :__name
|
14
|
+
# @return the author of the script.
|
15
|
+
attr_accessor :__author
|
16
|
+
# @return the version of the script.
|
17
|
+
attr_accessor :__version
|
18
|
+
# @return the path in which the script remains.
|
19
|
+
attr_accessor :__path
|
20
|
+
# Can be used inside the script to act with the client itself.
|
21
|
+
# @return [Network::Client] the client delegate.
|
22
|
+
attr_accessor :__client
|
6
23
|
|
24
|
+
# Check to see if the script has been evaluated.
|
7
25
|
def evaluated?; @__evaluated end
|
8
26
|
|
27
|
+
# Instantiates a script and evaluates the contents which remain in +path+.
|
9
28
|
def initialize path
|
10
29
|
@__path = path
|
11
30
|
@__evaluated = false
|
@@ -17,6 +36,14 @@ module Blur
|
|
17
36
|
end
|
18
37
|
end
|
19
38
|
|
39
|
+
# Make it a DSL-way of writing a script.
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# Script :example do
|
43
|
+
# def connection_ready network
|
44
|
+
# # …
|
45
|
+
# end
|
46
|
+
# end
|
20
47
|
def Script name, version = [1,0], author = nil, &block
|
21
48
|
@__name = name
|
22
49
|
@__author = author
|
@@ -27,6 +54,7 @@ module Blur
|
|
27
54
|
true
|
28
55
|
end
|
29
56
|
|
57
|
+
# Unload the script and save the cache, if present.
|
30
58
|
def unload!
|
31
59
|
cache.save if @__cache
|
32
60
|
__send__ :unloaded if respond_to? :unloaded
|
@@ -34,20 +62,26 @@ module Blur
|
|
34
62
|
@__cache = nil
|
35
63
|
end
|
36
64
|
|
65
|
+
# Access another script with name +name+.
|
66
|
+
#
|
67
|
+
# @return [Script] the script with the name +name+, or nil.
|
37
68
|
def script name
|
38
69
|
@__client.scripts.find { |script| script.__name == name }
|
39
70
|
end
|
40
71
|
|
72
|
+
# Get the cache, if none, instantiate a new cache.
|
41
73
|
def cache
|
42
74
|
@__cache ||= Cache.new self
|
43
75
|
end
|
44
76
|
|
77
|
+
# Convert it to a debug-friendly format.
|
45
78
|
def inspect
|
46
79
|
%{#<#{self.class.name} @name=#{@__name.inspect} @version=#{@__version.inspect} @author=#{@__author.inspect}>}
|
47
80
|
end
|
48
81
|
|
49
82
|
private
|
50
83
|
|
84
|
+
# Attempt to evaluate the contents of the script.
|
51
85
|
def evaluate
|
52
86
|
module_eval File.read(@__path), File.basename(@__path), 0
|
53
87
|
@__evaluated = true
|
@@ -2,24 +2,42 @@
|
|
2
2
|
|
3
3
|
module Blur
|
4
4
|
class Script < Module
|
5
|
+
# The +Cache+ class enables data storing inside Blur and it scripts.
|
6
|
+
#
|
7
|
+
# What it does is simply store a hash, and act like it is that hash.
|
8
|
+
#
|
9
|
+
# When the client closes, it sends a message to all available scripts
|
10
|
+
# and then those scripts tells the cache to save, in order to remember
|
11
|
+
# that data and reload it at the next run.
|
12
|
+
#
|
13
|
+
# Cache can then save the contents of the hash to a yaml file that persists
|
14
|
+
# in the ./cache/ directory.
|
15
|
+
#
|
16
|
+
# That same file is then loaded once needed again.
|
5
17
|
class Cache
|
6
|
-
|
18
|
+
# Get the path to the cache directory (./cache/)
|
7
19
|
def self.path
|
8
20
|
%{#{File.dirname File.expand_path $0}/cache}
|
9
21
|
end
|
10
22
|
|
23
|
+
# Check if there exists a cache file for the script with name +name+.
|
11
24
|
def self.exists? name
|
12
25
|
File.exists? "#{path}/#{name}.yml"
|
13
26
|
end
|
14
27
|
|
28
|
+
# Get a cache value by key.
|
15
29
|
def [] key; @hash[key] end
|
30
|
+
|
31
|
+
# Set a cache value by key.
|
16
32
|
def []= key, value; @hash[key] = value end
|
17
33
|
|
34
|
+
# Instantiate a cache with a script reference.
|
18
35
|
def initialize script
|
19
36
|
@hash = {}
|
20
37
|
@script = script
|
21
38
|
end
|
22
39
|
|
40
|
+
# Save all internal data to a yaml file in the cache directory.
|
23
41
|
def save
|
24
42
|
directory = File.dirname path
|
25
43
|
|
@@ -32,6 +50,9 @@ module Blur
|
|
32
50
|
end
|
33
51
|
end
|
34
52
|
|
53
|
+
# Load a yaml file as internal data from the cache directory.
|
54
|
+
#
|
55
|
+
# @return [Hash] the loaded data.
|
35
56
|
def load
|
36
57
|
if yaml = YAML.load_file(path)
|
37
58
|
@hash = yaml
|
@@ -40,10 +61,14 @@ module Blur
|
|
40
61
|
File.unlink path
|
41
62
|
end
|
42
63
|
|
64
|
+
# Let Hash#to_s do the job.
|
43
65
|
def to_s; @hash end
|
44
66
|
|
45
67
|
private
|
46
68
|
|
69
|
+
# The current caches file path.
|
70
|
+
#
|
71
|
+
# @return [String] the file path.
|
47
72
|
def path
|
48
73
|
%{#{Cache.path}/#{@script.__name}.yml}
|
49
74
|
end
|
@@ -2,9 +2,39 @@
|
|
2
2
|
|
3
3
|
module Blur
|
4
4
|
class Script < Module
|
5
|
+
# The +MessageParsing+ module is a module that gives the ability to turn a
|
6
|
+
# script into a DSL-like framework.
|
7
|
+
#
|
8
|
+
# What it does is automatically test to see if a message starts with a
|
9
|
+
# trigger, and then, if so, it sends the command-part of the message to
|
10
|
+
# the script object itself.
|
11
|
+
#
|
12
|
+
# This way, the plugin-writer doesn't need to have repetetive code like
|
13
|
+
# that in every script.
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# Script :example do
|
17
|
+
# extend MessageParsing
|
18
|
+
#
|
19
|
+
# def command_test user, channel, message
|
20
|
+
# channel.say "I hear you."
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# # And if a user were to send the message ".test my method", it would
|
25
|
+
# # trigger the #command_test method with the following arguments
|
26
|
+
# #
|
27
|
+
# # user => #<Blur::Network::User … >
|
28
|
+
# # channel => #<Blur::Network::Channel … >
|
29
|
+
# # message => ".test my method"
|
5
30
|
module MessageParsing
|
31
|
+
# The prefix that turns it into a possible command.
|
6
32
|
MessageTrigger = "."
|
7
33
|
|
34
|
+
# Handle all calls to the scripts +message+ method, check to see if
|
35
|
+
# the message containts a valid command, serialize it and pass it to
|
36
|
+
# the script as command_name with the parameters +user+, +channel+
|
37
|
+
# and +message+.
|
8
38
|
def message user, channel, line
|
9
39
|
return unless line.start_with? MessageTrigger
|
10
40
|
|
@@ -17,7 +47,8 @@ module Blur
|
|
17
47
|
end
|
18
48
|
|
19
49
|
protected
|
20
|
-
|
50
|
+
|
51
|
+
# Strip all non-word characters from the input command.
|
21
52
|
def serialize name
|
22
53
|
name.gsub /\W/, '' if name
|
23
54
|
end
|
metadata
CHANGED
@@ -1,20 +1,63 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 6
|
8
|
+
version: "1.6"
|
6
9
|
platform: ruby
|
7
10
|
authors:
|
8
11
|
- Mikkel Kroman
|
9
12
|
autorequire:
|
10
|
-
bindir:
|
13
|
+
bindir: bin
|
11
14
|
cert_chain: []
|
12
15
|
|
13
|
-
date: 2011-
|
16
|
+
date: 2011-09-30 00:00:00 +02:00
|
14
17
|
default_executable:
|
15
|
-
dependencies:
|
16
|
-
|
17
|
-
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: majic
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 1
|
30
|
+
version: "0.1"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: crypt19
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: eventmachine
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
- 12
|
57
|
+
version: "0.12"
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id003
|
60
|
+
description: " An event-driven IRC-framework in and for Ruby. Is extensible and supports script with (re)loading functionality during runtime.\n"
|
18
61
|
email: mk@maero.dk
|
19
62
|
executables: []
|
20
63
|
|
@@ -26,6 +69,7 @@ files:
|
|
26
69
|
- library/blur.rb
|
27
70
|
- library/blur/client.rb
|
28
71
|
- library/blur/enhancements.rb
|
72
|
+
- library/blur/handling.rb
|
29
73
|
- library/blur/network.rb
|
30
74
|
- library/blur/network/channel.rb
|
31
75
|
- library/blur/network/command.rb
|
@@ -34,11 +78,13 @@ files:
|
|
34
78
|
- library/blur/script.rb
|
35
79
|
- library/blur/script/cache.rb
|
36
80
|
- library/blur/script/messageparsing.rb
|
37
|
-
- library/blur/
|
81
|
+
- library/blur/encryption/fish.rb
|
82
|
+
- library/blur/encryption/base64.rb
|
83
|
+
- library/blur/encryption.rb
|
38
84
|
has_rdoc: true
|
39
|
-
homepage:
|
40
|
-
licenses:
|
41
|
-
|
85
|
+
homepage: https://github.com/mkroman/blur
|
86
|
+
licenses:
|
87
|
+
- ISC
|
42
88
|
post_install_message:
|
43
89
|
rdoc_options: []
|
44
90
|
|
@@ -49,19 +95,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
95
|
requirements:
|
50
96
|
- - ">="
|
51
97
|
- !ruby/object:Gem::Version
|
52
|
-
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
53
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
102
|
none: false
|
55
103
|
requirements:
|
56
104
|
- - ">="
|
57
105
|
- !ruby/object:Gem::Version
|
106
|
+
segments:
|
107
|
+
- 0
|
58
108
|
version: "0"
|
59
109
|
requirements: []
|
60
110
|
|
61
111
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.
|
112
|
+
rubygems_version: 1.3.7
|
63
113
|
signing_key:
|
64
114
|
specification_version: 3
|
65
|
-
summary:
|
115
|
+
summary: An event-driven IRC-framework for Ruby.
|
66
116
|
test_files: []
|
67
117
|
|