mIRC Homepage
Posted By: SuperMappy No channel Activity - 15/08/04 08:54 AM
How can I keep track of how long there is no public activity in a channel and store that value in a variable.

Ex. If no one says anything in #bots-r-us for one hour then have the bot say something.
Posted By: Coolkill Re: No channel Activity - 15/08/04 10:46 AM
You would need a timer to do that since you want to perform something after 'X' duration.

On me:*:Join:[color:red]#channel
:{
.timer $+ $chan 0 300 durmon $chan
}
[/color]
The above will start a timer when you (the bot) joins the channel to run every 300 seconds (5 min).

alias durmon {
if (!$chan($1)) { .timer $+ $1 off }
elseif (($hget(lastspoke,$1)) && ($calc($ctime - $hget(lastspoke,$1)) >= 3600)) { msg $1 You have not spoke in an hour. }
}
}

The above is the alias that checks firstly, if the channel is open, if not, stops the timer, saves having to code 'On Part', then checks if theres a recorded 'lastspoke' time in our database, and if so if the difference between NOW and THEN is over an hour.

On *:Text:*:#:[color:red]#channel
:{
hadd -m lastspoke $chan $ctime
}
[/color]
This records when the last person spoke (doesnt include the person running the script).

Should do it.

Eamonn.
Posted By: Kelder Re: No channel Activity - 15/08/04 10:25 PM
on *:TEXT:*:[color:orange]#channelname:.timeridle $+ $chan 1 3600 msg $chan hey it's idle here
on *:ACTION:*:#channelname:.timeridle $+ $chan 1 3600 msg $chan hey it's idle here[/color]

It doesn't store the time, but it (re)starts a timer each time someone else says something. If the timer runs out after an hour, the message is sent. You can ofcourse replace the msg $chan with a call to an alias and have the message read or constructed there.

It will not keep track of your own messages, if you need that too, you either add the .timer line to all scripted events in your bot (if it's only a bot) or you use a custom /msg alias or you just live with it smile
You can change the 1 to a 0 if you foresee idle times of multiple hours and want to say something every hour then.
© mIRC Discussion Forums