]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/script.rb
reaction plugin: no more :stuff, but :before and :after for the pre and postmatch...
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / script.rb
index 3976517f7d873154f248026849ef3813e2f263b8..5e2f1e58e1b9140eac4cfabae9a2e17384dfde70 100644 (file)
@@ -1,16 +1,19 @@
-# Plugin for the Ruby IRC bot (http://linuxbrit.co.uk/rbot/)
+#-- vim:sw=2:et
+#++
 #
-# Create mini plugins on IRC.
+# :title: Script plugin for rbot
 #
-# 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. 
+# Author:: Mark Kretschmann <markey@web.de>
+# Copyright:: (C) 2006 Mark Kretschmann
+# License:: GPL v2
 #
-# (c) 2006 Mark Kretschmann <markey@web.de>
-# Licensed under GPL V2.
-
-
-Command = Struct.new( "Command", :code, :nick, :created, :channel )
+# Create mini plugins on IRC.
+#
+# 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. 
 
+define_structure :Command, :code, :nick, :created, :channel
 
 class ScriptPlugin < Plugin
 
@@ -18,6 +21,7 @@ class ScriptPlugin < Plugin
     super
     if @registry.has_key?(:commands)
       @commands = @registry[:commands]
+      raise unless @commands
     else
       @commands = Hash.new
     end
@@ -31,7 +35,7 @@ class ScriptPlugin < Plugin
 
   def help( plugin, topic="" )
     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'."
+      "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>."
     end
@@ -55,7 +59,7 @@ class ScriptPlugin < Plugin
 
         begin
           eval( code )
-        rescue => e
+        rescue Exception => e
           m.reply( "Script '#{name}' crapped out :(" )
           m.reply( e.inspect )
         end
@@ -70,7 +74,7 @@ class ScriptPlugin < Plugin
         # TODO allow different safe levels for different botusers
         begin
           eval( code )
-        rescue => e
+        rescue Exception => e
           m.reply( "Script '#{name}' crapped out :(" )
           m.reply( e.inspect )
         end
@@ -84,7 +88,7 @@ class ScriptPlugin < Plugin
         # TODO allow different safe levels for different botusers
         begin
           m.reply eval( code ).to_s
-        rescue => e
+        rescue Exception => e
           m.reply( "Script '#{name}' crapped out :(" )
           m.reply( e.inspect )
         end