X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fscript.rb;h=762613d42e85b6052fa50f9554537798181153c0;hb=297c80c7632e76e5c5a55cabad57154706911b57;hp=f6d867c53e9ffb80353a140550d996316b17307a;hpb=427b14e3ee7f7d7d7769069b8b0816e4e59e3bad;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/script.rb b/data/rbot/plugins/script.rb index f6d867c5..762613d4 100644 --- a/data/rbot/plugins/script.rb +++ b/data/rbot/plugins/script.rb @@ -37,15 +37,24 @@ 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: ': 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 ." + "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 . 'script eval ' => evaluate expression . 'script echo ' => evaluate and display expression ." 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 ) + def message( m ) name = m.message.split.first if m.address? and @commands.has_key?( name ) + auth_path = "script::run::#{name}".intern + return unless @bot.auth.allow?(auth_path, m.source, m.replyto) + code = @commands[name].code.dup.untaint # Convenience variables, can be accessed by scripts: @@ -60,10 +69,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 +84,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 +98,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 @@ -106,12 +115,12 @@ class ScriptPlugin < Plugin code = params[:code].to_s nick = m.sourcenick created = Time.new.strftime '%Y/%m/%d %H:%m' - channel = m.target + channel = m.target.to_s command = Command.new( code, nick, created, channel ) @commands[name] = command - m.reply( "done" ) + m.okay end @@ -127,7 +136,7 @@ class ScriptPlugin < Plugin end @commands.delete( name ) - m.reply( "done" ) + m.okay end @@ -166,6 +175,7 @@ plugin = ScriptPlugin.new plugin.default_auth( 'edit', false ) plugin.default_auth( 'eval', false ) plugin.default_auth( 'echo', false ) +plugin.default_auth( 'run', true ) plugin.map 'script add -f :name *code', :action => 'handle_add_force', :auth_path => 'edit' plugin.map 'script add :name *code', :action => 'handle_add', :auth_path => 'edit'