]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/script.rb
script plugin: improve help
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / script.rb
index e3e718a70546350808ec410c4eb2abe1b17e09e8..793064bd20faa97723cd1db92796b4f1baf58fbb 100644 (file)
@@ -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
 
@@ -52,6 +57,9 @@ class ScriptPlugin < Plugin
     name = m.message.split.first
 
     if m.address? and @commands.has_key?( name )
+      auth_path = "script::run::#{name}".intern
+      return unless @bot.auth.allow?(auth_path, m.source, m.replyto)
+
       code = @commands[name].code.dup.untaint
 
       # Convenience variables, can be accessed by scripts:
@@ -73,6 +81,26 @@ class ScriptPlugin < Plugin
     end
   end
 
+  def handle_allow_deny(m, p)
+    name = p[:stuff]
+    if @commands.has_key?( name )
+      @bot.plugins['auth'].auth_allow_deny(m, p.merge(
+        :auth_path => "script::run::#{name}".intern
+      ))
+    else
+      m.reply(_("%{stuff} is not a script I know of") % p)
+    end
+  end
+
+  def handle_allow(m, p)
+    handle_allow_deny(m, p.merge(:allow => true))
+  end
+
+  def handle_deny(m, p)
+    handle_allow_deny(m, p.merge(:allow => false))
+  end
+
+
 
   def handle_eval( m, params )
     code = params[:code].to_s.dup.untaint
@@ -172,6 +200,7 @@ plugin = ScriptPlugin.new
 plugin.default_auth( 'edit', false )
 plugin.default_auth( 'eval', false )
 plugin.default_auth( 'echo', false )
+plugin.default_auth( 'run', true )
 
 plugin.map 'script add -f :name *code', :action => 'handle_add_force', :auth_path => 'edit'
 plugin.map 'script add :name *code',    :action => 'handle_add',       :auth_path => 'edit'
@@ -181,4 +210,12 @@ plugin.map 'script echo *code',         :action => 'handle_echo'
 plugin.map 'script list :page',         :action => 'handle_list',      :defaults => { :page => '1' }
 plugin.map 'script show :name',         :action => 'handle_show'
 
+plugin.map 'script allow :stuff for :user [*where]',
+  :action => 'handle_allow',
+  :requirements => {:where => /^(?:anywhere|everywhere|[io]n \S+)$/},
+  :auth_path => 'edit'
+plugin.map 'script deny :stuff for :user [*where]',
+  :action => 'handle_deny',
+  :requirements => {:where => /^(?:anywhere|everywhere|[io]n \S+)$/},
+  :auth_path => 'edit'