mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2017
Posts: 2
B
Bowl of petunias
OP Offline
Bowl of petunias
B
Joined: Dec 2017
Posts: 2
From research, I know that you can use $duration(seconds,N) to output uptime in hh:nn:ss format. However, I am looking for a way to change the output of uptime scripts so that it returns results in a format that excludes values larger than days and instead calculates the total days as the largest value.

In other words, instead of outputting uptime as (18wks 3days 15hrs 33mins 29secs), I would like to be able to have it output as (129days 15hrs 33mins 29secs). I have not been able to find any scripting examples which show a way to either change the output ($duration only has options to include or exclude seconds from the output), or perhaps some kind of workaround that redirects the initial uptime result returned from the system and recalculates it to output in the desired format above.

I have a feeling this is something that could be done with more advanced mIRC scripting knowledge such as regex, but I'm well out of my depth there, so I could use some assistance if someone would be so kind. Thanks! smile

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
Code:
//echo -a it has been $iif($int($calc($ctime / 86400)),$v1 $+ days) $duration($calc($ctime % 86400))

Joined: Oct 2015
Posts: 112
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
I faced this same issue almost two years ago and searched endlessly for an acceptable solution. I have edited a bunch of my scripts and put them into one script to make this work shareable. Hopefully you or someone else may find some or all of it useful. Enjoy. smile

This is a !date command that will return how long and when a user first followed your Twitch channel.

Mods may use !date by itself to get their own follow date, or they may use it with a users name after the !date command to get info of when another user followed the channel.

Non-Mods may only use !date by itself to get their own follow date, and there is a one minute cooldown (per user) on the command.

The command automatically removes any @ characters from the target's name.

The following are some example replies from the bot:

If the user has been following for LESS THAN ONE HOUR it will display MINUTES and SECONDS only:

User has been following this channel for 47 minutes, and 34 seconds.

If the user has been following for BETWEEN ONE HOUR and ONE DAY it will display HOURS and MINUTES only:

User has been following this channel for 13 hours, and 21 minutes.

If the user has been following for BETWEEN ONE DAY and ONE WEEK it will display DAYS and HOURS only as well as the date followed on:

User has been following this channel for 4 days, and 13 hours since Jan 10 2016.

If the user has been following for OVER A WEEK it will display YEARS, MONTHS, WEEKS, and DAYS only as well as the date followed on:

User has been following this channel for 1 year, 3 months, 1 week, and 4 days since Oct 3 2015.

You should just need to change YOUR_TWITCH_NAME_HERE to your Twitch channel name on line 33.

Code:
ON $*:TEXT:/^!date(\s@?\w+)?$/iS:#: {
  IF ($nick isop $chan) {
    IF (!$2) MSG $chan $followdate($nick)
    ELSE MSG $chan $IIF($twitch_name($remove($2,@)),$followdate($v1),$nick $+ $chr(44) $remove($2,@) is not a valid user on Twitch. FailFish)
  }
  ELSEIF ((!$($+(%,followdate_CD.,$nick),2)) && (!$2)) {
    SET -eu60 %followdate_CD. $+ $nick On
    MSG $chan $followdate($nick)
  }
}

alias twitch_name {
  INC %tn
  VAR %name, %name $IIF($1,$1,$nick), %tn %tn $+ $ticks
  JSONOpen -uw twitch_name $+ %tn https://api.twitch.tv/kraken/channels/ $+ %name
  JSONHttpHeader twitch_name $+ %tn Client-ID avm4vi7zv0xpjkpi3d4x0qzk8xbrdw8
  JSONHttpFetch twitch_name $+ %tn
  VAR %result $json(twitch_name $+ %tn, display_name).value
  IF (%result === %name) VAR %result %name
  ELSEIF (%result) {
    IF ($regex(%result,^(\w+)$)) VAR %result $regml(1)
    ELSE VAR %result $json(twitch_name $+ %tn, name).value
  }
  ELSE VAR %result $false
  JSONClose twitch_name $+ %tn
  RETURN %result
}

alias followdate {
  IF (%fd == 1000) %fd = 0
  INC %fd
  VAR %nick $1 , %since , %time_followed , %result , %fd %fd $+ $ticks
  JSONOpen -uw date $+ %fd https://api.twitch.tv/kraken/users/ $+ %nick $+ /follows/channels/YOUR_TWITCH_NAME_HERE?nocache= $+ $ticks
  JSONHttpHeader date $+ %fd Client-ID avm4vi7zv0xpjkpi3d4x0qzk8xbrdw8
  JSONHttpFetch date $+ %fd
  VAR %time_followed $JSON(date $+ %fd, created_at).value
  IF (%time_followed) {
    VAR %date_followed $TwitchTime(%time_followed)
    VAR %length_of_time $calc($ctime - %date_followed)
    VAR %better_length_of_time $DateXpander($calc($ctime - %date_followed))
    IF (%length_of_time >= 86400) VAR %better_length_of_time %better_length_of_time since $asctime(%date_followed,mmm dd yyyy)
    VAR %result %nick has been following the channel for %better_length_of_time $+ .
  }
  ELSE %result %nick is not following the channel.
  JSONClose date $+ %fd
  RETURN %result
}

; TwitchTime alias written by SReject and friends
alias -l TwitchTime {
  if ($regex($1-, /^(\d\d(?:\d\d)?)-(\d\d)-(\d\d)T(\d\d)\:(\d\d)\:(\d\d)(?:(?:Z$)|(?:([+-])(\d\d)\:(\d+)))?$/i)) {
    var %m = $Gettok(January February March April May June July August September October November December, $regml(2), 32), %d = $ord($base($regml(3),10,10)), %o = +0, %t
    if ($regml(0) > 6) %o = $regml(7) $+ $calc($regml(8) * 3600 + $regml(9))
    %t = $calc($ctime(%m %d $regml(1) $regml(4) $+ : $+ $regml(5) $+ : $+ $regml(6)) - %o)
    if ($asctime(zz) !== 0 && $regex($v1, /^([+-])(\d\d)(\d+)$/)) {
      %o = $regml(1) $+ $calc($regml(2) * 3600 + $regml(3))
      %t = $calc(%t + %o )
    }
    return %t
  }
}

; THE FOLLOWING IS A SLIGHTLY MODIFIED VERSION OF RAMIUS' DATEXPANDER SCRIPT FOUND HERE http://pastebin.com/eRMp7U8E
; ALL CREDITS GO TO RAMIUS FOR THIS SCRIPT http://www.kakkoiitranslations.net/mircscripts/
alias DateXpander {
  if ($1 isalpha) {
    echo -a Error.  Use the same format as in $chr(36) $+ duration's output or seconds for the "value".
    halt
  }

  if ($1 isnum) {
    set %dx_value $duration($1)
  }
  else {
    set %dx_value $1
  }

  set %dx_weeks $iif($gettok(%dx_value,1,119) isnum,$gettok(%dx_value,1,119),0)
  set %dx_days $iif($gettok($gettok(%dx_value,1,100),-1,32) isnum,$gettok($gettok(%dx_value,1,100),-1,32),0)
  set %dx_hours $iif($gettok($gettok(%dx_value,1,104),-1,32) isnum,$gettok($gettok(%dx_value,1,104),-1,32),0)
  set %dx_minutes $iif($gettok($gettok(%dx_value,1,109),-1,32) isnum,$gettok($gettok(%dx_value,1,109),-1,32),0)
  set %dx_seconds $iif(sec isin $gettok(%dx_value,$gettok(%dx_value,0,32),32),$gettok($gettok(%dx_value,$gettok(%dx_value,0,32),32),1,115),0)
  set %dx_totaldays $calc(%dx_weeks * 7 + %dx_days)
  set %dx_outputdays %dx_totaldays

  if ($3 != $null) {
    set %dx_currentmonth $gettok($3,1,47)
    set %dx_currentyear $gettok($3,3,47)
  }
  elseif ($chr(47) isin $2) {
    set %dx_currentmonth $gettok($2,1,47)
    set %dx_currentyear $gettok($2,3,47)
  }
  else {
    set %dx_currentmonth $date(m)
    set %dx_currentyear $date(yyyy)
  }
  if ($len(%dx_currentmonth) == 1) { set %dx_currentmonth 0 $+ %dx_currentmonth }
  if ($len(%dx_currentyear) == 2) { set %dx_currentyear 20 $+ %dx_currentyear }

  :monthstart
  if ($istok(12.10.07.05,%dx_currentmonth,46)) {
    set %dx_monthdays 30
  }
  elseif ($istok(11.09.08.06.04.02.01,%dx_currentmonth,46)) {
    set %dx_monthdays 31
  }
  elseif (%dx_currentmonth == 03 && ($calc(%dx_currentyear % 4) != 0 || ($calc(%dx_currentyear % 100) == 0 && $calc(%dx_currentyear % 400) != 0 && %dx_currentyear > 1582))) {
    set %dx_monthdays 28
  }
  elseif (%dx_currentmonth == 03) {
    set %dx_monthdays 29
  }
  if (%dx_totaldays >= %dx_monthdays) {
    inc %dx_months
    dec %dx_totaldays %dx_monthdays
    if (%dx_currentmonth != 01) {
      dec %dx_currentmonth
      if ($len(%dx_currentmonth) == 1) { set %dx_currentmonth 0 $+ %dx_currentmonth }
      dec %dx_currentyear
    }
    else { set %dx_currentmonth 12 }
    inc %dx_totalmonths
    inc %dx_monthsdays %dx_monthdays
    if (%dx_totalmonths == 12) {
      inc %dx_yeardays %dx_monthsdays
      unset %dc_monthsdays
      unset %dx_totalmonths
    }
    goto monthstart
  }

  set %dx_years $int($calc(%dx_months / 12))
  dec %dx_months $calc(%dx_years * 12)
  set %dx_weeks $int($calc(%dx_totaldays / 7))
  set %dx_totaldays $calc(%dx_totaldays % 7)

  if ($2 && $chr(47) !isin $2) {
    if (y !isin $2 && %dx_years > 0) {
      set %dx_months $calc(%dx_months + (%dx_years * 12))
      set %dx_years 0
    }
    if (m !isin $2 && %dx_months > 0) {
      set %dx_weeks $iif(%dx_years == 0,$int($calc((%dx_outputdays) / 7)),$int($calc((%dx_outputdays - %dx_yeardays) / 7)))
      set %dx_totaldays $iif(%dx_years == 0,$calc((%dx_outputdays) % 7),$calc((%dx_outputdays - %dx_yeardays) % 7))
    }
    if (w !isin $2 && %dx_weeks > 0) {
      set %dx_totaldays $calc(%dx_totaldays + (%dx_weeks * 7))
    }
    if (d !isin $2 && %dx_days > 0) {
      set %dx_hours $calc(%dx_hours + (%dx_days * 24))
    }
    if (h !isin $2 && %dx_hours > 0) {
      set %dx_minutes $calc(%dx_minutes + (%dx_hours * 60))
    }
    if (n !isin $2 && %dx_minutes > 0) {
      set %dx_seconds $calc(%dx_seconds + (%dx_minutes * 60))
    }
    set %dateoutput $replacex($2,y,$bytes(%dx_years,b) $iif(%dx_years == 1,year $+ $chr(44) $+ $chr(32),years $+ $chr(44) $+ $chr(32)),m,$bytes(%dx_months,b) $iif(%dx_months == 1,month $+ $chr(44) $+ $chr(32),months $+ $chr(44) $+ $chr(32)),w,$bytes(%dx_weeks,b) $iif(%dx_weeks == 1,week $+ $chr(44) $+ $chr(32),weeks $+ $chr(44) $+ $chr(32)),d,$bytes(%dx_totaldays,b) $iif(%dx_totaldays == 1,day $+ $chr(44) $+ $chr(32),days $+ $chr(44) $+ $chr(32)),h,$bytes(%dx_hours,b) $iif(%dx_hours == 1,hour $+ $chr(44) $+ $chr(32),hours $+ $chr(44) $+ $chr(32)),n,$bytes(%dx_minutes,b) $iif(%dx_minutes == 1,minute $+ $chr(44) $+ $chr(32),minutes $+ $chr(44) $+ $chr(32)),s,$bytes(%dx_seconds,b) $iif(%dx_seconds == 1,second $+ $chr(44) $+ $chr(32),seconds $+ $chr(44) $+ $chr(32)))
    set %dateoutput $left(%dateoutput,-1)
  }
  else {
    if ($1 >= 86400) {
      if (%dx_years > 1) { set %dateoutput %dateoutput $bytes(%dx_years,b) $+ _years }
      elseif (%dx_years == 1) { set %dateoutput %dateoutput $bytes(%dx_years,b) $+ _year }
      if (%dx_months > 1) { set %dateoutput %dateoutput %dx_months $+ _months }
      elseif (%dx_months == 1) { set %dateoutput %dateoutput %dx_months $+ _month }
      if (%dx_weeks > 1) { set %dateoutput %dateoutput %dx_weeks $+ _weeks }
      elseif (%dx_weeks == 1) { set %dateoutput %dateoutput %dx_weeks $+ _week }
      if (%dx_totaldays > 1) { set %dateoutput %dateoutput %dx_totaldays $+ _days }
      elseif (%dx_totaldays == 1) { set %dateoutput %dateoutput %dx_totaldays $+ _day }
    }
    if ($1 isnum 3600-604799) {
      if (%dx_hours > 1) { set %dateoutput %dateoutput %dx_hours $+ _hours }
      elseif (%dx_hours == 1) { set %dateoutput %dateoutput %dx_hours $+ _hour }
    }
    if ($1 isnum 60-86399) {
      if (%dx_minutes > 1) { set %dateoutput %dateoutput %dx_minutes $+ _minutes }
      elseif (%dx_minutes == 1) { set %dateoutput %dateoutput %dx_minutes $+ _minute }
    }
    if ($1 < 3600) {
      if (%dx_seconds > 1) { set %dateoutput %dateoutput %dx_seconds $+ _seconds }
      elseif (%dx_seconds == 1) { set %dateoutput %dateoutput %dx_seconds $+ _second }
    }
    set %dateoutput $replace(%dateoutput,$chr(32),$chr(44) $+ $chr(32),_,$chr(32))
  }
  if ($gettok(%dateoutput,0,32) > 2) {
    set %dateoutput $instok(%dateoutput,$chr(32) $+ and,-2,32)
  }
  unset %dx_*
  var %result %dateoutput
  unset %dateoutput
  return %result
}


Joined: Dec 2017
Posts: 2
B
Bowl of petunias
OP Offline
Bowl of petunias
B
Joined: Dec 2017
Posts: 2
Many thanks to both of you for your kind replies and swift assistance!

Ultimately, I was able to use what @maroon posted to modify the uptime script, and was able to successfully output in the format I wanted after a fair bit of trial and error.

Previous output, using uptime snippet from HM2K's moo.mrc v3.17 system stats script:
Code:
Current Uptime: 1day 1hr 38mins 4secs - Time To Beat: 18wks 3days 15hrs 33mins 29secs

on *:connect: up x
alias up { ;uptime v0.4
  $iif($timer(up) == $null,.timerup 0 60 up x)
  if (($uptime(system,3) >= %up) || (%up == $null)) set %up $uptime(system,3)
  $iif($1 == x,halt,$iif($chan,msg $chan,$iif($active == Status Window,echo,say)) $+(Windows,$OS) Uptime: $uptime(system,1) Best: $duration(%up))
}

Modified output, including minor cosmetic changes:
Code:
Current Uptime: 1day 2hrs 22mins 35secs - Time To Beat: 129days 15hrs 33mins 29secs

on *:connect: up x
alias up { ;uptime v0.4
  $iif($timer(up) == $null,.timerup 0 60 up x) 
  if (($uptime(system,3) >= %up) || (%up == $null)) set %up $uptime(system,3) 
  $iif($1 == x,halt,$iif($chan,msg $chan,$iif($active == Status Window,echo,say))) $+(4Current) Uptime: $uptime(system,1) 4Time To Beat: $iif($int($calc(%up / 86400)),$v1 $+ days) $duration($calc(%up % 86400))
}

Again, thanks to both of you for your input, and thank you for responding so quickly. Cheers!


Link Copied to Clipboard