mIRC Homepage

Can I put vars into a document & use mIRC 2 copy?

Posted By: seanturner70

Can I put vars into a document & use mIRC 2 copy? - 07/04/09 10:52 PM

Hi, I am wondering if I can use mIRC to first copy a file, and change the variables as it goes along.

For example:
If I have the following file saved in the C drive as index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>My Chat</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
<div id="header">
	<div id="logo">
		<h1><a href="#">no-nick</a></h1>
		<h2><a href="#">Visit Main Homepage.</a></h2>
	<div id="menu">
			<li class="active"><a href="#/">home</a></li>
			<li><a href="#">commands</a></li>
			<li><a href="#">about</a></li>
			<li><a href="#">support</a></li>
			<li><a href="#">contact</a></li>
<!-- end header -->
<script type="text/javascript"> function toggle(obj) {
var obj=document.getElementById(obj);
if (obj.style.display == "block") obj.style.display = "none";
else obj.style.display = "block"; } </script>
<!-- start page -->
<div id="page">
	<!-- start content -->
	<div id="content">
		<!-- start latest-post -->
		<div id="latest-post" class="post">
			<h1 class="title">Welcome to your chat.</h1>
			<div class="entry">
				<p>Your current topic is: % $+ $chan $+ mytopic</p>
		<div id="recent-posts">
			<div class="post">
				<h2 class="title">Lets see...</h2>
				<div class="entry">

When someone types a command, is there a way that I can use mIRC to copy the whole document (C:\\index.html) from that directory to another directory. (e.g. E:\\index.html)

Then, is there a way, for example if someone changes the topic, to change the varible:
<p>Your current topic is: % $+ $chan $+ mytopic </p>

So, when it is opened in a web browser it would look like:
Your current topic is: Hi, this is my example topic.

I know this isn't a board for html scripting, but I am guessing this is more an mIRC thing than a html thing.

I am planning on having a whole load of variables that get changed as people do different things. (if that makes a difference)

Thank you very much for any help, it is much appreciated.
Posted By: Horstl

Re: Can I put vars into a document & use mIRC 2 copy? - 07/04/09 11:38 PM

I'm sure you know how to set the trigger, thus I'll outline only some possible steps for the copy-n-change itself:

Most simple, yet slowest solution:
1) copy the file with /copy
2) Scan for the line you want to change: $read(s) or $read(w) or $read(r) > $readn
3) replace/modify this line with /write -l /write -il etc.
( steps 2&3 could be one single step if you use /write -sl / -wl / -rl )

More advanced (will be noticeably faster if there are many lines to change):
use file handling (/fseek and /fwrite) instead of $read and /write

Or (might be the fastest solution - worth the effort if you're going to change the file heavily):
1) bread the file into a binary variable (into RAM)
2) modify the binvar with $bfind, /bset, /bcopy etc.
3) /bwrite ("dump") the final data to the output location

If you want to create an "evaluated" copy of a whole file, you could create a while loop that reads all lines of the infile and writes the evaluated line to an outfile, e.g.:
; /evalcopy "infile":"outfile"
alias evalcopy {
  tokenize 58 $1-
  if ($isfile($2)) { write -c $2 }
  var %n = 1
  while ($read($1,%n)) { write $$2 $v1 | inc %n }
...obviously this will cause problems if your infile contains unknown text and/or code you don't want to evaluate, e.g. words starting with "%" or "&" or "$" etc. Depending on the actual file size, you may again use file handling instead of $read and /write.
I think it's preferable to put some distinct "keywords" in the first file, some words you'll easily find with one of the read methods mentioned above, then you can replace these lines or $replace just the keywords with the data they represent (e.g. the content of a variable)
Posted By: seanturner70

Re: Can I put vars into a document & use mIRC 2 co - 08/04/09 12:38 AM

Thank you so much, very thorough.

Much better than setting hundreds of timers to re-write it every time and get it all messed up >.<
Posted By: seanturner70

Re: Can I put vars into a document & use mIRC 2 co - 12/04/09 05:44 PM

Ok, it is working.

However, I am now wondering if there is a way, that...

mirc can scan a folder, go into each folder, go into a specific file within each folder and change the same line in each.

A snippet of the code I would like to do this:
      elseif ($1 == !enable) && ($2 == games ) && ($3 == $null) && ($read(games.enabled.txt,w,$chan)) { /write -ds $+ $chan games.enabled.txt | msg $chan 3Games enabled for $chan | /write -l114 "C:\Documents and Settings\Sean's\My Documents\Web\my\ $+ $remove(#,$chr(35)) $+ \ $+ $network $+ \index.html" <p>Games - Enabled</p> }

So, say the complete location is: C:\Documents and Settings\Sean's\My Documents\Web\my\its-meme\iNetwork\index.html and there is another folder: \its-meme\network2\index.html

So, because the chat #its-meme is on iNetwork and network2, if they enable games, then it is only going to write it to the network it was done on, and, it will make the other network incorrect.

The files in each folder are very similar, they will have the same number of lines etc. Just wondering if there is a way to change line 114 in the index.html file in both the iNetwork and network2. when that command is run.
Posted By: Horstl

Re: Can I put vars into a document & use mIRC 2 co - 13/04/09 01:46 AM

Hm, why do you want to remove $chr(35) in your filenames? # is a valid char for filenames, and (in theory) it will mix things up for channels like "#testchan" vs "#test#chan".
I'd use $mkfn here instead - $mkfn replaces all invalid chars with underscores. You still *may* have identical filenames with this method, but less likely, and at least you ensure to have valid filenames.

Another note: if the "games.enabled.txt" is a plain list of channel names, you could use an .ini instead of a .txt:
- doing a "if $readini ... remini" instead of the "if $read(w) ... /write -ds"
- or /writeini the channel's setting to "on" or "off" instead of adding/removing a line to switch it

elseif ($1- == !enable games) && ($read(games.enabled.txt,w,$chan)) {

  write -ds games.enabled.txt $chan
  msg $chan 3Games enabled for $chan

  var %maindir = C:\Documents and Settings\Sean's\My Documents\Web\my\its-meme\

  ; if you want to use remove
  var %chandir = %maindir $+ $remove($chan,$chr(35)) $+ \

  ;        alternatively, if you want to use $mkfn
  ;        var %chandir = %maindir $+ $mkfn($chan) $+ \

  ; find all files named "index.html" in the %chandir, up to 2 dirs deep (that is: including direct subdirs).
  ; perform the command "Set114on" on these files. 
  noop $findfile(%chandir, index.html, 0, 2, Set114on $qt($1-))

  ;        The findfile loop above calls an alias, this allows you to modify multiple lines per file.
  ;        If you have only one line to change per file you could use the shorter:
  ;        noop $findfile(%chandir, index.html, 0, 2, write -l114 $qt($1-) <p>Games - Enabled</p>)


alias -l Set114on { write -l114 $1- <p>Games - Enabled</p> }

Edit: fixed wrong varnames
© 2020 mIRC Discussion Forums