mIRC Homepage
Posted By: Exuviax Updating on Text Update - 26/09/14 07:17 PM
Hey,

Is it possible to have the bot auto read and say whats in a text file on update? So when the file is updated the bot will automatically read it out? Or maybe have the bot go to read out the file ever 30 seconds but only if there was a change in the file?

EDIT: Second Question.

I am reading from a text file that is using Currency, so it says $25 in their, the bot won't read that out, probably because of the $, how can I fix that? I can't take it out of the Text File.
Posted By: Belhifet Re: Updating on Text Update - 26/09/14 07:28 PM
Uh..sure several ways to do this. Maybe keep two copies of the file and have mirc update one textfile when there is a difference and have it read then.
Posted By: Loki12583 Re: Updating on Text Update - 26/09/14 10:59 PM
You can use a timer and a combination of $file().mtime and $md5

Without the n switch $read will evaluate the line. That means $25 is evaluated to the 25th token in $1-. You should always use the n switch.

$read(file,n,1)
Posted By: Exuviax Re: Updating on Text Update - 27/09/14 12:30 AM
Awesome! Thanks Loki! I got the ,n, to work, but I don't really understand the $file().mtime and $md5 as I have never used that before. Do you think you could help me write it out?
Posted By: Loki12583 Re: Updating on Text Update - 27/09/14 12:46 AM
$file(file).mtime will return the time the file was last modified, you can store this value and compare it later to know if it's been modified. Sometimes a program will open the file and write it again without changing it, this will alter the mtime but since the file has not changed you need to use $md5(file,2) and compare it to the last md5 to make sure the content is different.
Posted By: Exuviax Re: Updating on Text Update - 27/09/14 01:07 AM
Alright, this is what I tried (I am by no means a Coder)

Code:
on *:Text:!last:#:{
  if (check.txt != $file(C:\Users\Randy\Documents\Streamtip\tip-recent.txt)) {
    msg #  New Donation: $read(C:\Users\Randy\Documents\Streamtip\tip-recent.txt,n,1) 
    write check.txt $file(C:\Users\Randy\Documents\Streamtip\tip-recent.txt).mtime
  }
}


Is that what you meant?
Posted By: Exuviax Re: Updating on Text Update - 27/09/14 03:07 AM
I got it working!!

Final Code

Code:
on *:text:*:#exuviax: {
  var %one { $read(C:\Users\Randy\Documents\Streamtip\tip-recent.txt,n,1) }
  var %two { $read(C:\Users\Randy\AppData\Roaming\mIRC\check.txt,n,1) }
  if (%two isin %one) { return }
  msg # New Donation: %one 
  write -c check.txt %one
}

Posted By: Belhifet Re: Updating on Text Update - 27/09/14 05:32 AM
It would probably be best to run it on a timer instead of every time someone speaks. This runs it every 30 seconds..you can set that to w/e you want but there certainly isn't any reason to potentially run this script multiple times per second.
Code:
on *:CONNECT: {
  .timerdonations 0 30 donations
}
alias donations {
  var %one $read(C:\Users\Randy\Documents\Streamtip\tip-recent.txt,n,1) 
  var %two $read(C:\Users\Randy\AppData\Roaming\mIRC\check.txt,n,1) 
  if (%two isin %one) { return }
  msg #exuviax New Donation: %one 
  write -c check.txt %one
}
Posted By: Exuviax Re: Updating on Text Update - 27/09/14 09:20 AM
Oh! Thank you so much! That actually makes me so happy, I was actually thinking about a way to have more then just "When you type" messages in chat! Awesome!
© mIRC Discussion Forums