Auto-responder w/time spent idling

Posted by AnalogConspiracy on Wed 17 Apr 2013 01:29 PM — 6 posts, 28,742 views.

#0
So, I'm desiring a script that, when I idle (idle is >= 5 minutes), will record the time spent idling, and enable some sort of trigger that will auto-respond to tells.

Player tells you 'Do you know Tyler Durden?'
(.+) tells you \'+\'

>Send("reply Sorry, %1. I've been idling for: ".. idletime ..". I'll respond to you when I am back at the keyboard. Thank you!")

I know idletime would be an LUA var, but that's what I'd want... Right? I know it's hard to write an example for this (As Nick tends to write examples in the requester's language, mine being LUA

Could I have some assistance in making this come to life? I'm kinda confused as to how I'd even start.

EDIT: Of course, just to give a clear definition, idling starts at >= 5 minutes, AND when no command has been entered into the MUD. It automatically removes itself the moment I enter a command.
Amended on Wed 17 Apr 2013 01:30 PM by AnalogConspiracy
#1
I would start by using the socket object. This will help you do time calculations.


require "socket"
local currentclock = round(socket.gettime(),3)



Then programmatically determine when you last had an action. Must be a way programmatically to determine when you last entered input into the input text box. Store that in a variable, and do a


if (math.abs(currentclock - lastaction) >= 300) then
  Note("IM AFK")
end


That's a very rough shell, but that's how I'd approach it.
Amended on Wed 17 Apr 2013 08:19 PM by Oligo
#2
Well, I suppose we could start with setting an alias, as this seems to be the most obvious step.

 
<aliases>
  <alias
   match="^(.+)$"
   enabled="y"
   group="AFKstuff"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="100"
  >
  <send>Timerthing Disable
lastcommand = "%1"
Send("%1")
Timerthing Enable</send>
  </alias>
</aliases>


Now, I suppose we could add or create some sort of timer (a one-shot timer?)... I don't know the syntax for making, pausing, stopping, removing a timer or anything. But maybe this would be a start. And once the timer fires, I just throw a boolean in there.

afk = true

I don't know. Maybe I should just stop this and make a normal auto-respond trigger. At the same time, I don't want to just give up, because this would help expand my learning experience.
USA Global Moderator #3
You don't need socket to get the time. There are utils.timer() and os.time() and os.date() already.

And yes, a timer and an alias are the way to go.
See http://www.mushclient.com/scripts/doc.php?function=DoAfterSpecial

Also, Lua is not an acronym and should not be written in all caps.
Amended on Thu 18 Apr 2013 04:28 AM by Fiendish
#4
Fiendish said:

You don't need socket to get the time. There are utils.timer() and os.time() and os.date() already.

And yes, a timer and an alias are the way to go.
See http://www.mushclient.com/scripts/doc.php?function=DoAfterSpecial

Also, Lua is not an acronym and should not be written in all caps.


Thank you for the response, Fiendish, as well as the correction. I shall refrain from treating it as an acronym.

How would I enable and disable the time?
Also, simply just setting (.+) with lastaction = "%1" Send("%1") isn't going to work. It seems to run all the commands twice, for example, if I run a direction with an IMAP GMCP plugin for a MUD, then it would send "south" and "imap". Is there anything we can do to rectify this problem?

[EDIT] How would we keep the time spent idling in a variable?
Amended on Thu 18 Apr 2013 06:55 AM by AnalogConspiracy
USA Global Moderator #5
Maybe using http://www.mushclient.com/scripts/doc.php?function=AddTimer would be better than DoAfterSpecial. That way you can give the timer a name. You don't need to store the time spent idling. You need to store the timestamp when you started idling.

In a plugin, I guess you could do something like...


function OnPluginSent()
   went_idle_at = nil
   AddTimer ("idle_timer", 0, 5, 0, "", timer_flag.Enabled + timer_flag.OneShot + timer_flag.Replace, "goingIdle")
end

function goingIdle()
   went_idle_at = os.date()
end