menu menubar,channel,status {
-
Cricket-Ticker
.$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 15 crick last status)
echo 4 -ag *** Ticker for match ID %crickid $iif($timer(crick),started,stopped)
}
.$iif(%crickid,Show all comments now) : {
crick all status
echo 4 -sg *** Please wait a few seconds while I get you the info...
}
.-
.Set match ID $iif(%crickid,$+([current,$chr(58) $v1,])) : {
set %crickid $$regsubex($input(Enter numerical match ID (e.g. 1056):,eog,Set cricket match ID,%crickid),/\D/g,)
echo 4 -ag *** Cricket-Ticker match ID changed to: %crickid
}
.$iif(%crickid,Set tracking channel $+([current,$chr(58) $iif(%crickchan,$v1,none),])) : {
noop $input(Enter channel name:,eog,Set ticker tracking channel,%crickchan)
echo 4 -ag *** Ticker is $iif($!,$iif(($v1 != %crickchan),now) tracked at: $v1,not tracked $iif((%crickchan),anymore))
set %crickchan $!
}
}
; disabled query for <matchID> parameter, as it's glitchy with the new website
; I didn't have the time to take a look at this - maybe you don't need the feature at all.
; on $*:text:/^[!@.]crick ?(\S+)?$/iS:#: {
on $*:text:/^[!@.]crick$/iS:#: {
if ((!$hget(crickflood,0).item) && (!$timer(crick).pause)) {
hadd -mu5 crickflood flood
crick all # $regsubex($regml(1),/\D/g,)
}
}
alias -l crick {
if ($sock(crickcom)) { sockclose $v1 }
sockopen crickcom card.cricket.timesofindia.indiatimes.com 80
sockmark crickcom $+($1,$chr(1),$2,$chr(1),$iif($3-,$v1,%crickid))
}
on *:sockopen:crickcom: {
sockwrite -n $sockname GET $+(/,commentary.cms?matchid=,$gettok($sock($sockname).mark,3-,1)) HTTP/1.1
sockwrite -n $sockname Host: $sock($sockname).addr $+ $str($crlf,2)
}
on *:sockread:crickcom: {
var %r
sockread -fn %r
; span
if ($regex(%r,/^<div><span>([\d.]+)<\/span><\/div>$/)) { set -eu10 %crickspan $regml(1) }
; "x to y", description, scored runs, total score
; checking for "new comments" is somewhat tricky: last line is always "runs scored/total score", which may be the same
; furthermore, they tend to UPDATE existing comments (ball mph, typos, whatever) - means, the script wouldn't be able to recognize a modified description as "known" but
; replay all comments. the script now checks whether the 2nd last line is a "span" line (and not e.g. a "result" or "header"), to use that span Nr as a "last known" marker
; $regml(1) = "bat/bowl", $regml(2) = description, $regml(3) = scored runs, $regml(4) = total score
elseif ($regex(%r,/^<div class="wth"><span>([^<]+)<\/span><br> ([^<]+)<br>(\S+) ?run.+scored.+Total Score: ([^<]+)<\/div>$/)) {
var %t2 = $regml(2)
var %t1 = $+($chr(2), %crickspan $str($chr(15) $chr(32),4) $chr(31), $regml(1),$str($chr(15) $chr(32),5) Scored: $iif(($regml(3) == No),0,$v1) $chr(40),$regml(4),$chr(41))
if ($gettok($sock($sockname).mark,1,1) == last) && (%crickspan == %cricklast) { crickclose $sockname }
else { write -il1 crickcommentary.txt %t1 $+ $crlf $+ %t2 }
}
; result (over)
elseif ($regex(%r,/^<p><strong>([^<]+)<\/strong><\/p>$/)) {
var %t = 04 $+ $regml(1)
$iif(($gettok($sock($sockname).mark,1,1) == last) && (%t == %cricklast),crickclose $sockname,write -il1 crickcommentary.txt %t)
}
; misc
elseif ($regex(%r,/^<p>([^<]+)</p>$)) {
$iif(($gettok($sock($sockname).mark,1,1) == last) && ($regml(1) == %cricklast),crickclose $sockname,write -il1 crickcommentary.txt $regml(1))
}
; opponents
elseif ($regex(%r,/^<h2><i><a href=[^>]+>([^>]+)<\/a><\/i><\/h2>.+<h2><i><a href=[^>]+>([^>]+)<\/a><\/i><\/h2>$/)) {
sockmark $sockname $+($sock($sockname).mark,$chr(1),$regml(1) vs $regml(2))
}
; end of comments (close socket)
elseif (%r == <td class="rtclm" valign="top">) { crickclose $sockname }
}
alias -l crickclose {
var %s = $1, %f = crickcommentary.txt
tokenize 1 $sock($1).mark
sockclose %s
if (!$lines(%f)) {
if ($1 == all) { $iif(($me ison $2),msg $v2 4,echo 4 -ag) *** Sorry, no data found for match ID $qt($3) }
}
else {
if ($1 == last) {
var %l1 = $read(%f,n,$lines(%f)), %l2 = $read(%f,n,$calc($lines(%f) -1))
set %cricklast $iif(($gettok($strip(%l2),1,32) isnum),$v1,%l1)
}
if ($4) {
if ($lines(%f) > 2) { write -il1 %f 04 $+ $4 }
else { write -l1 %f 04 $+ $4 - $read(%f,n,1) }
}
if ($1 == all) {
if ($me !ison $2) { .play $iif(($v2 == status),-pse,-pe $v1) %f 0 }
else {
.play -m3 $2 %f 1500
if ($timer(crick)) { .timercrick -p }
}
}
elseif ($1 == last) {
.play -pse %f 0
if ($me ison %crickchan) {
.play -m3 $v2 %f 1500
if ($timer(crick)) { .timercrick -p }
}
}
}
}
on *:sockclose:crickcom: { crickclose $sockname }
on *:playend: {
if ($nopath($filename) == crickcommentary.txt) {
var %n = 1
while ($play(%n).fname) {
if ($v1 == $filename) { return }
inc %n
}
.remove $qt($filename)
if ($timer(crick).pause) { .timercrick -r }
}
}
on *:unload: { unset %crick* }