butler 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/CHANGELOG +4 -0
  2. data/GPL.txt +340 -0
  3. data/LICENSE.txt +52 -0
  4. data/README +37 -0
  5. data/Rakefile +334 -0
  6. data/bin/botcontrol +230 -0
  7. data/data/butler/config_template.yaml +4 -0
  8. data/data/butler/dialogs/backup.rb +19 -0
  9. data/data/butler/dialogs/botcontrol.rb +4 -0
  10. data/data/butler/dialogs/config.rb +1 -0
  11. data/data/butler/dialogs/create.rb +53 -0
  12. data/data/butler/dialogs/delete.rb +3 -0
  13. data/data/butler/dialogs/en/backup.yaml +6 -0
  14. data/data/butler/dialogs/en/botcontrol.yaml +5 -0
  15. data/data/butler/dialogs/en/create.yaml +11 -0
  16. data/data/butler/dialogs/en/delete.yaml +2 -0
  17. data/data/butler/dialogs/en/help.yaml +17 -0
  18. data/data/butler/dialogs/en/info.yaml +13 -0
  19. data/data/butler/dialogs/en/list.yaml +4 -0
  20. data/data/butler/dialogs/en/notyetimplemented.yaml +2 -0
  21. data/data/butler/dialogs/en/rename.yaml +3 -0
  22. data/data/butler/dialogs/en/start.yaml +3 -0
  23. data/data/butler/dialogs/en/sync_plugins.yaml +3 -0
  24. data/data/butler/dialogs/en/uninstall.yaml +5 -0
  25. data/data/butler/dialogs/en/unknown_command.yaml +2 -0
  26. data/data/butler/dialogs/help.rb +11 -0
  27. data/data/butler/dialogs/info.rb +27 -0
  28. data/data/butler/dialogs/interactive.rb +1 -0
  29. data/data/butler/dialogs/list.rb +10 -0
  30. data/data/butler/dialogs/notyetimplemented.rb +1 -0
  31. data/data/butler/dialogs/rename.rb +4 -0
  32. data/data/butler/dialogs/selectbot.rb +2 -0
  33. data/data/butler/dialogs/start.rb +5 -0
  34. data/data/butler/dialogs/sync_plugins.rb +30 -0
  35. data/data/butler/dialogs/uninstall.rb +17 -0
  36. data/data/butler/dialogs/unknown_command.rb +1 -0
  37. data/data/butler/plugins/core/logout.rb +41 -0
  38. data/data/butler/plugins/core/plugins.rb +134 -0
  39. data/data/butler/plugins/core/privilege.rb +103 -0
  40. data/data/butler/plugins/core/user.rb +166 -0
  41. data/data/butler/plugins/dev/eval.rb +64 -0
  42. data/data/butler/plugins/dev/nometa.rb +14 -0
  43. data/data/butler/plugins/dev/onhandlers.rb +93 -0
  44. data/data/butler/plugins/dev/raw.rb +36 -0
  45. data/data/butler/plugins/dev/rawlog.rb +77 -0
  46. data/data/butler/plugins/games/eightball.rb +54 -0
  47. data/data/butler/plugins/games/mastermind.rb +174 -0
  48. data/data/butler/plugins/irc/action.rb +36 -0
  49. data/data/butler/plugins/irc/join.rb +38 -0
  50. data/data/butler/plugins/irc/notice.rb +36 -0
  51. data/data/butler/plugins/irc/part.rb +38 -0
  52. data/data/butler/plugins/irc/privmsg.rb +36 -0
  53. data/data/butler/plugins/irc/quit.rb +36 -0
  54. data/data/butler/plugins/operator/deop.rb +41 -0
  55. data/data/butler/plugins/operator/devoice.rb +41 -0
  56. data/data/butler/plugins/operator/limit.rb +47 -0
  57. data/data/butler/plugins/operator/op.rb +41 -0
  58. data/data/butler/plugins/operator/voice.rb +41 -0
  59. data/data/butler/plugins/public/help.rb +69 -0
  60. data/data/butler/plugins/public/login.rb +72 -0
  61. data/data/butler/plugins/public/usage.rb +49 -0
  62. data/data/butler/plugins/service/clones.rb +56 -0
  63. data/data/butler/plugins/service/define.rb +47 -0
  64. data/data/butler/plugins/service/log.rb +183 -0
  65. data/data/butler/plugins/service/svn.rb +91 -0
  66. data/data/butler/plugins/util/cycle.rb +98 -0
  67. data/data/butler/plugins/util/load.rb +41 -0
  68. data/data/butler/plugins/util/pong.rb +29 -0
  69. data/data/butler/strings/random/acknowledge.en.yaml +5 -0
  70. data/data/butler/strings/random/gratitude.en.yaml +3 -0
  71. data/data/butler/strings/random/hello.en.yaml +4 -0
  72. data/data/butler/strings/random/ignorance.en.yaml +7 -0
  73. data/data/butler/strings/random/ignorance_about.en.yaml +3 -0
  74. data/data/butler/strings/random/insult.en.yaml +3 -0
  75. data/data/butler/strings/random/rejection.en.yaml +12 -0
  76. data/data/man/botcontrol.1 +17 -0
  77. data/lib/access.rb +187 -0
  78. data/lib/access/admin.rb +16 -0
  79. data/lib/access/privilege.rb +122 -0
  80. data/lib/access/role.rb +102 -0
  81. data/lib/access/savable.rb +18 -0
  82. data/lib/access/user.rb +180 -0
  83. data/lib/access/yamlbase.rb +126 -0
  84. data/lib/butler.rb +188 -0
  85. data/lib/butler/bot.rb +247 -0
  86. data/lib/butler/control.rb +93 -0
  87. data/lib/butler/dialog.rb +64 -0
  88. data/lib/butler/initialvalues.rb +40 -0
  89. data/lib/butler/irc/channel.rb +135 -0
  90. data/lib/butler/irc/channels.rb +96 -0
  91. data/lib/butler/irc/client.rb +351 -0
  92. data/lib/butler/irc/hostmask.rb +53 -0
  93. data/lib/butler/irc/message.rb +184 -0
  94. data/lib/butler/irc/parser.rb +125 -0
  95. data/lib/butler/irc/parser/commands.rb +83 -0
  96. data/lib/butler/irc/parser/generic.rb +343 -0
  97. data/lib/butler/irc/socket.rb +378 -0
  98. data/lib/butler/irc/string.rb +186 -0
  99. data/lib/butler/irc/topic.rb +15 -0
  100. data/lib/butler/irc/user.rb +265 -0
  101. data/lib/butler/irc/users.rb +112 -0
  102. data/lib/butler/plugin.rb +249 -0
  103. data/lib/butler/plugin/configproxy.rb +35 -0
  104. data/lib/butler/plugin/mapper.rb +85 -0
  105. data/lib/butler/plugin/matcher.rb +55 -0
  106. data/lib/butler/plugin/onhandlers.rb +70 -0
  107. data/lib/butler/plugin/trigger.rb +58 -0
  108. data/lib/butler/plugins.rb +147 -0
  109. data/lib/butler/version.rb +17 -0
  110. data/lib/cloptions.rb +217 -0
  111. data/lib/cloptions/adapters.rb +24 -0
  112. data/lib/cloptions/switch.rb +132 -0
  113. data/lib/configuration.rb +223 -0
  114. data/lib/dialogline.rb +296 -0
  115. data/lib/dialogline/localizations.rb +24 -0
  116. data/lib/durations.rb +57 -0
  117. data/lib/event.rb +295 -0
  118. data/lib/event/at.rb +64 -0
  119. data/lib/event/every.rb +56 -0
  120. data/lib/event/timed.rb +112 -0
  121. data/lib/installer.rb +75 -0
  122. data/lib/iterator.rb +34 -0
  123. data/lib/log.rb +68 -0
  124. data/lib/log/comfort.rb +85 -0
  125. data/lib/log/converter.rb +23 -0
  126. data/lib/log/entry.rb +152 -0
  127. data/lib/log/fakeio.rb +55 -0
  128. data/lib/log/file.rb +54 -0
  129. data/lib/log/filereader.rb +81 -0
  130. data/lib/log/forward.rb +49 -0
  131. data/lib/log/methods.rb +39 -0
  132. data/lib/log/nolog.rb +18 -0
  133. data/lib/log/splitter.rb +26 -0
  134. data/lib/ostructfixed.rb +26 -0
  135. data/lib/ruby/array/columnize.rb +38 -0
  136. data/lib/ruby/dir/mktree.rb +28 -0
  137. data/lib/ruby/enumerable/join.rb +13 -0
  138. data/lib/ruby/exception/detailed.rb +24 -0
  139. data/lib/ruby/file/append.rb +11 -0
  140. data/lib/ruby/file/write.rb +11 -0
  141. data/lib/ruby/hash/zip.rb +15 -0
  142. data/lib/ruby/kernel/bench.rb +15 -0
  143. data/lib/ruby/kernel/daemonize.rb +42 -0
  144. data/lib/ruby/kernel/non_verbose.rb +17 -0
  145. data/lib/ruby/kernel/safe_fork.rb +18 -0
  146. data/lib/ruby/range/stepped.rb +11 -0
  147. data/lib/ruby/string/arguments.rb +72 -0
  148. data/lib/ruby/string/chunks.rb +15 -0
  149. data/lib/ruby/string/post_arguments.rb +44 -0
  150. data/lib/ruby/string/unescaped.rb +17 -0
  151. data/lib/scheduler.rb +164 -0
  152. data/lib/scriptfile.rb +101 -0
  153. data/lib/templater.rb +86 -0
  154. data/test/cloptions.rb +134 -0
  155. data/test/cv.rb +28 -0
  156. data/test/irc/client.rb +85 -0
  157. data/test/irc/client_login.txt +53 -0
  158. data/test/irc/client_subscribe.txt +8 -0
  159. data/test/irc/message.rb +30 -0
  160. data/test/irc/messages.txt +64 -0
  161. data/test/irc/parser.rb +13 -0
  162. data/test/irc/profile_parser.rb +12 -0
  163. data/test/irc/users.rb +28 -0
  164. metadata +256 -0
@@ -0,0 +1 @@
1
+ response(:context, "notyetimplemented", :feature => "Interactive Mode")
@@ -0,0 +1,10 @@
1
+ user_config = variables.botcontrol.user_config(variables.user)
2
+ bot_list = Butler.list(user_config)
3
+ if bot_list.empty? then
4
+ say(:nobots)
5
+ else
6
+ say(:bots, :bot_count => bot_list.size)
7
+ bot_list.each { |bot|
8
+ say(:abot, :bot => bot)
9
+ }
10
+ end
@@ -0,0 +1 @@
1
+ say(:notyetimplemented)
@@ -0,0 +1,4 @@
1
+ old_name = variables.botname || context("selectbot")[:botname]
2
+ new_name = variables.newname || ask(:new_name, nil, String, :matching => /\A[A-Za-z0-9_]+\z/)
3
+ Butler.rename(nil, old_name, new_name)
4
+ say(:renamed, :old_name => old_name, :new_name => new_name)
@@ -0,0 +1,2 @@
1
+ # FIXME implement the question
2
+ response(:option, :botname, :value)
@@ -0,0 +1,5 @@
1
+ if Process.euid.zero? then
2
+ say(:discourage)
3
+ sleep(10)
4
+ end
5
+ store(:botname, variables.botname || context("selectbot")[:botname])
@@ -0,0 +1,30 @@
1
+ bots = variables.botname ? [variables.botname] : Butler.list(variables.path)
2
+ bots_path = variables.path.bots
3
+ dirlist = Dir[variables.path.plugin_repository+"/**/*"]
4
+ dirs, plugins = dirlist.partition { |filepath| File.directory?(filepath) }
5
+ slice = (variables.path.plugin_repository.length+1)..-1
6
+ dirs.map! { |dir| dir[slice] }
7
+ plugins.map! { |plugin| [plugin, plugin[slice], File.mtime(plugin)] }
8
+
9
+ bots.each { |name|
10
+ say(:updating, :name => name)
11
+ bot_path = "#{bots_path}/#{name}"
12
+ FileUtils.mkdir_p(dirs.map { |dir| "#{bot_path}/plugins/#{dir}" }, :mode => 0755)
13
+ plugins.each { |from, to, mtime|
14
+ full_to = "#{bot_path}/plugins/#{to}"
15
+ if File.exist?(full_to) then
16
+ if mtime > File.mtime(full_to) then
17
+ next unless prompt(:override_newer, true,
18
+ :name => to,
19
+ :a => File.mtime(full_to),
20
+ :b => mtime
21
+ )
22
+ end
23
+ #puts("Deleting #{full_to}")
24
+ File.delete(full_to)
25
+ end
26
+ #puts("Copying #{from} to #{full_to}")
27
+ FileUtils.cp(from, "#{full_to}")
28
+ }
29
+ }
30
+
@@ -0,0 +1,17 @@
1
+ unless ENV["SUDO_USER"]
2
+ say(:must_run_as_sudo)
3
+ else
4
+ variables.config.users.sort.each { |user, conf|
5
+ if prompt(:uninstall_user, false, :name => user) then
6
+ FileUtils.rm_r(conf[:bots])
7
+ FileUtils.rm_r(conf[:run])
8
+ end
9
+ }
10
+ if Butler::IsGem then
11
+ say(:run_gem_uninstall)
12
+ else
13
+ say(:uninstalling_botcontrol)
14
+ File.delete($0)
15
+ File.delete(variables.path.config)
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ say(:unknown)
@@ -0,0 +1,41 @@
1
+ #--
2
+ # Copyright 2007 by Stefan Rusterholz.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+
8
+
9
+ trigger "logout"
10
+
11
+ def on_trigger
12
+ if @butler.access.default_user == @message.from.access then
13
+ answer(:not_logged_in)
14
+ else
15
+ @message.from.access = @butler.access.default_user
16
+ answer(:success)
17
+ end
18
+ end
19
+
20
+ __END__
21
+ ---
22
+ :revision:
23
+ :plugin: 1
24
+ :summary:
25
+ en: "Log out from the bot"
26
+ :about:
27
+ :mail: "apeiros@gmx.net"
28
+ :version: "1.0.0"
29
+ :author: "Stefan Rusterholz"
30
+ :strings:
31
+ :success:
32
+ en: "You are now logged out."
33
+ :not_logged_in:
34
+ en: "You are not logged in, can't log you out."
35
+ :usage:
36
+ en: "![b]logout![o]"
37
+ :help:
38
+ en:
39
+ "": |
40
+ Using 'logout' you can log out from the bot.
41
+ Use it in order to prevent other people from abusing your account while you are not on your computer.
@@ -0,0 +1,134 @@
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/columnize'
10
+
11
+ #trigger "plugins"
12
+
13
+ def on_load_plugin(param)
14
+ if plugin_name = @butler.plugins.identify(param.plugin_name) then
15
+ begin
16
+ @butler.plugins.load(plugin_name)
17
+ answer(:load, :plugin_name => plugin_name)
18
+ rescue Exception => e
19
+ exception(e)
20
+ answer(:exception_load, :plugin_name => plugin_name, :exception => e)
21
+ end
22
+ else
23
+ answer(:unknown, :plugin_name => param.plugin_name)
24
+ end
25
+ end
26
+
27
+ def on_unload_plugin(param)
28
+ if plugin_name = @butler.plugins.identify(param.plugin_name) then
29
+ begin
30
+ @butler.plugins.unload(plugin_name)
31
+ answer(:unload, :plugin_name => plugin_name)
32
+ rescue Exception => e
33
+ exception(e)
34
+ answer(:exception_unload, :plugin => plugin_name, :exception => e)
35
+ end
36
+ else
37
+ answer(:unknown, :plugin_name => param.plugin_name)
38
+ end
39
+ end
40
+
41
+ def on_list_plugins(param)
42
+ return answer(usage) unless %w(active inactive all).include?(param.which)
43
+ plugins = @butler.plugins.send(param.which).sort.columnize(5)
44
+ answer(param.which.to_sym, :plugins => plugins)
45
+ end
46
+
47
+ # 37
48
+ def on_trigger
49
+ case @message.arguments[1]
50
+ when nil
51
+ answer(usage)
52
+
53
+ when "groups"
54
+ return answer(unknown(2)) if @message.arguments[2]
55
+ groups = @butler.plugins.groups.sort.columnize(5)
56
+ answer(:groups, :groups => groups)
57
+
58
+ when "names"
59
+ return answer(unknown(2)) if @message.arguments[2]
60
+ names = @butler.plugins.all.sort.columnize(5)
61
+ answer(:names, :names => names)
62
+
63
+ when "active"
64
+
65
+
66
+ else
67
+ unknown(1)
68
+ end
69
+ end
70
+
71
+ __END__
72
+ ---
73
+ :revision:
74
+ :plugin: 2
75
+ :summary:
76
+ en: Plugin management
77
+ :about:
78
+ :mail: "apeiros@gmx.net"
79
+ :version: "1.0.0"
80
+ :author: "Stefan Rusterholz"
81
+ :map:
82
+ :on_load_plugin:
83
+ en:
84
+ load plugin :plugin_name
85
+ :on_unload_plugin:
86
+ en:
87
+ unload plugin :plugin_name
88
+ :on_list_plugins:
89
+ en:
90
+ list :which plugins
91
+ :strings:
92
+ :groups:
93
+ en: |
94
+ Plugin-Groups:
95
+ <%= groups %>
96
+ :names:
97
+ en: |
98
+ Plugin-Names:
99
+ <%= groups %>
100
+ :active:
101
+ en: |
102
+ Active plugins:
103
+ <%= plugins %>
104
+ :inactive:
105
+ en: |
106
+ Inactive plugins:
107
+ <%= plugins %>
108
+ :all:
109
+ en: |
110
+ All plugins:
111
+ <%= plugins %>
112
+ :load:
113
+ en: Loaded '<%= plugin_name %>'.
114
+ :unload:
115
+ en: Unloaded '<%= plugin_name %>'.
116
+ :unknown:
117
+ en: Unknown plugin '<%= plugin_name %>'.
118
+ :exception_load:
119
+ en: |
120
+ An exception occured while loading '<%= plugin_name %>':
121
+ <%= exception %> in <%= exception.backtrace.first.sub(/.*?(lib|butler)/, '\1') %>
122
+ :exception_unload:
123
+ en: |
124
+ An exception occured while unloading '<%= plugin_name %>':
125
+ <%= exception %> in <%= exception.backtrace.first.sub(/.*?(lib|butler)/, '\1') %>
126
+
127
+ :usage:
128
+ en: |
129
+ 'load plugin' ![c(blue)]name![o]
130
+ 'unload plugin' ![c(blue)]name![o]
131
+ 'list' [![c(blue)]type![o]] 'plugins'
132
+ :help:
133
+ en:
134
+ "": "Plugins is responsible for loading, unloading and listing available plugins."
@@ -0,0 +1,103 @@
1
+ #--
2
+ # Copyright 2007 by Stefan Rusterholz.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+
8
+
9
+ trigger "privilege"
10
+
11
+ def on_trigger
12
+ case @message.arguments[1] && @message.arguments[1].downcase
13
+ when "create"
14
+ name, pass, active = @message.arguments[2,3]
15
+ active = active && !%(false off).include?(active.downcase)
16
+ return answer(usage) unless name and pass
17
+ if @butler.access.user.exists?(name) then
18
+ answer(:exists, :name => name)
19
+ else
20
+ @butler.access.user.create(name, pass, nil, false, :active => active)
21
+ answer(:created, :name => name)
22
+ end
23
+
24
+ when "delete"
25
+ return answer(usage) unless name = @message.arguments[2]
26
+ if @butler.access.user.exists?(name) then
27
+ @butler.access.user.delete(name)
28
+ answer(:deleted)
29
+ else
30
+ answer(:doesnt_exist, :name => name)
31
+ end
32
+
33
+ when "activate"
34
+ return answer(usage) unless name = @message.arguments[2]
35
+ if @butler.access.user.exists?(name) then
36
+ @butler.access.user[name].activate
37
+ answer(:activated)
38
+ else
39
+ answer(:doesnt_exist, :name => name)
40
+ end
41
+
42
+ when "deactivate"
43
+ return answer(usage) unless name = @message.arguments[2]
44
+ if @butler.access.user.exists?(name) then
45
+ @butler.access.user[name].deactivate
46
+ answer(:deactivated)
47
+ else
48
+ answer(:doesnt_exist, :name => name)
49
+ end
50
+
51
+ when "list"
52
+ answer(:users, :names => @butler.access.user.keys.columnize(5))
53
+
54
+ when "add"
55
+
56
+
57
+ when "remove"
58
+
59
+ else
60
+ answer(usage)
61
+
62
+ end
63
+ end
64
+
65
+ __END__
66
+ ---
67
+ :revision:
68
+ :plugin: 1
69
+ :summary:
70
+ en: "Manage your users."
71
+ :about:
72
+ :mail: "apeiros@gmx.net"
73
+ :version: "1.0.0"
74
+ :author: "Stefan Rusterholz"
75
+ :strings:
76
+ :users:
77
+ en: |
78
+ Users:
79
+ <%= names %>
80
+ :created:
81
+ en: |
82
+ Created user <%= name %>.
83
+ :deleted:
84
+ en: |
85
+ Deleted user <%= name %>.
86
+ :activated:
87
+ en: |
88
+ Activated user <%= name %>.
89
+ :deactivated:
90
+ en: |
91
+ Deactivated user <%= name %>.
92
+ :exists:
93
+ en: |
94
+ User <%= name %> exists already.
95
+ :doesnt_exist:
96
+ en: |
97
+ User <%= name %> does not exist.
98
+ :usage:
99
+ en: "![b]user![o] ('create' name password ['active' | 'inactive'] | ('delete' | 'activate' | 'deactivate') username | ('add' | 'remove') privilege)"
100
+ :help:
101
+ en:
102
+ "": |
103
+ Manage your users.
@@ -0,0 +1,166 @@
1
+ #--
2
+ # Copyright 2007 by Stefan Rusterholz.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+
8
+
9
+ trigger "user"
10
+
11
+ def on_trigger
12
+ case arguments(1)
13
+ when "create"
14
+ name, pass, active = @message.arguments[2,3]
15
+ active = active && !%(false off).include?(active.downcase)
16
+ return answer(usage) unless name and pass
17
+ if @butler.access.user.exists?(name) then
18
+ answer(:exists, :name => name)
19
+ else
20
+ @butler.access.user.create(name, pass, nil, false, :active => active)
21
+ answer(:created, :name => name)
22
+ end
23
+
24
+ when "delete"
25
+ return answer(usage) unless name = @message.arguments[2]
26
+ if @butler.access.user.exists?(name) then
27
+ @butler.access.user.delete(name)
28
+ answer(:deleted)
29
+ else
30
+ answer(:doesnt_exist, :name => name)
31
+ end
32
+
33
+ when "activate"
34
+ return answer(usage) unless name = @message.arguments[2]
35
+ if @butler.access.user.exists?(name) then
36
+ @butler.access.user[name].activate
37
+ answer(:activated)
38
+ else
39
+ answer(:doesnt_exist, :name => name)
40
+ end
41
+
42
+ when "deactivate"
43
+ return answer(usage) unless name = @message.arguments[2]
44
+ if @butler.access.user.exists?(name) then
45
+ @butler.access.user[name].deactivate
46
+ answer(:deactivated)
47
+ else
48
+ answer(:doesnt_exist, :name => name)
49
+ end
50
+
51
+ when "list"
52
+ answer(:users, :names => @butler.access.user.keys.columnize(5))
53
+
54
+ when "privileges"
55
+ return answer(usage) unless name = @message.arguments[2]
56
+ return answer(:doesnt_exist, :name => name) unless user = @butler.access.user[name]
57
+ answer(:privileges, :name => name, :privileges => user.privileges.list.keys.columnize(5))
58
+
59
+ when "roles"
60
+ return answer(usage) unless name = @message.arguments[2]
61
+ return answer(:doesnt_exist, :name => name) unless user = @butler.access.user[name]
62
+ answer(:roles, :name => name, :roles => user.roles.map { |r| r.id }.columnize(5))
63
+
64
+ when "add"
65
+ return answer(usage) unless name = @message.arguments[3] and @message.arguments[4]
66
+ return answer(:doesnt_exist, :name => name) unless user = @butler.access.user[name]
67
+ case arguments(2)
68
+ when "privilege"
69
+ user.privileges.add(@message.arguments[4])
70
+ answer(:added_privilege, :name => name, :privilege => @message.arguments[4])
71
+
72
+ when "role"
73
+ role_name = @message.arguments[4]
74
+ answer(:role_doesnt_exist, :role => role_name) unless role = @butler.access.role[role_name]
75
+ user.roles.add(role)
76
+ answer(:added_role, :name => name, :role => role_name)
77
+
78
+ else
79
+ answer(usage)
80
+
81
+ end
82
+
83
+ when "remove"
84
+ return answer(usage) unless name = @message.arguments[3] and @message.arguments[4]
85
+ return answer(:doesnt_exist, :name => name) unless user = @butler.access.user[name]
86
+ case arguments(2)
87
+ when "privilege"
88
+ user.privileges.remove(@message.arguments[4])
89
+ answer(:removed_privilege, :name => name, :privilege => @message.arguments[4])
90
+
91
+ when "role"
92
+ role_name = @message.arguments[4]
93
+ answer(:role_doesnt_exist, :role => role_name) unless role = @butler.access.role[role_name]
94
+ user.roles.remove(role)
95
+ answer(:removed_role, :name => name, :role => role_name)
96
+
97
+ else
98
+ answer(usage)
99
+
100
+ end
101
+
102
+ else
103
+ answer(usage)
104
+
105
+ end
106
+ end
107
+
108
+ __END__
109
+ ---
110
+ :revision:
111
+ :plugin: 1
112
+ :summary:
113
+ en: "Manage your users."
114
+ :about:
115
+ :mail: "apeiros@gmx.net"
116
+ :version: "1.0.0"
117
+ :author: "Stefan Rusterholz"
118
+ :strings:
119
+ :exists:
120
+ en: |
121
+ User <%= name %> exists already.
122
+ :doesnt_exist:
123
+ en: |
124
+ User <%= name %> does not exist.
125
+ :users:
126
+ en: |
127
+ Users:
128
+ <%= names %>
129
+ :privileges:
130
+ en: |
131
+ Privileges of <%= name %>:
132
+ <%= privileges %>
133
+ :roles:
134
+ en: |
135
+ Roles of <%= name %>:
136
+ <%= roles %>
137
+ :created:
138
+ en: |
139
+ Created user <%= name %>.
140
+ :deleted:
141
+ en: |
142
+ Deleted user <%= name %>.
143
+ :activated:
144
+ en: |
145
+ Activated user <%= name %>.
146
+ :deactivated:
147
+ en: |
148
+ Deactivated user <%= name %>.
149
+ :added_privilege:
150
+ en: |
151
+ Added privilege <%= privilege %> to <%= name %>.
152
+ :removed_privilege:
153
+ en: |
154
+ Removed privilege <%= privilege %> from <%= name %>.
155
+ :added_role:
156
+ en: |
157
+ Added role <%= role %> to <%= name %>.
158
+ :removed_role:
159
+ en: |
160
+ Removed role <%= role %> from <%= name %>.
161
+ :usage:
162
+ en: "![b]user![o] ('create' name password ['active' | 'inactive'] | ('delete' | 'activate' | 'deactivate') username | ('add' | 'remove') privilege)"
163
+ :help:
164
+ en:
165
+ "": |
166
+ Manage your users.