]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/script.rb
Adapt script plugin to new message mappper. Whitespace in code is now preserved
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / script.rb
index 8234442c840ca71186280c9887cc958638eac942..ff45df0bfd91100caec9d8da8bd8822822237adf 100644 (file)
@@ -18,7 +18,9 @@ class ScriptPlugin < Plugin
     super
     if @registry.has_key?(:commands)
       @commands = @registry[:commands]
-    else
+    end
+    
+    if @commands.nil?
       @commands = Hash.new
     end
 
@@ -77,7 +79,7 @@ class ScriptPlugin < Plugin
       return
     end
 
-    code    = params[:code].join( " " )
+    code    = params[:code].to_s
     nick    = m.sourcenick
     created = Time.new.strftime '%Y/%m/%d %H:%m'
     channel = m.target
@@ -112,7 +114,7 @@ class ScriptPlugin < Plugin
 
     cmds_per_page = 30
     cmds = @commands.keys.sort
-    num_pages = cmds.length / cmds_per_page
+    num_pages = cmds.length / cmds_per_page + 1
     page = params[:page].to_i
     page = [page, 1].max
     page = [page, num_pages].min
@@ -137,10 +139,11 @@ end
 
 plugin = ScriptPlugin.new
 plugin.register( "script" )
+plugin.default_auth( 'edit', false )
 
-plugin.map 'script add -f :name *code', :action => 'handle_add_force', :auth => 'scriptedit'
-plugin.map 'script add :name *code',    :action => 'handle_add',       :auth => 'scriptedit'
-plugin.map 'script del :name',          :action => 'handle_del',       :auth => 'scriptedit'
+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'
+plugin.map 'script del :name',          :action => 'handle_del',       :auth_path => 'edit'
 plugin.map 'script list :page',         :action => 'handle_list',      :defaults => { :page => '1' }
 plugin.map 'script show :name',         :action => 'handle_show'