]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/script.rb
help for eval and echo
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / script.rb
index f6d867c53e9ffb80353a140550d996316b17307a..7a8c0c84696abc03ab36e2025a03c7577b148e8b 100644 (file)
@@ -37,10 +37,16 @@ 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 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>."
+      "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>."
     end
   end
 
+  def report_error(m, name, e)
+    # ed = e.backtrace.unshift(e.inspect).join(' ')
+    ed = e.inspect
+    m.reply( "Script '#{name}' crapped out :( #{ed}" )
+  end
+
 
   def listen( m )
     name = m.message.split.first
@@ -60,10 +66,10 @@ class ScriptPlugin < Plugin
         begin
           eval( code )
         rescue Exception => e
-          m.reply( "Script '#{name}' crapped out :(" )
-          m.reply( e.inspect )
+          report_error(m, name, e)
         end
       }
+      m.replied = true
     end
   end
 
@@ -75,10 +81,10 @@ class ScriptPlugin < Plugin
       begin
         eval( code )
       rescue Exception => e
-        m.reply( "Script '#{name}' crapped out :(" )
-        m.reply( e.inspect )
+        report_error(m, code, e)
       end
     }
+    m.replied = true
   end
 
 
@@ -89,10 +95,10 @@ class ScriptPlugin < Plugin
       begin
         m.reply eval( code ).to_s
       rescue Exception => e
-        m.reply( "Script '#{name}' crapped out :(" )
-        m.reply( e.inspect )
+        report_error(m, code, e)
       end
     }
+    m.replied = true
   end
 
 
@@ -111,7 +117,7 @@ class ScriptPlugin < Plugin
     command = Command.new( code, nick, created, channel )
     @commands[name] = command
 
-    m.reply( "done" )
+    m.okay
   end
 
 
@@ -127,7 +133,7 @@ class ScriptPlugin < Plugin
     end
 
     @commands.delete( name )
-    m.reply( "done" )
+    m.okay
   end