mIRC Home    About    Download    Register    News    Help

Print Thread
#214156 20/07/09 10:47 PM
Joined: Mar 2008
Posts: 33
S
starr Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2008
Posts: 33
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.

starr #214157 20/07/09 11:33 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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

Horstl #214163 21/07/09 12:18 AM
Joined: Mar 2008
Posts: 33
S
starr Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2008
Posts: 33
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.

starr #214164 21/07/09 12:27 AM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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.

Last edited by Horstl; 21/07/09 12:34 AM.
Horstl #214174 21/07/09 09:06 AM
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
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.


Link Copied to Clipboard