<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, May 01, 2008, 9:38 AM -->
<!-- MuClient version 4.23 -->

<!-- Plugin "Command_Throttler" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Command_Throttler"
   author="Nick Gammon"
   id="40b23d22e34074ddefa98f09"
   language="Lua"
   purpose="Sends commands to the MUD gradually"
   date_written="2008-05-01 09:34:22"
   requires="4.18"
   version="1.0"
   >
<description trim="y">
<![CDATA[
"Throttles" your output to an acceptable rate.

Aliases:

show_queue  --> display outstanding queue

empty_queue --> discard entire queue

Command_Throttler:help --> this help
]]>
</description>

</plugin>


<!--  Aliases  -->

<aliases>
  <alias
   match="empty_queue"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

ColourNote ("gray", "", "Deleted " .. #queue .. " outstanding item(s) from the queue.")

queue = {}  -- queue is now empty

</send>
  </alias>

  <alias
   match="show_queue"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

if #queue == 0 then
  ColourNote ("gray", "", "Pending command queue is empty")
  return
end -- if

ColourNote ("gray", "", "Command queue:")
for k, v in ipairs (queue) do
  ColourNote ("gray", "", k .. ": " .. v) 
end -- for

ColourNote ("gray", "", #queue .. " outstanding item(s) in the command queue.")
</send>
  </alias>
</aliases>

<!--  Timers  -->

<timers>
  <timer 
    enabled="y" 
    second="0.20" 
    offset_second="0.00"    
    send_to="12"
>
  <send>

-- no queued commands? just exit

if next (queue) == nil then
  return
end -- if empty

-- send the earliest item

send_now = true  -- don't requeue it

Send (table.remove (queue, 1))

send_now = false -- queue if not from this plugin

</send>

  </timer>
</timers>

<!--  Script  -->


<script>
<![CDATA[

require "getlines"

queue = {}
send_now = false

function OnPluginInstall ()
  if GetOption ("enable_timers") ~= 1 then
    ColourNote ("white", "red", "Timers not enabled - commands will not be sent")
  end -- if timers not enabled

  if GetGlobalOption ("TimerInterval") ~= 0 then
    ColourNote ("white", "red", 
[[
Please go to the File menu -> Global Preferences Timers (Ctrl+Alt+G),
navigate to the Timers tab, and set the value for "Timer Interval" to be zero, 
in order for this plugin to work correctly. 
]])
  end -- if timer interval not zero

end -- function OnPluginInstall

function OnPluginSend (s)

  if send_now then
    return true -- yes we can send it
  end -- if sending from within the plugin

  -- queue the command - broken into individual lines
  for line in getlines (s) do
    table.insert (queue, line)
  end -- for loop

  return false

end -- function OnPluginSend
]]>
</script>


<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="Command_Throttler:help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
function OnHelp ()
  world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end
]]>
</script> 

</muclient>
