bind pub - !pdgroup msg_pdgroup
proc msg_pdgroup {nick uhost hand chan text} {
  set text [string tolower $text]

  set connect [::http::geturl http://www.livescore.com/worldcup/group-$text/]
  set files [::http::data $connect]
  ::http::cleanup $files


set l [regexp -all -inline -- { .*?<td class="ty">(.*?)</td> <td class="dt">(.*?)</td> <td class="tm">(.*?)</td> <td><a href="(.*?)">(.*?)</a></td> <td class="sc">(.*?)</td>.*?} $files]

putserv "PRIVMSG $nick :\[\002Group $text\002\] (Majukan 7 jam untuk WIB +7 GMT)"
if {[llength $l] != 0} {

     foreach {black a b c d e f} $l {

         set a [string trim $a " \n"]
         set b [string trim $b " \n"]
         set c [string trim $c " \n"]
         set d [string trim $d " \n"]
         set e [string trim $e " \n"]
         set f [string trim $f " \n"]

         regsub -all {<.+?>} $a {} a
         regsub -all {<.+?>} $b {} b
         regsub -all {<.+?>} $c {} c
         regsub -all {<.+?>} $d {} d
         regsub -all {<.+?>} $e {} e
         regsub -all {<.+?>} $f {} f

putserv "PRIVMSG $nick :\[\002$e\002 ($f)\] $b, Jam: $c - Ketik !pd $e untuk info details yang sudah bertanding"}

} else { putserv "PRIVMSG $nick :lapor mbah, ndak nemu nih datanya.. lapor dex aja.." }

  set connecta [::http::geturl http://www.livescore.com/worldcup/group-$text/]
  set filesa [::http::data $connecta]
  ::http::cleanup $filesa

set la [regexp -all -inline -- {<td class="num">1</td> <td class="cty"> <a href="/worldcup/team-.*?/">(.*?)</a> </td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td class="ls">(.*?)</td> </tr> <tr class=""> <td class="col">&nbsp;</td> <td class="num">2</td> <td class="cty"> <a href="/worldcup/team-.*?/">(.*?)</a> </td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td class="ls">(.*?)</td> </tr> <tr class="even"> <td class="col">&nbsp;</td> <td class="num">3</td> <td class="cty"> <a href="/worldcup/team-.*?/">(.*?)</a> </td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td class="ls">(.*?)</td> </tr> <tr class=""> <td class="col">&nbsp;</td> <td class="num">4</td> <td class="cty"> <a href="/worldcup/team-.*?/">(.*?)</a> </td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td>(.*?)</td> <td class="ls">(.*?)</td> </tr> </table> </table>} $filesa] 
if {[llength $la] != 0} {

     foreach {black aa bb cc dd ee ff gg hh ii aa1 bb1 cc1 dd1 ee1 ff1 gg1 hh1 ii1 aa2 bb2 cc2 dd2 ee2 ff2 gg2 hh2 ii2 aa3 bb3 cc3 dd3 ee3 ff3 gg3 hh3 ii3} $la {
         set aa [string trim $aa " \n"]
         set bb [string trim $bb " \n"]
         set cc [string trim $cc " \n"]
         set dd [string trim $dd " \n"]
         set ee [string trim $ee " \n"]
         set ff [string trim $ff " \n"]
         set gg [string trim $gg " \n"]
         set hh [string trim $hh " \n"]
         set ii [string trim $ii " \n"]

         set aa1 [string trim $aa1 " \n"]
         set bb1 [string trim $bb1 " \n"]
         set cc1 [string trim $cc1 " \n"]
         set dd1 [string trim $dd1 " \n"]
         set ee1 [string trim $ee1 " \n"]
         set ff1 [string trim $ff1 " \n"]
         set gg1 [string trim $gg1 " \n"]
         set hh1 [string trim $hh1 " \n"]
         set ii1 [string trim $ii1 " \n"]

         set aa2 [string trim $aa2 " \n"]
         set bb2 [string trim $bb2 " \n"]
         set cc2 [string trim $cc2 " \n"]
         set dd2 [string trim $dd2 " \n"]
         set ee2 [string trim $ee2 " \n"]
         set ff2 [string trim $ff2 " \n"]
         set gg2 [string trim $gg2 " \n"]
         set hh2 [string trim $hh2 " \n"]
         set ii2 [string trim $ii2 " \n"]

         set aa3 [string trim $aa3 " \n"]
         set bb3 [string trim $bb3 " \n"]
         set cc3 [string trim $cc3 " \n"]
         set dd3 [string trim $dd3 " \n"]
         set ee3 [string trim $ee3 " \n"]
         set ff3 [string trim $ff3 " \n"]
         set gg3 [string trim $gg3 " \n"]
         set hh3 [string trim $hh3 " \n"]
         set ii3 [string trim $ii3 " \n"]


         regsub -all {<.+?>} $aa {} aa
         regsub -all {<.+?>} $bb {} bb
         regsub -all {<.+?>} $cc {} cc
         regsub -all {<.+?>} $dd {} dd
         regsub -all {<.+?>} $ee {} ee
         regsub -all {<.+?>} $ff {} ff
         regsub -all {<.+?>} $gg {} gg
         regsub -all {<.+?>} $hh {} hh
         regsub -all {<.+?>} $ii {} ii

         regsub -all {<.+?>} $aa1 {} aa1
         regsub -all {<.+?>} $bb1 {} bb1
         regsub -all {<.+?>} $cc1 {} cc1
         regsub -all {<.+?>} $dd1 {} dd1
         regsub -all {<.+?>} $ee1 {} ee1
         regsub -all {<.+?>} $ff1 {} ff1
         regsub -all {<.+?>} $gg1 {} gg1
         regsub -all {<.+?>} $hh1 {} hh1
         regsub -all {<.+?>} $ii1 {} ii1

         regsub -all {<.+?>} $aa2 {} aa2
         regsub -all {<.+?>} $bb2 {} bb2
         regsub -all {<.+?>} $cc2 {} cc2
         regsub -all {<.+?>} $dd2 {} dd2
         regsub -all {<.+?>} $ee2 {} ee2
         regsub -all {<.+?>} $ff2 {} ff2
         regsub -all {<.+?>} $gg2 {} gg2
         regsub -all {<.+?>} $hh2 {} hh2
         regsub -all {<.+?>} $ii2 {} ii2

         regsub -all {<.+?>} $aa3 {} aa3
         regsub -all {<.+?>} $bb3 {} bb3
         regsub -all {<.+?>} $cc3 {} cc3
         regsub -all {<.+?>} $dd3 {} dd3
         regsub -all {<.+?>} $ee3 {} ee3
         regsub -all {<.+?>} $ff3 {} ff3
         regsub -all {<.+?>} $gg3 {} gg3
         regsub -all {<.+?>} $hh3 {} hh3
         regsub -all {<.+?>} $ii3 {} ii3


putserv "PRIVMSG $nick : \[\002$aa\002\] Bermain: $bb - Menang: $cc - Drew: $dd - Kalah: $ee - Goal: $ff - Bunuhdiri: $gg - GD: $hh - Score: $ii"
putserv "PRIVMSG $nick : \[\002$aa1\002\] Bermain: $bb1 - Menang: $cc1 - Drew: $dd1 - Kalah: $ee1 - Goal: $ff1 - Bunuhdiri: $gg1 - GD: $hh1 - Score: $ii1"
putserv "PRIVMSG $nick : \[\002$aa2\002\] Bermain: $bb2 - Menang: $cc2 - Drew: $dd2 - Kalah: $ee2 - Goal: $ff2 - Bunuhdiri: $gg2 - GD: $hh2 - Score: $ii2"
putserv "PRIVMSG $nick : \[\002$aa3\002\] Bermain: $bb3 - Menang: $cc3 - Drew: $dd3 - Kalah: $ee3 - Goal: $ff3 - Bunuhdiri: $gg3 - GD: $hh3 - Score: $ii3"


		}
	}

}


bind pub - !pdstats msg_pdstats
proc msg_pdstats {nick uhost hand chan text} {
  set namateam [string tolower $text]
  set connect [::http::geturl http://www.livescore.com/worldcup/team-$namateam/]
  set files [::http::data $connect]
  ::http::cleanup $files


set l [regexp -all -inline -- { .*?<td class="tcenter" colspan="6">Wins: <strong>(.*?)</strong>(.*?)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Draws: <strong>(.*?)</strong>(.*?)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Losses: <strong>(.*?)</strong>(.*?)</td>.*?Coach</th></tr> <tr> <td class="nb"></td> <td class="nm"><strong>(.*?)</strong></td> } $files]

if {[llength $l] != 0} {

     foreach {black a b c d e f g} $l {

         set a [string trim $a " \n"]
         set b [string trim $b " \n"]
         set c [string trim $c " \n"]
         set d [string trim $d " \n"]
         set e [string trim $e " \n"]
         set f [string trim $f " \n"]
         set g [string trim $g " \n"]

         regsub -all {<.+?>} $a {} a
         regsub -all {<.+?>} $b {} b
         regsub -all {<.+?>} $c {} c
         regsub -all {<.+?>} $d {} d
         regsub -all {<.+?>} $e {} e
         regsub -all {<.+?>} $f {} f
         regsub -all {<.+?>} $g {} g



putserv "PRIVMSG $chan :\[\002$text\002\] : Sejak 2012 Record Kenegaraan Wins: $a $b, Draws: $c $d, Losses: $e $f - Coach: $g"}


		} else { putserv "PRIVMSG $chan :lapor mbah, untuk $text ndak nemu nih datanya.. nulis negara nya yang bener dong ah.." }

}



############################## komplikasi

bind pub - !pd msg_pd
proc msg_pd {nick uhost hand chan text} {
set vs1 ""
set vs2 "" 
set awalan ""
set akhiran ""
                set vs1 [lindex $text 0]
                set vs2 [lindex $text 2 end]

                set lewat1 ""
                set lewat2 ""

        
                if {$vs1 == ""} {return} else { set lewat1 1 }
		if {$vs2 == ""} {return} else { set lewat2 1 }



                if {$lewat1 == 1} {
                if {$lewat2 == 1} {


  set connect [::http::geturl http://www.livescore.com/worldcup2018/]
  set files [::http::data $connect]
  ::http::cleanup $files

set vs1 [string tolower $vs1] 
set vs2 [string tolower $vs2]
set awalan [string totitle $vs1]
set akhiran [string totitle $vs2]
set lawan [cleanthisstring $vs1-vs-$vs2]
set l [regexp -all -inline -- [subst -nocommands -nobackslashes {<tr class="even"> <td class="fd"> FT </td> <td class="fh"> $awalan </td> <td class="fs"> <a href="/worldcup/match/(.*?)">(.*?)</a> </td> <td class="fa"> $akhiran </td> </tr>}] $files]

if {[llength $l] != 0} {

     foreach {black a b} $l {

         set a [string trim $a " \n"]
         set b [string trim $b " \n"]
#         set c [string trim $c " \n"]

         regsub -all {<.+?>} $a {} a
         regsub -all {<.+?>} $b {} b
#         regsub -all {<.+?>} $c {} c




###	putserv "PRIVMSG $chan :\[\002 $awalan vs $akhiran\002\] Score: $b"


############################ selesai check hal berikut


	} 

############################# check hal berikut
set nahini [cleanthisstring $a]
set jadiurlnya "http://www.livescore.com/worldcup/match/[subst -nocommands -nobackslashes $nahini]"
  set connectx [::http::geturl $jadiurlnya ]
  set filesx [::http::data $connectx]
  ::http::cleanup $filesx
set lx [regexp -all -inline -- { .*?<span class="league"> <span class="left"> <a href="/worldcup/.*?/"><strong>Group (.*?)</strong></a> </span> <span class="right">(.*?)</span> </span> <span class="date">(.*?)</span> </th>.*?<th colspan="3">referee :</th> <th class="tcenter">spectators :</th> </tr> <tr> <td></td> <td colspan="2"> (.*?) </td> <td class="tright pr4">(.*?)</td> </tr> <tr> <th colspan="4" class="title">match details.*?} $filesx]
if {[llength $lx] != 0} {

     foreach {black aa bb cc dd ee} $lx {

         set aa [string trim $aa " \n"]
         set bb [string trim $bb " \n"]
         set cc [string trim $cc " \n"]
         set dd [string trim $dd " \n"]
         set ee [string trim $ee " \n"]

         regsub -all {<.+?>} $aa {} aa
         regsub -all {<.+?>} $bb {} bb
         regsub -all {<.+?>} $cc {} cc
         regsub -all {<.+?>} $dd {} dd
         regsub -all {<.+?>} $ee {} ee





        putserv "PRIVMSG $chan :\[\002 $awalan vs $akhiran\002\]  Score: $b - Group: $aa (Ketik !pdgroup $aa untuk info lebih lanjut)- Stadium: $bb - Tanggal: $cc - Wasit: $dd - Penonton: $ee - Silahkan ketik !pdstats $awalan atau !pdstats $akhiran untuk info lainnya"
        }
}



} else { putserv "PRIVMSG $nick : hmm.. kayaknya kebalik vs nya ... atau data tidak ditemukan om... " }

	  }
	}

}


proc cleanthisstring {input} { 
  regsub -all -- {<(.+?)>} $input { } input 
  while {[string match "*  *" $input ]} { 
    regsub -all -- {  } $input " " input 
  } 
  return $input 
} 
