looks like someone has already made it.
http://www.mircscripts.org/showdoc.php?type=code&id=4491
its a great looking script btw, nice compact use of COM too.
i think it has many practical uses. many site offer a JSON web service
even google offers a multitude:
youtube
dictionary
web search
translate
to name a few
And as for parsing, you could use a COM call to MSScriptControl.ScriptControl
but anyway, it seems im alone in thinking there is a practical use for this in mirc. ah well
i know youtube is changing its html all the time, and parsing it is becoming harder.
One alternative to get youtube info cleanly, from a more stable source is googles own youtube api
http://code.google.com/apis/youtube/2.0/developers_guide_protocol.html
but the real challenge lies in someone making their own json_decode alias. but hell, you could just regex match the json string instead.
heres an example url for one result. and the query = the youtube url
http://gdata.youtube.com/feeds/api/videos?q=http://www.youtube.com/watch?v=Nrm8-vnSEfc&start-index=1&max-results=1&v=2&alt=json
ps: json services are very fast indeed
have phun.
i added the $fileType array
function dir2array($targetDir, &$fileType){
$filesArray = array();
if ($handle = opendir($targetDir)){
while (false !== ($file = readdir($handle))){
if(in_array(end(explode(".", $file)), $fileType)){
$filesArray[] = $file;
}
}
closedir($handle);
}
if (count($filesArray) > 0) {
return $filesArray;
} else {
return FALSE;
}
}
// Usage Examples:
$arrayName = dir2array("path/to/directory", $arr = array("jpg", "png", "gif"));
$randfile = $arrayName[array_rand($arrayName)];
if(FALSE !== ($arrayName = dir2array("path/to/directory", $arr = array("jpg", "png", "gif")))){ $randfile = $arrayName[array_rand($arrayName)]; }
this should meet what's required
and can be quickly edited to handle a $fileType array
// Put all files of a directory of A selected filetype into an array.
function dir2array($targetDir, $fileType){
$filesArray = array();
if ($handle = opendir($targetDir)){
while (false !== ($file = readdir($handle))){
if(end(explode(".", $file)) == $fileType){
$filesArray[] = $file;
}
}
closedir($handle);
}
if (count($filesArray) > 0) {
return $filesArray;
} else {
return FALSE;
}
}
// Usage examples:
$arrayName = dir2array("path/to/directory", "jpg");
$randfile = $arrayName[array_rand($arrayName)];
if(FALSE !== ($arrayName = dir2array("path/to/directory", "png"))){ $randfile = $arrayName[array_rand($arrayName)]; }
of course, it's the main other language i use, even though i hardly do it these days.
I used to code mIRC a long time ago. but, i really don't see the point in applying all that time and effort into a language thats of no use outside of mIRCLAND. Thats just my opinion though. Not trying to get on anyones tits. :P
by closing the socket. try using socket_ functions in php. example here http://www.hawkee.com/snippet/6076/
by the way killwithme, if you launch the script with a .bat file it uses cmd.exe as the bot window.
I also noticed a problem with mIRC colours in unicode. If a sentence starts with a number, the first number of that sentence is incorporated in the unicode. thus, resulting in a normal coloured sentence with the first char missing.
But after some exploring i discovered "chr(3) is the mIRC equivalent on CTRL+K".
Just prefix any mIRC colour with a value < 10 with a zero to prevent the same crap happening
chr(3).'08,04hello'; <-- yellow foreground and red background.
chr(3).'14blah blah'; <-- gray text..
Hope it helps someone.
you could try this it may be slower than explode but you're only talking milliseconds..
/ Create An Infinite Loop.
while(1) {
while($data = fgets($socket)) {
/* Seperate All Data */
preg_match("/^:(.*?)!(.*?)@(.*?)[\s](.*?)[\s](.*?)[\s]:(.*?)$/",$data, $rawdata);
$nick = $rawdata[1];
$ident = $rawdata[2];
$host = $rawdata[3];
$msg_type = $rawdata[4];
$channel = $rawdata[5];
$message = rtrim($rawdata[6]);
$ex = explode(' ', $data);
/* Create the Commands Trigger */
$message = explode(" ", trim($message));
$trigger = array_shift($message);
$message = implode(" ", $message);
/* Send PONG Back To The Server. */
if($ex[0] == "PING"){ fputs($socket, "PONG ".$ex[1]."\n"); }
...
...
But keep using the $ex array for IRC events other than user events.