butler 1.8.2 → 1.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/bin/botcontrol +1 -1
- data/data/butler/dialogs/create_config.rb +2 -2
- data/data/butler/dialogs/quickcreate.rb +6 -4
- data/data/butler/dialogs/uninstall.rb +4 -3
- data/data/butler/plugins/core/access.rb +10 -10
- data/data/butler/plugins/dev/bleakhouse.rb +19 -8
- data/data/butler/plugins/operator/deop.rb +10 -1
- data/data/butler/plugins/operator/devoice.rb +9 -0
- data/data/butler/plugins/operator/limit.rb +12 -0
- data/data/butler/plugins/operator/op.rb +9 -0
- data/data/butler/plugins/operator/voice.rb +10 -0
- data/data/butler/plugins/util/calculator.rb +11 -0
- data/data/butler/services/org.rubyforge.butler/calculator/1/calculator.rb +68 -0
- data/data/butler/services/org.rubyforge.butler/log/1/service.rb +198 -0
- data/data/butler/services/org.rubyforge.butler/strings/1/data/en/acknowledge.yaml +8 -0
- data/data/butler/services/org.rubyforge.butler/strings/1/data/en/gratitude.yaml +3 -0
- data/data/butler/services/org.rubyforge.butler/strings/1/data/en/hello.yaml +6 -0
- data/data/butler/services/org.rubyforge.butler/strings/1/data/en/ignorance.yaml +7 -0
- data/data/butler/services/org.rubyforge.butler/strings/1/data/en/ignorance_about.yaml +3 -0
- data/data/butler/services/org.rubyforge.butler/strings/1/data/en/insult.yaml +3 -0
- data/data/butler/services/org.rubyforge.butler/strings/1/data/en/rejection.yaml +12 -0
- data/data/butler/services/org.rubyforge.butler/strings/1/service.rb +50 -0
- data/lib/access.rb +6 -3
- data/lib/access/privilege.rb +9 -78
- data/lib/access/privilegelist.rb +75 -0
- data/lib/access/role.rb +14 -94
- data/lib/access/role/base.rb +40 -0
- data/lib/access/rolelist.rb +99 -0
- data/lib/access/savable.rb +6 -3
- data/lib/access/user.rb +21 -19
- data/lib/access/version.rb +17 -0
- data/lib/access/yamlbase.rb +64 -48
- data/lib/butler.rb +1 -0
- data/lib/butler/bot.rb +8 -2
- data/lib/butler/control.rb +3 -1
- data/lib/butler/initialvalues.rb +1 -1
- data/lib/butler/irc/client.rb +6 -0
- data/lib/butler/irc/message.rb +14 -9
- data/lib/butler/irc/parser.rb +8 -5
- data/lib/butler/irc/parser/generic.rb +33 -1
- data/lib/butler/irc/parser/rfc2812.rb +5 -2
- data/lib/butler/plugin.rb +22 -2
- data/lib/butler/plugins.rb +2 -7
- data/lib/butler/service.rb +73 -0
- data/lib/butler/services.rb +65 -0
- data/lib/butler/version.rb +1 -1
- data/lib/ruby/array/random.rb +17 -0
- data/lib/ruby/string/camelcase.rb +14 -0
- data/test/test_access.rb +164 -59
- data/test/test_access/privilege/banners.statistics.yaml +3 -0
- data/test/test_access/privilege/banners.yaml +3 -0
- data/test/test_access/privilege/news.create.yaml +3 -0
- data/test/test_access/privilege/news.delete.yaml +3 -0
- data/test/test_access/privilege/news.edit.yaml +3 -0
- data/test/test_access/privilege/news.read.yaml +3 -0
- data/test/test_access/privilege/news.yaml +3 -0
- data/test/test_access/privilege/paid_content.yaml +3 -0
- data/test/test_access/privilege/statistics.ftp.yaml +3 -0
- data/test/test_access/privilege/statistics.web.yaml +3 -0
- data/test/test_access/privilege/statistics.yaml +3 -0
- data/test/test_access/role/chiefeditor.yaml +7 -0
- data/test/test_access/role/editor.yaml +9 -0
- data/test/test_access/user/test.yaml +12 -0
- metadata +51 -5
- data/data/butler/plugins/core/user.rb +0 -166
- data/data/butler/plugins/dev/onhandlers.rb +0 -93
- data/data/butler/plugins/service/log.rb +0 -183
@@ -0,0 +1,12 @@
|
|
1
|
+
---
|
2
|
+
- "Nope"
|
3
|
+
- "Sorry, I won't do that"
|
4
|
+
- "That won't work"
|
5
|
+
- "And how could that be done?"
|
6
|
+
- "No Sir"
|
7
|
+
- "No way I'd do that"
|
8
|
+
- "Aw come on, why should I do that?"
|
9
|
+
- "Never, read me, NEVER!"
|
10
|
+
- "Dude, what the heck makes you think that's my job?"
|
11
|
+
- "Go, bother someone else with that boring task."
|
12
|
+
- "Naaa, I don't want to."
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2007 by Stefan Rusterholz.
|
3
|
+
# All rights reserved.
|
4
|
+
# See LICENSE.txt for permissions.
|
5
|
+
#++
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
require 'ruby/array/random'
|
10
|
+
require 'templater'
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
class Strings
|
15
|
+
def initialize(dir)
|
16
|
+
@dir = dir
|
17
|
+
rescan
|
18
|
+
end
|
19
|
+
|
20
|
+
def rescan
|
21
|
+
strings = Hash.new { |h,k|
|
22
|
+
raise ArgumentError, "No such string key #{k}"
|
23
|
+
}
|
24
|
+
Dir.glob(@dir+'/*') { |dir|
|
25
|
+
language = dir[/[^\/]+$/]
|
26
|
+
Dir.glob(dir+'/*.yaml') { |file|
|
27
|
+
resort = file.sub(%r{.*/([^/]+).yaml$}, '\1')
|
28
|
+
strings[resort] = {} unless strings.has_key?(resort)
|
29
|
+
strings[resort][language] = YAML.load_file(file).map { |string|
|
30
|
+
Templater.new(string)
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
@strings = strings
|
35
|
+
end
|
36
|
+
|
37
|
+
def [](resort, language='en', variables={})
|
38
|
+
resort = @strings[resort.to_s]
|
39
|
+
string = (resort[language] || resort["en"])
|
40
|
+
string.random.result(variables)
|
41
|
+
end
|
42
|
+
|
43
|
+
def answer(message, resort, variables={})
|
44
|
+
message.answer(self[resort, message.language, variables])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.on_load
|
49
|
+
register(Strings.new(@path.base+'/data'))
|
50
|
+
end
|
data/lib/access.rb
CHANGED
@@ -10,7 +10,10 @@ require 'digest/md5'
|
|
10
10
|
require 'access/yamlbase'
|
11
11
|
require 'access/user'
|
12
12
|
require 'access/role'
|
13
|
+
require 'access/role/base'
|
14
|
+
require 'access/rolelist'
|
13
15
|
require 'access/privilege'
|
16
|
+
require 'access/privilegelist'
|
14
17
|
|
15
18
|
|
16
19
|
|
@@ -28,9 +31,9 @@ class Access
|
|
28
31
|
#
|
29
32
|
# =Synopsis
|
30
33
|
# access = Access.new(
|
31
|
-
# Access::YAMLBase.new(Access::User::Base, "./access/user"),
|
32
|
-
# Access::YAMLBase.new(Access::Role::Base, "./access/role"),
|
33
|
-
# Access::YAMLBase.new(Access::Privilege::Base, "./access/privilege")
|
34
|
+
# Access::YAMLBase.new(Access::User::Base, "./access/user"), # second arg is optional
|
35
|
+
# Access::YAMLBase.new(Access::Role::Base, "./access/role"), # second arg is optional
|
36
|
+
# Access::YAMLBase.new(Access::Privilege::Base, "./access/privilege") # second arg is optional
|
34
37
|
# )
|
35
38
|
# %w(news news/create news/edit news/delete).each { |privilege|
|
36
39
|
# access.privilege.create(privilege, "...description...")
|
data/lib/access/privilege.rb
CHANGED
@@ -7,7 +7,6 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
require 'access'
|
10
|
-
require 'access/savable'
|
11
10
|
|
12
11
|
|
13
12
|
|
@@ -29,111 +28,43 @@ class Access
|
|
29
28
|
# Restore an Access::Privilege from it's storable data
|
30
29
|
def load(*args) # :nodoc:
|
31
30
|
return nil unless data = super
|
32
|
-
privilege = new(*data.values_at(:
|
31
|
+
privilege = new(*data.values_at(:oid, :description))
|
33
32
|
privilege.access = access
|
34
33
|
privilege.base = self
|
35
34
|
privilege
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
|
-
attr_reader :
|
38
|
+
attr_reader :oid
|
40
39
|
attr_reader :description
|
41
40
|
|
42
41
|
def initialize(privilege, description=nil)
|
43
|
-
@
|
42
|
+
@oid = privilege
|
44
43
|
@description = description || "No description"
|
45
44
|
end
|
46
45
|
|
47
46
|
def storable
|
48
47
|
{
|
49
|
-
:
|
48
|
+
:oid => @oid,
|
50
49
|
:description => @description,
|
51
50
|
}
|
52
51
|
end
|
53
52
|
|
54
53
|
def eql?(other)
|
55
|
-
self.class == other.class && @
|
54
|
+
self.class == other.class && @oid.eql?(other.oid)
|
56
55
|
end
|
57
56
|
|
58
57
|
def hash
|
59
|
-
@
|
58
|
+
@oid.hash
|
60
59
|
end
|
61
60
|
|
62
61
|
def inspect # :nodoc:
|
63
|
-
"#<%s:0x%08x
|
62
|
+
"#<%s:0x%08x oid=%s description=%s>" % [
|
64
63
|
self.class,
|
65
64
|
object_id << 1,
|
66
|
-
@
|
65
|
+
@oid,
|
67
66
|
@description
|
68
67
|
]
|
69
68
|
end
|
70
69
|
end
|
71
|
-
|
72
|
-
class Privileges
|
73
|
-
include Enumerable
|
74
|
-
|
75
|
-
def initialize(owner, privileges=nil)
|
76
|
-
@owner = owner
|
77
|
-
@privileges = Hash.new { |h,k| h[k] = [] }.merge(privileges || {})
|
78
|
-
end
|
79
|
-
|
80
|
-
def storable
|
81
|
-
@privileges
|
82
|
-
end
|
83
|
-
|
84
|
-
def allow?(privilege, condition=nil)
|
85
|
-
walk(privilege) { |priv|
|
86
|
-
@privileges.has_key?(priv)
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
|
-
def add(privilege)
|
91
|
-
case privilege
|
92
|
-
when Array: privilege.each { |priv| @privileges[priv] = nil }
|
93
|
-
when Hash: privilege.each { |priv, cond| @privileges[priv] << cond }
|
94
|
-
else @privileges[privilege] = nil
|
95
|
-
end
|
96
|
-
@owner.save
|
97
|
-
end
|
98
|
-
|
99
|
-
def delete(privilege)
|
100
|
-
case privilege
|
101
|
-
when Array
|
102
|
-
privilege.each { |priv| @privileges.delete(priv) }
|
103
|
-
when Hash
|
104
|
-
privilege.each { |priv, cond|
|
105
|
-
@privileges[priv].delete(cond)
|
106
|
-
@privileges.delete(priv) if @privileges[priv].empty?
|
107
|
-
}
|
108
|
-
else
|
109
|
-
@privileges.delete(priv)
|
110
|
-
end
|
111
|
-
@owner.save
|
112
|
-
end
|
113
|
-
|
114
|
-
def list
|
115
|
-
@privileges
|
116
|
-
end
|
117
|
-
|
118
|
-
def each(&block)
|
119
|
-
@privileges.each(&block)
|
120
|
-
end
|
121
|
-
|
122
|
-
def walk(priv)
|
123
|
-
until priv.empty?
|
124
|
-
return true if yield(priv)
|
125
|
-
priv = priv.gsub(%r{(?:/|^)[^/]*$}, '')
|
126
|
-
end
|
127
|
-
return true if yield("")
|
128
|
-
false
|
129
|
-
end
|
130
|
-
|
131
|
-
def inspect # :nodoc:
|
132
|
-
"#<%s:0x%08x %s>" % [
|
133
|
-
self.class,
|
134
|
-
object_id << 1,
|
135
|
-
@privileges.keys.join(', ')
|
136
|
-
]
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
70
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2007 by Stefan Rusterholz.
|
3
|
+
# All rights reserved.
|
4
|
+
# See LICENSE.txt for permissions.
|
5
|
+
#++
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
require 'access'
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
class Access
|
14
|
+
class PrivilegeList
|
15
|
+
include Enumerable
|
16
|
+
|
17
|
+
def initialize(owner, privileges=nil)
|
18
|
+
@owner = owner
|
19
|
+
@privileges = Hash.new { |h,k| h[k] = [] }.merge(privileges || {})
|
20
|
+
end
|
21
|
+
|
22
|
+
def storable
|
23
|
+
@privileges
|
24
|
+
end
|
25
|
+
|
26
|
+
def allow?(privilege, condition=nil)
|
27
|
+
walk(privilege) { |priv|
|
28
|
+
@privileges.has_key?(priv)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_oid(privilege)
|
33
|
+
case privilege
|
34
|
+
when Array: privilege.each { |priv| @privileges[priv] = nil }
|
35
|
+
when Hash: privilege.each { |priv, cond| @privileges[priv] << cond }
|
36
|
+
else @privileges[privilege] = nil
|
37
|
+
end
|
38
|
+
@owner.save
|
39
|
+
end
|
40
|
+
|
41
|
+
def remove_oid(priv_oid)
|
42
|
+
@privileges.delete(priv_oid)
|
43
|
+
@owner.save
|
44
|
+
end
|
45
|
+
|
46
|
+
def remove(priv)
|
47
|
+
remove_oid(priv.oid)
|
48
|
+
end
|
49
|
+
|
50
|
+
def list
|
51
|
+
@privileges
|
52
|
+
end
|
53
|
+
|
54
|
+
def each(&block)
|
55
|
+
@privileges.each(&block)
|
56
|
+
end
|
57
|
+
|
58
|
+
def walk(priv)
|
59
|
+
until priv.empty?
|
60
|
+
return true if yield(priv)
|
61
|
+
priv = priv.gsub(%r{(?:/|^)[^/]*$}, '')
|
62
|
+
end
|
63
|
+
return true if yield("")
|
64
|
+
false
|
65
|
+
end
|
66
|
+
|
67
|
+
def inspect # :nodoc:
|
68
|
+
"#<%s:0x%08x %s>" % [
|
69
|
+
self.class,
|
70
|
+
object_id << 1,
|
71
|
+
@privileges.keys.join(', ')
|
72
|
+
]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/access/role.rb
CHANGED
@@ -6,6 +6,10 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
require 'access'
|
10
|
+
|
11
|
+
|
12
|
+
|
9
13
|
class Access
|
10
14
|
|
11
15
|
# Access::Role's are a set of privileges with (optionally)
|
@@ -14,38 +18,8 @@ class Access
|
|
14
18
|
class Role
|
15
19
|
include Savable
|
16
20
|
|
17
|
-
# The
|
18
|
-
|
19
|
-
|
20
|
-
# Create a new Role
|
21
|
-
# role is a role-id, should be \w+
|
22
|
-
# description is a piece of text describing the role
|
23
|
-
# privileges are the privileges the role provides
|
24
|
-
def create(role, description=nil, privileges=[])
|
25
|
-
raise "Role #{role} already exists" if exists?(role)
|
26
|
-
role = Role.new(role, description)
|
27
|
-
role.access = access
|
28
|
-
role.base = self
|
29
|
-
add(role)
|
30
|
-
role
|
31
|
-
end
|
32
|
-
|
33
|
-
# Restore an Access::Privilege from it's storable data
|
34
|
-
def load(*args) # :nodoc:
|
35
|
-
return nil unless data = super
|
36
|
-
roles = access.role
|
37
|
-
data[:roles] = data[:roles].map { |role| roles[role] }
|
38
|
-
array = data.values_at(:id, :description)
|
39
|
-
array << data
|
40
|
-
role = Role.new(*array)
|
41
|
-
role.access = access
|
42
|
-
role.base = self
|
43
|
-
role
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# The record-id
|
48
|
-
attr_reader :id
|
21
|
+
# The record-oid
|
22
|
+
attr_reader :oid
|
49
23
|
|
50
24
|
# The description of the role
|
51
25
|
attr_reader :description
|
@@ -57,13 +31,13 @@ class Access
|
|
57
31
|
attr_reader :privileges
|
58
32
|
|
59
33
|
# Create a new Role
|
60
|
-
# role is a role-
|
34
|
+
# role is a role-oid, should be \w+
|
61
35
|
# description is a piece of text describing the role
|
62
36
|
# other: a hash that accepts the keys :privileges and :roles
|
63
37
|
def initialize(role, description=nil, other={})
|
64
|
-
@
|
65
|
-
@privileges =
|
66
|
-
@roles =
|
38
|
+
@oid = role
|
39
|
+
@privileges = PrivilegeList.new(self, other[:privileges])
|
40
|
+
@roles = RoleList.new(self, other[:roles])
|
67
41
|
@description = (description || "No description").freeze
|
68
42
|
end
|
69
43
|
|
@@ -77,7 +51,7 @@ class Access
|
|
77
51
|
# serialize to column => value for storage
|
78
52
|
def storable
|
79
53
|
{
|
80
|
-
:
|
54
|
+
:oid => @oid,
|
81
55
|
:description => @description,
|
82
56
|
:privileges => @privileges.storable,
|
83
57
|
:roles => @roles.storable,
|
@@ -93,12 +67,12 @@ class Access
|
|
93
67
|
|
94
68
|
# :nodoc:
|
95
69
|
def eql?(other)
|
96
|
-
self.class == other.class && @
|
70
|
+
self.class == other.class && @oid.eql?(other.oid)
|
97
71
|
end
|
98
72
|
|
99
73
|
# :nodoc:
|
100
74
|
def hash
|
101
|
-
@
|
75
|
+
@oid.hash
|
102
76
|
end
|
103
77
|
|
104
78
|
def inspect # :nodoc:
|
@@ -111,58 +85,4 @@ class Access
|
|
111
85
|
]
|
112
86
|
end
|
113
87
|
end
|
114
|
-
|
115
|
-
# A list of roles
|
116
|
-
class Roles
|
117
|
-
include Enumerable
|
118
|
-
|
119
|
-
# owner must be capable of #save
|
120
|
-
# roles is the list of Role instances (array)
|
121
|
-
def initialize(owner, roles=nil)
|
122
|
-
@owner = owner
|
123
|
-
@roles = roles || []
|
124
|
-
end
|
125
|
-
|
126
|
-
# Tests if any of the roles in self allows a privilege under
|
127
|
-
# given conditions (may be nil to indicate no condition)
|
128
|
-
def allow?(privilege, condition=nil)
|
129
|
-
@roles.any? { |role| role.allows?(privilege, condition) }
|
130
|
-
end
|
131
|
-
|
132
|
-
# add a role (Role instance)
|
133
|
-
def add(role)
|
134
|
-
@roles << role
|
135
|
-
@owner.save
|
136
|
-
end
|
137
|
-
|
138
|
-
# delete a role (Role instance)
|
139
|
-
def delete(role)
|
140
|
-
@roles.delete(role)
|
141
|
-
@owner.save
|
142
|
-
end
|
143
|
-
|
144
|
-
# all roles
|
145
|
-
def list
|
146
|
-
@roles.dup
|
147
|
-
end
|
148
|
-
|
149
|
-
# Iterate over the roles
|
150
|
-
def each(&block)
|
151
|
-
@roles.each(&block)
|
152
|
-
end
|
153
|
-
|
154
|
-
# :nodoc:
|
155
|
-
# prepare for storage
|
156
|
-
def storable
|
157
|
-
@roles.map { |role| role.id }
|
158
|
-
end
|
159
|
-
|
160
|
-
def inspect # :nodoc:
|
161
|
-
"#<%s:0x%08x roles=%s>" % [
|
162
|
-
self.class,
|
163
|
-
object_id << 1,
|
164
|
-
@roles.map { |r| r.id }.join(', '),
|
165
|
-
]
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
88
|
+
end
|