mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2017
Posts: 1
A
Mostly harmless
OP Offline
Mostly harmless
A
Joined: Jun 2017
Posts: 1
I would like to be able to automatically run a command at a scheduled day and time each week. To be more specific this would be for hosting and then later unhosting a channel on Twitch. Any assistance would be greatly appreciated.

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
A timer set to activate into the future the number of seconds between then-and-now is almost guaranteed to be late because of seconds lost during busy times, so instead this script sets the activating time based on the time of day.

This sets a timer to execute a command at the specified day hour:minute. mIRC's timer for triggering the timer ignores the seconds and doesn't let you specify the date, so if the target day/time is 24.0 or more hours in the future, this will keep setting a timer for 23 hrs 59 minutes in the future, until it's close enough to activate at the specified time. It will then repeat the following weeks, unless you comment-out the indicated line.

The command will get evaluated the 1st time the timer executes, so save any variables for being inside the command you want to execute at the future time.

The timer contains the triggerdate_time in the name, so you can use this to have several triggers throughout the week. Time is on the 24 hour clock, so midnight is 0:00 and 3:45pm is 15:45.

/DayTime_Activate Mon 18:00 Command-to-host-channel
/DayTime_Activate Mon 20:00 Command-to-unhost-channel

Each command executes the next time that day/time is reached, so if right now is Monday 19:00, the 2nd command gets executed 1 hour in the future, and the 1st command doesn't execute until 6.9 days in the future.

Code:
alias DayTime_Activate {
  var %now $calc(60* $int($calc($ctime / 60)))
  if ($1 == activate) goto $1

  :setup
  if (!$istok(Sun Mon Tue Wed Thu Fri Sat,$1,32)) goto syntax
  var %target_day $1
  var %target_hour $gettok($2,1,58)
  var %target_mins $gettok($2,2,58)
  if ((%target_hour !isnum 0-23) || (%target_mins !isnum 0-59)) goto syntax
  if (!$3-) goto syntax
  var %day_now  $asctime(%now,ddd)
  var %hour_now $asctime(%now,HH)
  var %mins_now $asctime(%now,nn)

  var %delay_mins $calc( (%target_hour - %hour_now) *60 + (%target_mins - %mins_now) *1 )
  var %target_weekday $findtok(Sun Mon Tue Wed Thu Fri Sat,%target_day,32)
  var %now_weekday    $findtok(Sun Mon Tue Wed Thu Fri Sat,%day_now   ,32)
  var %days_into_future $calc( (%target_weekday +7-%now_weekday) % 7)
  if (%target_day == %day_now) { var %days_into_future $iif(%delay_mins > 0,0,7) }
  var %delay_mins $calc( 24*60*%days_into_future + %delay_mins)
  var %2359 $asctime($calc(%now + (24*60-1)*60),HH:nn)
  var %time $iif(%delay_mins < $calc(24*60), $asctime($calc( %now + 60*%delay_mins ),HH:nn) , %2359)
  echo 4 -s timerDayTime_Activate_  $+ $1 $+ $2 -o %time 1 0 /DayTime_Activate $iif(%delay_mins < $calc(24*60),Activate) $1 $2 $3-
  .timerDayTime_Activate_           $+ $1 $+ $2 -o %time 1 0 /DayTime_Activate $iif(%delay_mins < $calc(24*60),Activate) $1 $2 $3-
  return

  :activate
  echo -a Timer set for $1 at $2 activating
  $4-

  ; make next line a COMMENT to avoid activating same time next week
  .timer 1 0 /DayTime_Activate $2 $3 $4-
  return

  :syntax
  window -ea @DayTime_Activate
  echo -a $iif($1-,Invalid syntax: $1-) Syntax: /DayTime_Activate Day_of_Week Time_of_Day COMMAND parameters Example: /DayTime_Activate Mon 18:00 Quiz c:\data\questions.txt
}

Joined: Nov 2018
Posts: 4
B
Self-satisified door
Offline
Self-satisified door
B
Joined: Nov 2018
Posts: 4
Using this how would I send a message to a specified channel?

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
In any editbox: /DayTime_Activate Mon 18:00 msg #channelname message
Note this assumes that making this command on a Monday assumes you want it to be NEXT Monday not today. If you are on more than 1 network, you must start the timer from any window attached to the network where that channel is.

If you're wanting this to be doing more than 1 command at that time each week, you can create an alias where you put all the commands, then have this script run that alias instead of showing the message.

Also, note that this assumes you are in that channel at the trigger day/times.


Code:
alias DayTime_Activate {
  var %now $calc(60* $int($calc($ctime / 60)))
  if ($1 == activate) goto $1

  :setup
  if (!$istok(Sun Mon Tue Wed Thu Fri Sat,$1,32)) goto syntax
  var %target_day $1
  var %target_hour $gettok($2,1,58))
  var %target_mins $gettok($2,2-,58)
  if ((%target_hour !isnum 0-23) || (. isin $2) || (%target_mins !isnum 0-59)) goto syntax
  if (!$3-) goto syntax
  var %day_now  $asctime(%now,ddd)
  var %hour_now $asctime(%now,HH)
  var %mins_now $asctime(%now,nn)

  var %delay_mins $calc( (%target_hour - %hour_now) *60 + (%target_mins - %mins_now) *1 )
  var %target_weekday $findtok(Sun Mon Tue Wed Thu Fri Sat,%target_day,32)
  var %now_weekday    $findtok(Sun Mon Tue Wed Thu Fri Sat,%day_now   ,32)
  var %days_into_future $calc( (%target_weekday +7-%now_weekday) % 7)
  if (%target_day == %day_now) { var %days_into_future $iif(%delay_mins > 0,0,7) }
  var %delay_mins $calc( 24*60*%days_into_future + %delay_mins)

  var %2359 $asctime($calc(%now + (24*60-1)*60),HH:nn)
  var %time $iif(%delay_mins < $calc(24*60), $asctime($calc( %now + 60*%delay_mins ),HH:nn) , %2359)
  echo -sc info timerDayTime_Activate_  $+ $1 $+ $2 -o %time 1 0 /DayTime_Activate $iif(%delay_mins < $calc(24*60),Activate) $1 $2 $3-
  .timerDayTime_Activate_               $+ $1 $+ $2 -o %time 1 0 /DayTime_Activate $iif(%delay_mins < $calc(24*60),Activate) $1 $2 $unsafe( $3- ) $chr(124) halt $chr(124) decoded command: $3-                      
  ; the above timer moves the timer forward 1 day when the target is not within 24 hrs, otherwise executes at the target time

  var %e $iif($fromeditbox,-ag,-sg)
  echo %e timer targeted to activate $asctime( $calc($ctime + %delay_mins *60),ddd mmm dd yyyy HH:nn tt ) executing: $3-
  echo %e To cancel this timer: /timerDayTime_Activate_  $+ $1 $+ $2 off
  echo %e To see all timers created by this script: /timerDayTime_Activate_*
  return

  :activate
  echo -a Timer set for $1 at $2-3 is now activating with command: $4-
  $4-

  ; make next line a COMMENT to avoid activating again same time 7 days after activating
  .timer 1 0 /DayTime_Activate $2 $3 $unsafe( $4- )
  return

  :syntax
  window -ea @DayTime_Activate
  echo -a $iif($1-,Invalid syntax: $1-) Syntax: /DayTime_Activate Day_of_Week Time_of_Day COMMAND [optional parameters]
  echo -a If target day-of-week is same as today's day-of-week, target will be 7 days from today (Use 3-letter day)
  echo -a To run alias /quiz next $asctime($ctime,dddd) at 6pm: /DayTime_Activate $asctime($ctime,ddd) 18:00 Quiz c:\data\questions.txt
}

Joined: Nov 2018
Posts: 4
B
Self-satisified door
Offline
Self-satisified door
B
Joined: Nov 2018
Posts: 4
Is there any way to save these timers when mIRC is closed? I noticed that they are offline timers. But when I close mIRC I have to recreate all of the timers again after closing.

Last edited by BlakeNote; 16/11/18 04:24 PM.
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
on *:START:{
commands to be performed on startup go in here
}

You can add an ON START event that performs commands only during startup. But for doing this inside a script instead of in the editbox as I described, you'll need to use the 2nd version of the script.

Be aware that the alias works by assuming that if today is Friday, and the alias is given parameters to perform the action on "Fri" at any time of day, it's assuming that you mean the Friday 7 days from now. So if you restart mirc at 2am Friday on the day where the notice should be happening, and if the command is to display Fri 18:00 it will first activate 7 days later.

Joined: Nov 2018
Posts: 4
B
Self-satisified door
Offline
Self-satisified door
B
Joined: Nov 2018
Posts: 4
Thank you for all your help!


Link Copied to Clipboard