]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/script.rb
Improve help.
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / script.rb
index e2669088c1c6062928d0ca8f4c2c85247504e8a5..4509c71b08dabc0d08243b4aba66cc663ff62f88 100644 (file)
@@ -18,18 +18,9 @@ class ScriptPlugin < Plugin
     super
     if @registry.has_key?(:commands)
       @commands = @registry[:commands]
-    end
-    
-    if @commands.nil?
+    else
       @commands = Hash.new
     end
-
-    # Migrate old Hash to new:
-    @commands.each_pair do |name, cmd|
-      unless cmd.instance_of?( Command )
-        @commands[name] = Command.new( cmd, 'unknown hacker', 'somedate', '#somechan' )
-      end
-    end
   end
 
 
@@ -42,7 +33,7 @@ class ScriptPlugin < Plugin
     if topic == "add"
       "Scripts are little Ruby programs that run in the context of the script plugin. You can access @bot (class IrcBot), m (class 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 code <source>. '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>."
+      "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>."
     end
   end
 
@@ -87,6 +78,20 @@ class ScriptPlugin < Plugin
   end
 
 
+  def handle_echo( m, params )
+    code = params[:code].to_s.dup.untaint
+      Thread.start {
+        # TODO allow different safe levels for different botusers
+        begin
+          m.reply eval( code ).to_s
+        rescue => e
+          m.reply( "Script '#{name}' crapped out :(" )
+          m.reply( e.inspect )
+        end
+      }
+  end
+
+
   def handle_add( m, params, force = false )
     name    = params[:name]
     if !force and @commands.has_key?( name )
@@ -156,11 +161,13 @@ plugin = ScriptPlugin.new
 plugin.register( "script" )
 plugin.default_auth( 'edit', false )
 plugin.default_auth( 'eval', false )
+plugin.default_auth( 'echo', false )
 
 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'
 plugin.map 'script del :name',          :action => 'handle_del',       :auth_path => 'edit'
 plugin.map 'script eval *code',         :action => 'handle_eval'
+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'