; added new menu item to set the match ID %crickid
; added new menu item to start/stop offline timer "crick" (= new ticker)
; renamed command "autocrickon" to "crick", added "type" (last/all) and "target" (output location) parameter to the "crick" command
menu menubar,channel,status {
-
Cric-Commentary
.Set match ID $iif(%crickid,$+([current $chr(58) $v1,])) : {
set %crickid $$gettok($gettok($input(Enter match ID (e.g. score6M691):,eog,Set cricket match ID,%crickID),-1,47),1,46)
echo 4 -ag *** Match ID changed to: %crickid
}
.$iif(!%crickid,$style(2) -- you have to set a match ID first --) : noop
.$iif(%crickid,$iif($timer(crick),$style(1) Ticker $+ $chr(58) enabled,Ticker $+ $chr(58) disabled))
..$iif($timer(crick),disable,enable) {
.timercrick $iif($timer(crick),off,-o 0 10 crick last status window)
echo 4 -ag *** Ticker for Match ID %crickid $iif($timer(crick),started,stopped)
}
.$iif(%crickid,Show ALL comments now) : {
crick all status window
echo 4 -ag *** Please Wait a Few Seconds While I Get You the Info...
}
}
; "type" and "target" parameters are now sent to command "crick" (and later stored in sockmark), I thus removed the %ccrick global variable
on $*:text:/^[!@.]startmatch$/iS:#:{
if (!%crickflood) {
inc -eu5 %crickflood
crick all #
msg # 4 *** Please Wait a Few Seconds While I Get You the Info...
}
}
; always closes open crick socket
; sockmark now contains "type" and "target" parameter (target parameter allows fast/safe playback to status window/unjoined channels - for my tests in the first place)
alias -l crick {
if ($sock(crickcom)) { sockclose $v1 }
sockopen crickcom mathrubhumi.cricfeeds.com 80
sockmark crickcom $+($1,$chr(1),$2-,$chr(1),.play $iif(($me !ison $2-),$iif(($2- == status window),-se,-e $2-) crickcommentary.txt 1,$2- crickcommentary.txt 2000))
}
; uses now match ID "%crickid" as set in the menu
on *:sockopen:crickcom:{
sockwrite -n $sockname GET $+(/,%crickid,.html) HTTP/1.1
sockwrite -n $sockname Host: $sock($sockname).addr $+ $str($crlf,2)
}
; moved the check for "end of comments" to the top, it was nested inside the last elseif (at that place it didn't trigger at all: "clear:both" is always a new line)
; furthermore, as there are multiple "style="clear:both"" in the source text, I put "<!--end of main-->" to detect "end of comments"
; the "end of comments" check now will also sockclose if "type" is "last" and the last-known comment had been received - so you can show new comments only
; added a line to capture the two opponents of the match for the "full" output - hope you like it :)
; finally, "on sockclose" won't trigger if you close the socket on your side. Output is now triggered by alias "crickclose".
on *:sockread:crickcom:{
var %read
sockread -fn %read
if (%read == </div> <!--end of main--></div>) { crickclose $sockname }
elseif ($regex(%read,/<div class="cf_np_column2"><span class="cf_underlin">([^<]+)<br \/><\/span>/)) { sockmark $sockname $+($sock($sockname).mark,$chr(1),$regml(1)) }
elseif ($regex(%read,/\S+\-\S+\:\ssmall;">(.*?)</div>/i)) {
var %t = $regsubex($+(Announcement:,$chr(32),$regml(1)),/<[^>]*>/g,)
$iif(($gettok($sock($sockname).mark,1,1) == last) && (%t == %cricklast),crickclose $sockname,write -il1 crickcommentary.txt %t)
}
; modified last regsubex to remove tab chars as well
elseif ($regex(%read,/<strong>(over)\s(\d+\.\d+)\:(.*)</div>/i)) {
var %t = $single($+(12 $+ $regml(1),$chr(32),$chr(3),05,$regml(2),$chr(3),$chr(32),:,$chr(32),$regsubex($regml(3),/(?:<[^>]*>|\t)/g,)))
$iif(($gettok($sock($sockname).mark,1,1) == last) && (%t == %cricklast),crickclose $sockname,write -il1 crickcommentary.txt %t)
}
}
; new close/output alias
alias -l crickclose {
var %s = $1
tokenize 1 $sock($1).mark
sockclose %s
if (!$lines(crickcommentary.txt)) {
if ($1 == all) { $iif(($me ison $2),msg $v1 4,echo 4 -ag) *** Sorry, No Cricket Match Found on $date $time *** }
}
else {
; for type "last" it stores the last line (= last comment) into a global var "%cricklast" to track changes
if ($1 == last) { set %cricklast $read(crickcommentary.txt,n,$lines(crickcommentary.txt)) }
; insert "opponents" header-line or at start of single line
if ($lines(crickcommentary.txt) > 1) { write -il1 crickcommentary.txt $4 }
else { write -l1 crickcommentary.txt $4 $read(crickcommentary.txt,n.1) }
; play command
$3
}
}
alias -l single { return $regsubex($1,/(single)/ig,$+($chr(3),04,\1)) }
; checking for $filename is imho better than than $exists (another /play request might end while this script is running)
; restarting the ticker timer on playend should account for playback delay
on *:playend: {
if ($nopath($filename) == crickcommentary.txt) {
.remove $qt($filename)
if ($timer(crick)) { .timercrick -o 0 10 crick last status window }
}
}