Passing command through idle-timer alias

Posted by Dragonatorul on Fri 08 Jan 2016 09:13 PM — 5 posts, 20,373 views.

#0
Hello,

I'm trying to set up a way to be notified if I've been idle for 15, 20, and 25 minutes.

The way I thought of is to set up an alias that captures every command I send to the world and passes it through to the world, while at the same time creating 3 timers which set off a function that plays a "ding". However, I'm having trouble with the passing the command through to the world.

If I setup an alias to capture

^(.*?)$


and set up the body of the alias with the function:

Send(%1)


If I set it to send this to the world and type the command look it sends this to the world:

Send(look)


If I set it to send to Script it sends this to the world:

nil


I'm stumped because it seems to capture it properly when sending to the world, but not when sending to the script, then passing back to the world.
Australia Forum Administrator #1
You could make a small plugin that uses the OnPluginCommand callback to find when you actually typed a command.

Something like the one below:


Template:saveplugin=IdleWarning
To save and install the IdleWarning plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. Save to disk on your PC, preferably in your plugins directory, as IdleWarning.xml
    • The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file IdleWarning.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. Save your world file, so that the plugin loads next time you open it.




<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="IdleWarning"
   author="Nick Gammon"
   id="9c9c760caf80e43893bb7b70"
   language="Lua"
   purpose="Warns when you are idle"
   date_written="2016-01-09 08:22:56"
   requires="4.90"
   version="1.0"
   >
</plugin>

<!--  Timers  -->

<timers>
  <timer 
    name="timer1" 
    enabled="y"
    minute="15"  
    send_to="1"
    script="OnIdleTimeout"
  >
  </timer>
  
  <timer 
    name="timer2" 
    enabled="y"
    minute="20"  
    send_to="1"
    script="OnIdleTimeout"
  >
  </timer>
  
  <timer 
    name="timer3" 
    enabled="y"
    minute="25"  
    send_to="1"
    script="OnIdleTimeout"
  >
  </timer>
      
</timers>

<!--  Script  -->


<script>
<![CDATA[

playedDing = {}  -- empty table
lastCommand = os.time ()

function OnPluginCommand ()
  ResetTimers ()   -- all timers start again
  playedDing = {}  -- reset table of played dings
  lastCommand = os.time ()
  return true -- process this command
end -- OnPluginCommand

function OnIdleTimeout (name)
  
  -- don't play it twice
  if playedDing [name] then
    return
  end -- if
  
  playedDing [name] = true
  PlaySound (0, "ding.wav")
  minutes = (os.time () - lastCommand) / 60
  ColourNote ("yellow", "", string.format ("WARNING: You have been idle for %i minutes now.", minutes))
end -- OnIdleTimeout

]]>
</script>

</muclient>


Note that the sound file should be in the "sounds" directory under the MUSHclient install folder.

The only file type supported is a .wav file, as follows:

* 16-bit
* 22.05 KHz
* PCM (ie. uncompressed)
* Mono or Stereo
Amended on Sat 09 Jan 2016 02:36 AM by Nick Gammon
Australia Forum Administrator #2
Quote:

... and set up the body of the alias with the function:

Send(%1)


Related to your question:

Template:faq=32
Please read the MUSHclient FAQ - point 32.


It would have worked better as:


Send("%1")
Amended on Sat 09 Jan 2016 04:53 AM by Nick Gammon
#3
Nick Gammon said:

You could make a small plugin that uses the OnPluginCommand callback to find when you actually typed a command.

Something like the one below:



Did you just write the plugin I was trying to write myself? You are AWESOME! Thank you!

Also thanks for clearing that lua value quote up for me. I have very little experience in Lua, having mostly worked with Java so far, but am learning as I go thanks to your client.

I'd also like to say you did an awesome job with the MUSHclient and thank you for making it available.
Australia Forum Administrator #4
Quote:

Did you just write the plugin I was trying to write myself?


Yes I did. I thought other people might find it useful too. :)