mIRC Home    About    Download    Register    News    Help

Print Thread
#71396 14/02/04 08:01 PM
Joined: Feb 2004
Posts: 16
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Feb 2004
Posts: 16
Let's say the .txt file reads like this :

Hello @ 10:54:07 14/02/2004
Goodbye @ 10:55:07 14/02/2004
etc

Basically I want to be able to display results when someone searches for a variable via !cmd
For example, if someone typed !search Hello, I'd want this displayed in the channel. "Hello @ 10:54:07 14/02/2004 :: 3hrs 2mins 4secs ago"

Cant seem to figure out how to grab the "10:54:07 14/02/2004" part out of the same line in a .txt file and convert it to dd/mm/ss ago in the end of the line.

Any ideas?

Thanks.

Joined: Dec 2003
Posts: 219
F
Fjord artisan
Offline
Fjord artisan
F
Joined: Dec 2003
Posts: 219
Hi!

$read function has an "s" option to scan the file for a line beginning with a specified word, a nickname in your case.
Here's my proposal:

Code:
  %nickname = the_nickname_to_search_for, maybe $2 ...

  %found = $read(file.txt, s, %nickname)

  /if (%found) {
    %time = $mid(%found, 3, 8)
    %date = $mid(%found, 12, 10)

    %ctime = $ctime(%date %time)
    %print = $format_time($calc($ctime - %ctime))

    /msg $chan %nickname %found :: %print ago
  }

  /else {
    /msg $chan Nothing was found about %nickname
  }

  /unset %found
  /unset %print
  /unset %nickname


and the $format_time function:

Code:
format_time {
  %value = $1

  /unset %result

  %year = $floor($calc(%value / (365 * 86400)))
  %value = $calc(%value % (365 * 86400))
  /if (%year) { %result = %year $+ year }

  %day = $floor($calc(%value / 86400))
  %value = $calc(%value % 86400)
  /if (%day) { %result = %result %day $+ day }

  %hour = $floor($calc(%value / 3600))
  %value = $calc(%value % 3600)
  /if (%hour) { %result = %result %hour $+ hr }

  %min = $floor($calc(%value / 60))
  %value = $calc(%value % 60)
  /if (%min) { %result = %result %min $+ min }

  /if (%value) { %result = %result %value $+ sec }

  /unset %year
  /unset %day
  /unset %hour
  /unset %min
  /unset %value

  /return %result
}



Hope this will help!
chris

Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Code:
on *:text:!search *:#:{
  if $read([color:blue]file.txt[/color],w,$2 *) {
    msg # $ifmatch :: $duration($calc($ctime - $ctime($gettok($ifmatch,3-,32)))) ago
  }
  else msg # $2 not found
}

Joined: Dec 2003
Posts: 219
F
Fjord artisan
Offline
Fjord artisan
F
Joined: Dec 2003
Posts: 219
didn't know about $duration :tongue: great

Joined: Feb 2004
Posts: 16
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Feb 2004
Posts: 16
Neither of those worked, but thanks anyways smile

Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
You did of course change the file.txt to the real filename didn't you?
Do you have any other on *:text: events in the script file?

Joined: Feb 2004
Posts: 16
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Feb 2004
Posts: 16
Yup..its ok. Did it another way. Just made another txt just for times and used $duration($calc($ctime($time $date) - $ctime($read(pretime.txt, s, $2)))) ago.

Kind of a pain to make two files..but ah well lol..thx anyways.

Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
If what you posted above is the format of the file. "Hello @ 10:54:07 14/02/2004" then it should work out.

Try this:
/write -c newfile.tst Hello @ 10:54:07 14/02/2004
//if $read(newfile.tst,w, hello *) { echo -a $ifmatch :: $duration($calc($ctime - $ctime($gettok($ifmatch,3-,32)))) ago }

Joined: Feb 2004
Posts: 16
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Feb 2004
Posts: 16
Ah..It worked..check ur PM?


Link Copied to Clipboard