X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fscript.rb;h=8a3e1e847a0876416906a8b86186ba9a91c95e6a;hb=27cb79be57f9377d8c13dab2d7d0776e80dfd115;hp=29afa20a62e183fea66450382ef1a91722b1bd21;hpb=42045b5df29519cb4307ac433c6fd0d4ba5f157b;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/script.rb b/data/rbot/plugins/script.rb index 29afa20a..8a3e1e84 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 @@ -65,35 +64,38 @@ class ScriptPlugin < Plugin m.reply( e.inspect ) end } + m.replied = true end end 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 Exception => 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 Exception => 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 @@ -112,7 +114,7 @@ class ScriptPlugin < Plugin command = Command.new( code, nick, created, channel ) @commands[name] = command - m.reply( "done" ) + m.okay end @@ -128,7 +130,7 @@ class ScriptPlugin < Plugin end @commands.delete( name ) - m.reply( "done" ) + m.okay end