X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fscript.rb;h=83a1c9144f3efa1cfddb0ad0b6ebed8af1126fb6;hb=3d901ac98e5bf4c4c8e1a605208fabc4ba71a73e;hp=c091b5864a430baa4fc291016ff888a6cdf1b208;hpb=edd1cf77be07ae507014574141e920ad23eb164d;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/script.rb b/data/rbot/plugins/script.rb index c091b586..83a1c914 100644 --- a/data/rbot/plugins/script.rb +++ b/data/rbot/plugins/script.rb @@ -13,9 +13,7 @@ # plugin. You can create them directly in an IRC channel, and invoke them just # like normal rbot plugins. - -Command = Struct.new( "Command", :code, :nick, :created, :channel ) - +define_structure :Command, :code, :nick, :created, :channel class ScriptPlugin < Plugin @@ -23,6 +21,7 @@ class ScriptPlugin < Plugin super if @registry.has_key?(:commands) @commands = @registry[:commands] + raise unless @commands else @commands = Hash.new end @@ -36,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: ': 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: ': greet'." else "Create mini plugins on IRC. 'script add ' => Create script named with the Ruby program . 'script list' => Show a list of all known scripts. 'script show ' => Show the source code for . 'script del ' => Delete the script ." end @@ -60,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 @@ -71,29 +70,31 @@ class ScriptPlugin < Plugin def handle_eval( m, params ) code = params[:code].to_s.dup.untaint - Thread.start { - # TODO allow different safe levels for different botusers - begin - eval( code ) - rescue => e - m.reply( "Script '#{name}' crapped out :(" ) - m.reply( e.inspect ) - end - } + Thread.start { + # TODO allow different safe levels for different botusers + begin + eval( code ) + rescue Exception => e + m.reply( "Script '#{name}' crapped out :(" ) + m.reply( e.inspect ) + end + } + m.replied = true 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 - } + Thread.start { + # TODO allow different safe levels for different botusers + begin + m.reply eval( code ).to_s + rescue Exception => e + m.reply( "Script '#{name}' crapped out :(" ) + m.reply( e.inspect ) + end + } + m.replied = true end