]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/script.rb
quiz: stop quizzes and timers on cleanup
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / script.rb
index 16f39648d0ebf48acb27d3d4c63ac9b2bfbe913e..0923dd5dc15eeb59c40e770d15008c4fa241e7db 100644 (file)
@@ -11,7 +11,7 @@
 #
 # Scripts are little Ruby programs that run in the context of the script
 # plugin. You can create them directly in an IRC channel, and invoke them just
-# like normal rbot plugins. 
+# like normal rbot plugins.
 
 define_structure :Command, :code, :nick, :created, :channel
 
@@ -21,7 +21,7 @@ class ScriptPlugin < Plugin
     super
     if @registry.has_key?(:commands)
       @commands = @registry[:commands]
-      raise unless @commands
+      raise LoadError, "corrupted script database" unless @commands
     else
       @commands = Hash.new
     end
@@ -34,10 +34,15 @@ class ScriptPlugin < Plugin
 
 
   def help( plugin, topic="" )
-    if topic == "add"
+    case topic
+    when "add"
       "Scripts are little Ruby programs that run in the context of the script plugin. You can access @bot (class Irc::Bot), m (class Irc::PrivMessage), user (class String, either the first argument, or if missing the sourcenick), and args (class Array, an array of arguments). Example: 'script add greet m.reply( 'Hello ' + user )'. Invoke the script just like a plugin: '<botnick>: greet'."
-    else  
-      "Create mini plugins on IRC. 'script add <name> <code>' => Create script named <name> with the Ruby program <code>. 'script list' => Show a list of all known scripts. 'script show <name>' => Show the source code for <name>. 'script del <name>' => Delete the script <name>. 'script eval <expr>' => evaluate expression <expr>. 'script echo <expr>' => evaluate and display expression <expr>."
+    when "allow"
+      "script allow <script> for <user> [where] => allow <user> to run script <script> [where]"
+    when "allow"
+      "script deny <script> for <user> [where] => prevent <user> from running script <script> [where]"
+    else
+      "Create mini plugins on IRC. 'script add <name> <code>' => Create script named <name> with the Ruby program <code>. 'script list' => Show a list of all known scripts. 'script show <name>' => Show the source code for <name>. 'script del <name>' => Delete the script <name>. 'script eval <expr>' => evaluate expression <expr>. 'script echo <expr>' => evaluate and display expression <expr>. See also: add, allow, deny."
     end
   end
 
@@ -59,8 +64,8 @@ class ScriptPlugin < Plugin
 
       # Convenience variables, can be accessed by scripts:
       args = m.message.split
-      args.delete_at( 0 ) 
-      user = args.empty? ? m.sourcenick : args.first  
+      args.delete_at( 0 )
+      user = args.empty? ? m.sourcenick : args.first
 
       Thread.start {
         # TODO allow different safe levels for different botusers
@@ -147,7 +152,7 @@ class ScriptPlugin < Plugin
   def handle_add_force( m, params )
     handle_add( m, params, true )
   end
-    
+
 
   def handle_del( m, params )
     name = params[:name]
@@ -171,9 +176,9 @@ class ScriptPlugin < Plugin
     page = params[:page].to_i
     page = [page, 1].max
     page = [page, num_pages].min
-    str = cmds[(page-1)*cmds_per_page, cmds_per_page].join(', ') 
+    str = cmds[(page-1)*cmds_per_page, cmds_per_page].join(', ')
 
-    m.reply "Available scripts (page #{page}/#{num_pages}): #{str}" 
+    m.reply "Available scripts (page #{page}/#{num_pages}): #{str}"
   end