blur 1.6 → 1.6.2.pre

Sign up to get free protection for your applications and to get access to all the features.
data/library/blur.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'pp'
3
4
  require 'yaml'
4
5
  require 'majic'
5
6
  require 'socket'
@@ -26,7 +27,7 @@ require 'blur/script/messageparsing'
26
27
  # It can be by handlers, scripts, communications, and what have you.
27
28
  module Blur
28
29
  # The major and minor version-values of Blur.
29
- Version = "1.6"
30
+ Version = "1.6.2.pre"
30
31
 
31
32
  # Instantiates a client with given options and then makes the client instance
32
33
  # evaluate the given block to form a DSL.
@@ -8,7 +8,7 @@ module Blur
8
8
  # It stores networks, scripts and callbacks, and is also encharge of
9
9
  # distributing the incoming commands to the right networks and scripts.
10
10
  class Client
11
- include Handling
11
+ include Handling, Logging
12
12
 
13
13
  # @return [Array] the options that is passed upon initialization.
14
14
  attr_accessor :options
@@ -57,7 +57,7 @@ module Blur
57
57
  # @param [Network] network the network that received the command.
58
58
  # @param [Network::Command] command the received command.
59
59
  def got_command network, command
60
- puts "<- #{network.inspect ^ :bold} | #{command}"
60
+ log "#{'←' ^ :green} #{command.name.to_s.ljust(8, ' ') ^ :light_gray} #{command.params.map(&:inspect).join ' '}"
61
61
  name = :"got_#{command.name.downcase}"
62
62
 
63
63
  if respond_to? name
@@ -110,15 +110,19 @@ module Blur
110
110
  # @param [...] args Arguments that is passed to the event-handler.
111
111
  # @private
112
112
  def emit name, *args
113
- @callbacks[name].each do |callback|
114
- callback.call *args
115
- end if @callbacks[name]
116
-
117
- @scripts.each do |script|
118
- begin
119
- script.__send__ name, *args if script.respond_to? name
120
- rescue Exception => exception
121
- puts ("#{File.basename script.__path}:#{exception.line}" ^ :bold) + ": #{"error:" ^ :red} #{exception.message}"
113
+ EM.defer do
114
+ @callbacks[name].each do |callback|
115
+ callback.call *args
116
+ end if @callbacks[name]
117
+
118
+ scripts = @scripts.select{|script| script.__emissions.include? name }
119
+
120
+ scripts.each do |script|
121
+ begin
122
+ script.__send__ name, *args
123
+ rescue Exception => exception
124
+ log.error "#{File.basename(script.__path) << " - " << exception.message ^ :bold} on line #{exception.line.to_s ^ :bold}"
125
+ end
122
126
  end
123
127
  end
124
128
  end
@@ -79,8 +79,14 @@ module Blur
79
79
  if channel = network.channel_by_name(name)
80
80
  emit :topic_change, channel, topic
81
81
  channel.topic = topic
82
- else
82
+ else
83
83
  channel = Network::Channel.new name, network, []
84
+
85
+ if network.fish? and network.options[:fish].key? name
86
+ keyphrase = network.options[:fish][name]
87
+ channel.encryption = Encryption::FiSH.new keyphrase
88
+ end
89
+
84
90
  emit :topic_change, channel, topic
85
91
  channel.topic = topic
86
92
 
@@ -134,7 +140,7 @@ module Blur
134
140
  message = channel.encryption.decrypt message[4..-1]
135
141
  end
136
142
  rescue Encryption::BadInputError
137
- #
143
+ puts "-!- FiSH: #{$!.message}"
138
144
  rescue => exception
139
145
  puts "-!- There was a problem with the FiSH encryption, disabling"
140
146
 
@@ -6,6 +6,8 @@ module Blur
6
6
  # Although the connection is a part of the network module, it is mainly used
7
7
  # for network-related structures, such as {User}, {Channel} and {Command}.
8
8
  class Network
9
+ include Logging
10
+
9
11
  # +ConnectionError+ should only be triggered from within {Connection}.
10
12
  class ConnectionError < StandardError; end
11
13
 
@@ -73,7 +75,7 @@ module Blur
73
75
  message = "+OK #{recipient.encryption.encrypt message}"
74
76
  end
75
77
 
76
- transmit :PRIVMSG, recipient, message
78
+ transmit :PRIVMSG, recipient.to_s, message
77
79
  end
78
80
 
79
81
  # Called when the network connection has enough data to form a command.
@@ -126,7 +128,7 @@ module Blur
126
128
  # @param [...] arguments all the prepended parameters.
127
129
  def transmit name, *arguments
128
130
  command = Command.new name, arguments
129
- puts "-> #{inspect ^ :bold} | #{command}"
131
+ log "#{'→' ^ :red} #{command.name.to_s.ljust(8, ' ') ^ :light_gray} #{command.params.map(&:inspect).join ' '}"
130
132
 
131
133
  @connection.send_data "#{command}\r\n"
132
134
  end
@@ -61,7 +61,7 @@ module Blur
61
61
  else
62
62
  @sender = prefix
63
63
  end
64
- end
64
+ end
65
65
 
66
66
  # Convert it to an IRC-compliant line.
67
67
  #
@@ -9,6 +9,12 @@ module Blur
9
9
  # @todo add examples in the documentation
10
10
  # @see Script#Script
11
11
  class Script < Module
12
+ include Logging
13
+
14
+ Emissions = [:connection_ready, :topic_change, :user_rename, :message,
15
+ :private_message, :user_entered, :user_left, :user_quit,
16
+ :user_kicked, :topic, :user_mode, :channel_mode]
17
+
12
18
  # @return the name of the script.
13
19
  attr_accessor :__name
14
20
  # @return the author of the script.
@@ -20,6 +26,8 @@ module Blur
20
26
  # Can be used inside the script to act with the client itself.
21
27
  # @return [Network::Client] the client delegate.
22
28
  attr_accessor :__client
29
+ # @return [Array] a list of handled emissions.
30
+ attr_accessor :__emissions
23
31
 
24
32
  # Check to see if the script has been evaluated.
25
33
  def evaluated?; @__evaluated end
@@ -28,9 +36,14 @@ module Blur
28
36
  def initialize path
29
37
  @__path = path
30
38
  @__evaluated = false
39
+ @__emissions = []
31
40
 
32
41
  if evaluate and @__evaluated
33
42
  cache.load if Cache.exists? @__name
43
+
44
+ Emissions.each do |emission|
45
+ @__emissions.push emission if respond_to? emission
46
+ end
34
47
 
35
48
  __send__ :loaded if respond_to? :loaded
36
49
  end
@@ -76,17 +89,17 @@ module Blur
76
89
 
77
90
  # Convert it to a debug-friendly format.
78
91
  def inspect
79
- %{#<#{self.class.name} @name=#{@__name.inspect} @version=#{@__version.inspect} @author=#{@__author.inspect}>}
92
+ File.basename @__path
80
93
  end
81
94
 
82
95
  private
83
96
 
84
97
  # Attempt to evaluate the contents of the script.
85
98
  def evaluate
86
- module_eval File.read(@__path), File.basename(@__path), 0
99
+ instance_eval File.read(@__path), File.basename(@__path), 0
87
100
  @__evaluated = true
88
101
  rescue Exception => exception
89
- puts "#{File.basename(@__path) ^ :bold}:#{exception.line.to_s ^ :bold}: #{"error:" ^ :red} #{exception.message ^ :bold}"
102
+ log.error "#{exception.message ^ :bold} on line #{exception.line.to_s ^ :bold}"
90
103
  end
91
104
  end
92
105
  end
@@ -30,6 +30,10 @@ module Blur
30
30
  module MessageParsing
31
31
  # The prefix that turns it into a possible command.
32
32
  MessageTrigger = "."
33
+
34
+ def self.extended klass
35
+ warn "#{File.realpath __FILE__}: MessageParsing will be deprecated in the future, use Fantasy."
36
+ end
33
37
 
34
38
  # Handle all calls to the scripts +message+ method, check to see if
35
39
  # the message containts a valid command, serialize it and pass it to
metadata CHANGED
@@ -1,73 +1,63 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: blur
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 6
8
- version: "1.6"
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.2.pre
5
+ prerelease: 6
9
6
  platform: ruby
10
- authors:
7
+ authors:
11
8
  - Mikkel Kroman
12
9
  autorequire:
13
10
  bindir: bin
14
11
  cert_chain: []
15
-
16
- date: 2011-09-30 00:00:00 +02:00
17
- default_executable:
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
12
+ date: 2011-11-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
20
15
  name: majic
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &19385580 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 1
30
- version: "0.1"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.2'
31
22
  type: :runtime
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: crypt19
35
23
  prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *19385580
25
+ - !ruby/object:Gem::Dependency
26
+ name: crypt19
27
+ requirement: &19401480 !ruby/object:Gem::Requirement
37
28
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.1
44
33
  type: :runtime
45
- version_requirements: *id002
46
- - !ruby/object:Gem::Dependency
47
- name: eventmachine
48
34
  prerelease: false
49
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *19401480
36
+ - !ruby/object:Gem::Dependency
37
+ name: eventmachine
38
+ requirement: &19401020 !ruby/object:Gem::Requirement
50
39
  none: false
51
- requirements:
52
- - - ">"
53
- - !ruby/object:Gem::Version
54
- segments:
55
- - 0
56
- - 12
57
- version: "0.12"
40
+ requirements:
41
+ - - ! '>'
42
+ - !ruby/object:Gem::Version
43
+ version: '0.12'
58
44
  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"
45
+ prerelease: false
46
+ version_requirements: *19401020
47
+ description: ! ' An event-driven IRC-framework in and for Ruby. Is extensible and
48
+ supports script with (re)loading functionality during runtime.
49
+
50
+ '
61
51
  email: mk@maero.dk
62
52
  executables: []
63
-
64
53
  extensions: []
65
-
66
54
  extra_rdoc_files: []
67
-
68
- files:
55
+ files:
69
56
  - library/blur.rb
70
57
  - library/blur/client.rb
58
+ - library/blur/encryption.rb
59
+ - library/blur/encryption/base64.rb
60
+ - library/blur/encryption/fish.rb
71
61
  - library/blur/enhancements.rb
72
62
  - library/blur/handling.rb
73
63
  - library/blur/network.rb
@@ -78,40 +68,29 @@ files:
78
68
  - library/blur/script.rb
79
69
  - library/blur/script/cache.rb
80
70
  - library/blur/script/messageparsing.rb
81
- - library/blur/encryption/fish.rb
82
- - library/blur/encryption/base64.rb
83
- - library/blur/encryption.rb
84
- has_rdoc: true
85
71
  homepage: https://github.com/mkroman/blur
86
- licenses:
72
+ licenses:
87
73
  - ISC
88
74
  post_install_message:
89
75
  rdoc_options: []
90
-
91
- require_paths:
76
+ require_paths:
92
77
  - library
93
- required_ruby_version: !ruby/object:Gem::Requirement
78
+ required_ruby_version: !ruby/object:Gem::Requirement
94
79
  none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- segments:
99
- - 0
100
- version: "0"
101
- required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
85
  none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- segments:
107
- - 0
108
- version: "0"
86
+ requirements:
87
+ - - ! '>'
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.1
109
90
  requirements: []
110
-
111
91
  rubyforge_project:
112
- rubygems_version: 1.3.7
92
+ rubygems_version: 1.8.10
113
93
  signing_key:
114
94
  specification_version: 3
115
95
  summary: An event-driven IRC-framework for Ruby.
116
96
  test_files: []
117
-