mIRC Homepage
Posted By: starr Bot Code - 20/07/09 10:47 PM
I have a bot and I would like a message to be sent to channel at timed intervals. Can anyone give me an example of code for that? All help is appreciated.
Posted By: Horstl Re: Bot Code - 20/07/09 11:33 PM
With "timed intervals"; do you mean for example "every two hours"?

If yes, a basic example would be:
Code:
alias MyTimer {
  if ($1 == off) { .timerMyTimer off }
  else { .timerMyTimer 0 $duration(2h) if ($me ison #somechannel) msg #somechannel <My Message> }
}
"/MyTimer" will start the timer, "/MyTimer off" will stop it.
The alias can be called in your bot by events, e.g. a trigger ("on text"), or "on start", or "on me:*:join:#somechannel" ...

If instead you want to message at specific, fixed times/days of the week, maybe this thread (i.e. the script in my last post there) is of help.
In case neither is what you have in mind, provide an example please smile
Posted By: starr Re: Bot Code - 21/07/09 12:18 AM
Your first example is what I am looking for...a message sent to channel every 15 min. But if I use the trigger, does this still go in alias or would it go in remotes...a bit confused on that. And thank you so much for responding.
Posted By: Horstl Re: Bot Code - 21/07/09 12:27 AM
The example is an alias - for a remote file (every alias definition in a remote file is indicated by the initial word "alias"). Simply remove this word if you want to put it into "aliases".
It doesn't matter whether the alias is in the remote file or in "aliases" if you set a trigger to call the alias. The trigger itself has to be inside a remote file of course - so why not keep the two parts together in the same file smile
You could as well place the command right inside the event of your trigger...

Also note that you'll see the first message at the moment the timer fires for his first time, not at the moment the alias is called and the timer starts.
Posted By: 5618 Re: Bot Code - 21/07/09 09:06 AM
One additional note: the timer will stop if you disconnect or reconnect, for whatever reason.
You could make this an offline timer, but I think a more elegant solution here would be:
Code:
on me:*:JOIN:#somechannel:{ .MyTimer }

This code goes into Remote and restarts the timer whenever you join the channel.
NOTE: ONLY USE THIS CODE IF YOU ALWAYS WANT THE TIMER TO BE ON
You could also add an event for when you PART the channel, but there's a channel check already in the timer itself and I bet you'll be on the channel all the time anyway.
© mIRC Discussion Forums