zmb 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,63 +0,0 @@
1
- class Command
2
- attr_accessor :delegate, :signal, :help
3
-
4
- def initialize(delegate, signal, commands=1, help=nil)
5
- @delegate = delegate
6
- @signal = signal
7
- @help = help
8
- @commands = commands
9
- end
10
-
11
- def help?
12
- help != nil
13
- end
14
-
15
- def run(e, args)
16
- if @commands == 0 then
17
- args = Array.new
18
- elsif args.size > @commands
19
- a = args.first @commands-1 # Take one under amount of commands
20
- a << args[@commands-1..-1].join(' ')
21
- args = a
22
- end
23
-
24
- begin
25
- @delegate.send(@signal, e, *args)
26
- rescue ArgumentError
27
- 'incorrect arguments'
28
- rescue Exception
29
- if e.respond_to?('user') and e.user.respond_to?('admin?') and e.user.admin? and e.private? then
30
- "#{$!.message}\n#{$!.inspect}\n#{$!.backtrace[0..2].join("\n")}"
31
- else
32
- "command failed"
33
- end
34
- end
35
- end
36
- end
37
-
38
- class PermCommand < Command
39
- attr_accessor :perm
40
-
41
- def initialize(perm, *args)
42
- super(*args)
43
- @perm = perm
44
- end
45
-
46
- def run(e, args)
47
- if e.respond_to?('user') and e.user.permission?(@perm) then
48
- super(e, args)
49
- else
50
- 'permission denied'
51
- end
52
- end
53
- end
54
-
55
- class AuthCommand < Command
56
- def run(e, args)
57
- if e.respond_to?('user') and e.user.authenticated? then
58
- super(e, args)
59
- else
60
- 'permission denied'
61
- end
62
- end
63
- end