;-----------------------------;
;   Weather Reporter v2.0     ;
;     by [H]3rCuL3[S]         ;
;  http://www.morbidx.com/    ;
;-----------------------------;

;-- on load stuff --
on *:load: {
  if ($version < 5.61) { echo 4 -a *** Please use a higher version of mIRC.. You are currently using $version which is not compatible with Weather Reporter v2.0 ... | echo 4 -a *** You can download mIRC 5.61+ at http://www.mirc.com/ | echo 4 -a *** | echo 4 -a *** Unloaded script due to lower version of mIRC ... Visit http://www.morbidx.com for updates! | .unload -rs weather.txt | halt }
  else { echo 4 -a *** Loaded script! | echo 4 -a *** Weather Reporter v2.0 (Dialog Based) by [H]3rCuL3[S] - http://www.morbidx.com/ | echo 4 -a *** Please e-mail (Godsp33d@hotmail.com) if you have any questions or having problems with this addon! | echo 4 -a *** | echo 4 -a *** To get this thing work, type '/WEATHER <US ZIPCODE>' (without the quotes)... | echo 4 -a *** Note: US Zipcodes only!!!!!!! | halt }
}

;-- status and channel menu --
menu channel,status {
  Weather Reporter v2.0:
  .Check weather: weather $?="Enter a U.S. zipcode:"
  .-
  .Website: run http://www.morbidx.com
  .Email: run mailto:w0b@home.com
  .-
  .Check updates: http://www.morbidx.com
}

;-- weather dialog --
dialog weather {
  title ".:[weather reporter]:."
  size -1 -1 300 300
  button "Close",1, 115 275 75 20,ok
  box "Weather Reporter v2.0",2, 1 1 299 299
  edit "City, State",3, 10 20 280 20,read,center
  text "Condition:",4, 30 60 100 13
  edit "",5, 110 57 160 20,read
  text "Temperature:",6, 30 80 100 13
  edit "",7, 110 77 160 20,read
  text "Wind:",8, 30 100 100 13
  edit "",9, 110 97 160 20,read
  text "Dewpoint:",10, 30 120 100 13
  edit "",11, 110 117 160 20,read
  text "Rel. Humidity:",12, 30 140 100 13
  edit "",13, 110 137 160 20,read
  text "Visibility:",14, 30 160 100 13
  edit "",15, 110 157 160 20,read
  text "Barometer",16, 30 180 100 13
  edit "",17, 110 177 160 20,read
  text "Sunrise:",18, 30 200 100 13
  edit "",19, 110 197 160 20,read
  text "Sunset:",20, 30 220 100 13
  edit "",21, 110 217 160 20,read
  edit "Status...",22, 10 250 280 20,read,center
}

;-- weather alias --
alias weather { if ($1 !isnum) || ($2 != $null) || ($len($1) > 5) { echo 4 -a $sep Syntax: /weather <uszipcode> | halt } | if ($sock(weather) == weather) { echo 4 -a $sep Error: Weather is currently in use! | halt } | if ($dialog(weather) == $null) { dialog -m weather weather } | set %w.zc $1 $+ .html | sockopen weather www.weather.com 80 | did -i weather 2 1 Zipcode: $gettok(%w.zc,1,46) | did -i weather 3 1 Looking up zipcode ( $+ $gettok(%w.zc,1,46) $+ ) }

;-- socket events --
on *:sockopen:weather: { if ($dialog(weather) == $null) { dialog -m weather weather } | sockwrite -n weather GET /weather/us/zips/ $+ %w.zc }
on *:sockread:weather: {
  if ($dialog(weather) == $null) { dialog -m weather weather }
  sockread %w.temp | tokenize 32 %w.temp
  if ($left($remove($1-,$chr(44)),58) ==       <FONT FACE="Arial Helvetica Chicago Sans Serif" SIZE=3><B>) { set %W.cond $right($remove($1-,$chr(44)),$calc($len($1-) - 61)) | set %W.cond $left(%W.cond,$calc($len(%W.cond) - 15)) | if (No report !isin %W.cond) { did -i weather 5 1 %W.Cond } }
  if (<TITLE> isin $1-) && (%W.place == $null) { set %W.place $1- | if (zip and city search !isin %W.place) { did -i weather 3 1 $remove($remove($remove(%W.place,The Weather Channel -),<TITLE>),</TITLE>) } }
  if (No report !isin %W.cond) && (Temp: isin $1-) || (Wind: isin $1-) || (Dewpoint: isin $1-) || (Rel. Humidity: isin $1-) || (Visibility: isin $1-) || (Barometer: isin $1-) || (Sunrise: isin $1-) || (Sunset: isin $1-) { set %W.type $ifmatch }
  if (No report !isin %W.cond) && (<TD WIDTH=90><FONT FACE="Arial Helvetica Chicago Sans Serif" SIZE=2> isin $remove($1-,$chr(44))) {
    if (Temp: isin %w.type) { did -i weather 22 1 Looking up wind... | did -i weather 7 1 $replace($remove($gettok($1-,3,62),</font),&deg;,) }
    if (Wind: isin %w.type) { did -i weather 22 1 Looking up dewpoint... | did -i weather 9 1 $replace($remove($gettok($1-,3,62),</font),&deg;,) }
    if (Dewpoint: isin %w.type) { did -i weather 22 1 Looking up rel. humidity... | did -i weather 11 1 $replace($remove($gettok($1-,3,62),</font),&deg;,) }
    if (Rel. Humidity: isin %w.type) { did -i weather 22 1 Looking up visibility... | did -i weather 13 1 $replace($remove($gettok($1-,3,62),</font),&deg;,) }
    if (Visibility: isin %w.type) { did -i weather 22 1 Looking up barometer... | did -i weather 15 1 $replace($remove($gettok($1-,3,62),</font),&deg;,) }
    if (Barometer: isin %w.type) { did -i weather 22 1 Looking up sunrise... | did -i weather 17 1 $replace($remove($gettok($1-,3,62),</font),&deg;,) }
    if (Sunrise: isin %w.type) { did -i weather 22 1 Looking up sunset... | did -i weather 19 1 $replace($remove($gettok($1-,3,62),</font),&deg;,) }
    if (Sunset: isin %w.type) { did -i weather 22 1 Weather completed, please wait... | did -i weather 21 1 $replace($remove($gettok($1-,3,62),</font),&deg;,) }
    unset %w.type
  }
  if (</HTML> == $1-) { sockclose weather | if (zip and city search isin %w.place) { did -i weather 22 1 Unable to find Zip Code. | unset %w.place } | if (No Report isin %w.cond) { did -i weather 22 1 No report for that Zip Code. | unset %w.place } | did -i weather 22 1 End of weather report. | unset %w.* }
  :next
  write weather.txt $1-
}

;-- ctcp version --
ctcp *:*:*: { if ($1 == VERSION) { .ctcpreply $nick VERSION Weather Reporter by [H]3rCuL3[S] - Get it at http://www.morbidx.com/ } }

;-- on connect --
on *:connect: {
  if (dal.net isin $server) { join #Pinoy-Chat }
  if (woot.net isin $server) { join #Pinoy }
}

;-- on disconnect --
on *:disconnect: { unset %w.* }
