]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
script plugin: echo function. like eval, but implies an m.reply
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 29 Aug 2006 07:23:22 +0000 (07:23 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 29 Aug 2006 07:23:22 +0000 (07:23 +0000)
ChangeLog
data/rbot/plugins/script.rb

index 3317fff4bb15276d09bb2fbfae426592b8a5b404..f76d53fcd3d94782527e64a84f532f5c549272f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-08-29  Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
+
+       * Script plugin: new (UNSAFE!) echo functions. Just like eval, but
+       m.replies the result of the evaluation.
+
 2006-08-26  Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
 
        * Plugin message mapper: new implementation. Multi-word parameters now
index e2669088c1c6062928d0ca8f4c2c85247504e8a5..60c0e97329745a108c30fe4093a2f6ec991e2826 100644 (file)
@@ -87,6 +87,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 )
+        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 )
@@ -161,6 +175,7 @@ plugin.map 'script add -f :name *code', :action => 'handle_add_force', :auth_pat
 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'