mIRC Home    About    Download    Register    News    Help

Print Thread
i need a little script #268458 14/02/21 02:53 AM
Joined: Feb 2021
Posts: 1
usman Offline OP
Mostly harmless
OP Offline
Mostly harmless
Joined: Feb 2021
Posts: 1
its long time ago to scripting with msl that i need help
i Need an MSL script sending on follow times, follow messeges

Monday - Sonday
Time in 24h

12:00 /msg #grp01 !command
12:30 /msg #grp02 !command
13:00 /msg #grp03 !command
13:30 /msg #grp04 !command
14:00 /msg #grp05 !command
14:30 /msg #grp06 !command
15:00 /msg #grp07 !command
15:30 /msg #grp08 !command
16:00 /msg #grp09 !command
16:30 /msg #grp10 !command
17:00 /msg #grp11 !command
17:30 /msg #grp12 !command
18:00 /msg #grp13 !command
18:30 /msg #grp14 !command
19:00 /msg #grp15 !command
19:30 /msg #grp16 !command
20:00 /msg #grp17 !command
20:30 /msg #grp18 !command
21:00 /msg #grp19 !command
21:30 /msg #grp20 !command
22:00 /msg #grp21 !command
22:30 /msg #grp22 !command
23:00 /msg #grp23 !command

Please note that the bot needs to keep it repeating please.


Re: i need a little script [Re: usman] #268462 16/02/21 01:02 AM
Joined: Jan 2004
Posts: 1,510
maroon Offline
Hoopy frood
Hoopy frood
Joined: Jan 2004
Posts: 1,510
This can be done with timers, but you must be careful if your 'payload' includes identifiers or variable names which need to be evaluated at the time of execution instead of the time of the launch. If you've accurately described your request as wishing to send the literal string !command as a channel message, then it's fine to put the !command string into the timer. But if the string is something that originates from something created by someone else, you must take care to avoid it triggering a timer exploit.


If your timer command includes things that need to be evaluated in the future, it's probably easiest to create a custom alias where the evaluation takes place inside it, then have the timer call the alias.

It's been a while since I've tested the timer command to make sure that this will keep executing every day at midnight, or whether the 24*60*60 seconds can have an interval of more more than 24.0000 hours.

/timer 00:00 0 86400 echo -a hello this is midnight

You can't have the command assume that the time-of-day will happen in the future, because if your command is:

/timer 12:34 1 0 name_of_alias

You can't have the alias contain the command to execute the timer at 12:34 because if that time is the now-time, it executes immediately instead of 24 hours from now. What you can do is have a midnight timer execute at 23:59 each day with a 60 seconds delay, where the alias contains a command to execute the timer again in 23.99 hours. Because I'm being paranoid, and there's been rare cases in the past where a timer set to execute later at 16:00 would rarely execute at 15:59:59, I'll have this alias wait 61 seconds instead of 60.

With this alias you can do like:

/dailytimers init 00:00 /msg #channelname it's midnight! $!asctime

and this will execute that timer on a daily interval. Note how the $! is need to make it show the time when the timer executes not when it was created.

It works by calculating what's 1 minute earlier, then setting the timer to trigger 1 minute early, at which time it waits 61 seconds before sending the command to execute. After executing the message, it again sets itself to be launching the timer for the next day at 1-minute-early. You can either launch each init individually like the above, or you can do /dailytimers launchall and it launches all the timers that are hard-coded there. The timer needs the -o switch because, without it, the timer gets killed if you happen to get disconnected.

If you need it to not execute on certain days, the timer would need to include some logic to decide whether to execute the "$3-" line, like:

if ($asctime($ctime,ddd) isin Mon Tue Wed Thu Fri) $3-

You can kill all timers with
/timerdailytimers* off

or kill just 1 of them like
/timerdailytimer12:30 off

Note that when I'm setting the timer, it's including the seconds. mIRC always ignores the seconds and always behaves as if 12:34 or 12:34:any_seconds should be 12:34:00. It was just easier to avoid removing the extra :00 from the $duration output each time.

If you put this in your alt+D aliases file instead, be sure to remove the 'alias ' prefix on the 1st line.

alias dailytimers {
  if ($1 == init) {
    var %a $gettok($2,1-2,$asc(:))
    var %one_min_early $duration($calc( ($duration(%a $+ :00 ) - 60+86400) % 86400 ),3)
    .timerdailytimers $+ $2 -o %one_min_early 1 61 dailytimers delay_until $2-
    echo -s this will wait until %one_min_early then wait 61 more seconds until %a when it executes as a command: $3-
    echo -s it then repeats the cycle
    echo -s note that any % or $ appearing in the command string will be evaluated at that time
    echo -s to stop this 1 timer, type: /timerdailytimers $+ $2 OFF or to stop all timers: /timerdailytimers* off
  elseif ($1 == delay_until) {
    var %one_min_early $duration($calc( ($duration($2 $+ :00) - 60+86400) % 86400 ),3)
    .timerdailytimers $+ $2 -o 1 61 dailytimers exec $2-
  elseif ($1 == exec) {
    var %one_min_early $duration($calc( ($duration($2 $+ :00) - 60+86400) % 86400 ),3)
    .timerdailytimers $+ $2 -o %one_min_early 1 61 dailytimers delay_until $2-
  elseif ($1 == launchall) {
    dailytimers init 12:00 /msg #grp01 !command
    dailytimers init 12:30 /msg #grp02 !command
    dailytimers init 13:00 /msg #grp03 !command
    dailytimers init 13:30 /msg #grp04 !command
    dailytimers init 14:00 /msg #grp05 !command
    dailytimers init 14:30 /msg #grp06 !command
    dailytimers init 15:00 /msg #grp07 !command
    dailytimers init 15:30 /msg #grp08 !command
    dailytimers init 16:00 /msg #grp09 !command
    dailytimers init 16:30 /msg #grp10 !command
    dailytimers init 17:00 /msg #grp11 !command
    dailytimers init 17:30 /msg #grp12 !command
    dailytimers init 18:00 /msg #grp13 !command
    dailytimers init 18:30 /msg #grp14 !command
    dailytimers init 19:00 /msg #grp15 !command
    dailytimers init 19:30 /msg #grp16 !command
    dailytimers init 20:00 /msg #grp17 !command
    dailytimers init 20:30 /msg #grp18 !command
    dailytimers init 21:00 /msg #grp19 !command
    dailytimers init 21:30 /msg #grp20 !command
    dailytimers init 22:00 /msg #grp21 !command
    dailytimers init 22:30 /msg #grp22 !command
    dailytimers init 23:00 /msg #grp23 !command
  else { echo -a syntax: /dailytimers init HH:nn command goes here
    or: /dailytimers launchall