blur 1.5 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ require 'ostruct'
7
7
  Dir.glob("#{File.dirname __FILE__}/blur/**/*.rb").each &method(:require)
8
8
 
9
9
  module Blur
10
- class << Version = [1,5]
10
+ class << Version = [1,5,1]
11
11
  def to_s; join '.' end
12
12
  end
13
13
 
@@ -9,5 +9,9 @@ class Exception
9
9
  end
10
10
 
11
11
  class String
12
+ def numeric?
13
+ self =~ /^\d+$/
14
+ end
15
+
12
16
  alias_method :starts_with?, :start_with?
13
17
  end
@@ -150,6 +150,26 @@ module Blur
150
150
  end
151
151
  end
152
152
 
153
+ def got_mode network, command
154
+ name, modes, limit, nick, mask = command.params
155
+
156
+ if channel = network.channel_by_name(name)
157
+ if limit
158
+ unless limit.numeric?
159
+ nick = limit
160
+ end
161
+
162
+ if user = channel.user_by_nick(nick)
163
+ emit :user_mode, user, modes
164
+ user.merge_modes modes
165
+ end
166
+ else
167
+ emit :channel_mode, channel, modes
168
+ channel.merge_modes modes
169
+ end
170
+ end
171
+ end
172
+
153
173
  alias_method :got_422, :got_end_of_motd
154
174
  alias_method :got_376, :got_end_of_motd
155
175
  end
@@ -3,16 +3,32 @@
3
3
  module Blur
4
4
  class Network
5
5
  class Channel
6
- attr_accessor :name, :users, :topic, :network
6
+ attr_accessor :name, :users, :topic, :modes, :network
7
7
 
8
8
  def initialize name, network = nil, users = []
9
9
  @name = name
10
10
  @users = users
11
+ @modes = ""
11
12
  @network = network
12
13
 
13
14
  users.each { |user| user.channel = self }
14
15
  end
15
16
 
17
+ def merge_modes modes
18
+ addition = true
19
+
20
+ modes.each_char do |char|
21
+ case char
22
+ when ?+
23
+ addition = true
24
+ when ?-
25
+ addition = false
26
+ else
27
+ addition ? @modes.concat(char) : @modes.delete!(char)
28
+ end
29
+ end
30
+ end
31
+
16
32
  def say message
17
33
  @network.say self, message
18
34
  end
@@ -30,4 +46,4 @@ module Blur
30
46
  end
31
47
  end
32
48
  end
33
- end
49
+ end
@@ -3,10 +3,41 @@
3
3
  module Blur
4
4
  class Network
5
5
  class User
6
- attr_accessor :nick, :name, :host, :channel
7
-
6
+ attr_accessor :nick, :name, :host, :modes, :channel
7
+
8
+ def self.map_mode name, character
9
+ define_method(:"#{name}?") { @modes.include? character.to_s }
10
+ end
11
+
12
+ map_mode :admin, :a
13
+ map_mode :voice, :v
14
+ map_mode :owner, :q
15
+ map_mode :operator, :o
16
+ map_mode :half_operator, :h
17
+
8
18
  def initialize nick
9
- @nick = nick.sub /^[@|~|\+|%|&]/, ''
19
+ @nick = nick
20
+ @modes = ""
21
+
22
+ if modes = prefix_to_mode(nick[0])
23
+ @nick = nick[1..-1]
24
+ @modes = modes
25
+ end
26
+ end
27
+
28
+ def merge_modes modes
29
+ addition = true
30
+
31
+ modes.each_char do |char|
32
+ case char
33
+ when ?+
34
+ addition = true
35
+ when ?-
36
+ addition = false
37
+ else
38
+ addition ? @modes.concat(char) : @modes.delete!(char)
39
+ end
40
+ end
10
41
  end
11
42
 
12
43
  def say message
@@ -20,6 +51,18 @@ module Blur
20
51
  def to_s
21
52
  @nick
22
53
  end
54
+
55
+ private
56
+
57
+ def prefix_to_mode prefix
58
+ case prefix
59
+ when '@' then 'o'
60
+ when '+' then 'v'
61
+ when '%' then 'h'
62
+ when '&' then 'a'
63
+ when '~' then 'q'
64
+ end
65
+ end
23
66
  end
24
67
  end
25
- end
68
+ end
@@ -32,6 +32,10 @@ module Blur
32
32
 
33
33
  __send__ :unloaded if respond_to? :unloaded
34
34
  end
35
+
36
+ def script name
37
+ @client.scripts.find { |script| script.name == name }
38
+ end
35
39
 
36
40
  def cache
37
41
  @cache ||= Cache.new self
@@ -44,11 +48,10 @@ module Blur
44
48
  private
45
49
 
46
50
  def evaluate
47
- if module_eval File.read(@path), File.basename(@path), 0
48
- @evaluated = true
49
- end
51
+ module_eval File.read(@path), File.basename(@path), 0
52
+ @evaluated = true
50
53
  rescue Exception => exception
51
54
  puts "\e[1m#{File.basename @path}:#{exception.line}: \e[31merror:\e[39m #{exception.message}\e[0m"
52
55
  end
53
56
  end
54
- end
57
+ end
metadata CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 5
8
- version: "1.5"
8
+ - 1
9
+ version: 1.5.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-18 00:00:00 +01:00
17
+ date: 2011-01-21 00:00:00 +01:00
17
18
  default_executable:
18
19
  dependencies: []
19
20
 
@@ -26,18 +27,18 @@ extensions: []
26
27
  extra_rdoc_files: []
27
28
 
28
29
  files:
30
+ - library/blur.rb
29
31
  - library/blur/client.rb
30
32
  - library/blur/enhancements.rb
31
33
  - library/blur/handling.rb
34
+ - library/blur/network.rb
32
35
  - library/blur/network/channel.rb
33
36
  - library/blur/network/command.rb
34
37
  - library/blur/network/connection.rb
35
38
  - library/blur/network/user.rb
36
- - library/blur/network.rb
39
+ - library/blur/script.rb
37
40
  - library/blur/script/cache.rb
38
41
  - library/blur/script/messageparsing.rb
39
- - library/blur/script.rb
40
- - library/blur.rb
41
42
  has_rdoc: true
42
43
  homepage:
43
44
  licenses: []