mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2015
Posts: 26
O
obee Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jul 2015
Posts: 26
Hello,

I am in need of a script that will extract info from a text file (when file is modified) and send a chat message with the matching contents.

When dayzprofile.txt is modified
Search dayzprofile.txt for "LastMPServer="
Return data after "LastMPServer=" (Should be the IP for server)
Send a chat message "!editcmd !server " + IP

Expected chat message outcome:

!editcmd !server 192.168.0.1

For more info, this is to update twitch viewers with the current server I'm playing in Dayz. I am trying to automate the process, currently i open the dayzprofile text file, search for lastmp, copy and paste IP into chat and update the !server command in my twitch bot.

Joined: Nov 2009
Posts: 295
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
Ok that is fairly simple. It will involve a timer that checks if the file has changed, so it will only check so often.

Code:
;Start timer when mirc starts that checks for changes every 30 seconds
on *:start: .timerdayzprofile 0 30 dayzprofile

;Alias that checks if the file has changed and messages channel. Make sure to update the path for the file and the channel name to message to.
alias dayzprofile {
  set -l %filepath dayzprofile.txt
  if ($file(%filepath).mtime != %dayzprofile) {
    set %dayzprofile $file(%filepath).mtime
    msg #pball !editcmd !server $remove($read(%filepath,w,LastMPServer=*),LastMPServer=)
  }
}


http://scripting.pball.win
My personal site with some scripts I've released.
Joined: Jul 2015
Posts: 26
O
obee Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jul 2015
Posts: 26
Nice work man! Works amazingly. The only thing is, how can I set it to only send the message when the file has changed? It is updating every 30 seconds even if the file has not changed.

Last edited by obee; 08/07/15 02:47 AM.
Joined: Nov 2009
Posts: 295
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
I tested it and it only triggered when the file changed. I wonder if you text file is changing even if the ip isn't. A simple fix anyways. This will store the ip address and check if that changes, so even if the text file changes nothing will happen if the ip doesn't change.

Code:
;Start timer when mirc starts that checks for changes every 30 seconds
on *:start: .timerdayzprofile 0 30 dayzprofile

;Alias that checks if the file has changed and messages channel. Make sure to update the path for the file and the channel name to message to.
alias dayzprofile {
  set -l %filepath dayzprofile.txt
  set -l %ip $remove($read(%filepath,w,LastMPServer=*),LastMPServer=)
  if (%ip != %dayzprofile) {
    set %dayzprofile %ip
    msg #pball !editcmd !server %ip
  }
}


http://scripting.pball.win
My personal site with some scripts I've released.
Joined: May 2015
Posts: 249
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
Store last IP somewhere and send msg only if read-IP != stored-IP.


Dont give a fish - teach to fish!
Joined: Jul 2015
Posts: 26
O
obee Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jul 2015
Posts: 26
pball you are a genius! Thank you so much, this works great. One final tweak, I was able to remove the " at the front of the IP by putting LastMPServer="

But I'm unable to remove the "; at the end of the IP.

Joined: Nov 2009
Posts: 295
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
oh if the ip has quotes around it you can use the following, just replace the whole line in the previous script.

Code:
set -l %ip $noqt($remove($read(%filepath,w,LastMPServer=*),LastMPServer=))


http://scripting.pball.win
My personal site with some scripts I've released.
Joined: Jul 2015
Posts: 26
O
obee Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jul 2015
Posts: 26
Thanks PBall!!

Joined: Jul 2015
Posts: 26
O
obee Offline OP
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jul 2015
Posts: 26
Ok so this is the code i currently use to update server command. Is there a way to private message this instead of sending to all? I'm trying to make it so that the server info isn't displayed to all, users can only retrieve the server info if they have access to the !server command on the other bot. If it updates the server info by !editcmd ip, it will display it to everybody.

Also, when it extracts the data it is pulling "; at the end too, is there a way to remove that?


Code:
;Start timer when mirc starts that checks for changes every 30 seconds
on *:start: .timerdayzprofile 0 30 dayzprofile

;Alias that checks if the file has changed and messages channel. Make sure to update the path for the file and the channel name to message to.
alias dayzprofile {
  set -l %filepath E:\Users\oBeE\Documents\DayZ\obee.DayZProfile
  set -l %ip $noqt($remove($read(%filepath,w,LastMPServer=*),LastMPServer=))
  if (%ip != %dayzprofile) {
    set %dayzprofile %ip
    msg #obeewnn !editcmd !server %ip
  }
}


Link Copied to Clipboard