;;;;Buzz-Zyrus SoulFly Multi-Gamer by d33j4y™  ©2010 EvolutionScriptz d0t c0m;;;;
;;;;;;;;;;;;Evolution Scriptz Website http://www.evolutionscriptz.com;;;;;;;;;;;;
;;;;;;;;;;;;;;;;Weather Addon v2.0 by err0r - http://www.tg007.net;;;;;;;;;;;;;;;

;;; Use .w <location/zip> ;;;

menu channel {
  Weather Options
  .$iif($istok(%Weatherstore.Log,$chan,44),$style(1)) Weather $replace($mid(#,3),\b,$chr(32)) : $iif($istok(%Weatherstore.Log,$chan,44),set %Weatherstore.Log $remtok(%Weatherstore.Log,$chan,1,44),set %Weatherstore.Log $addtok(%Weatherstore.Log,$chan,44))
  .Weather Settings
  ..Clear Log : hfree weather | $iif($exists(weatherhash.txt),/remove -d weatherhash.txt) | hmake weather 50
  ..View Log : weatherlog
  -
}
on *:start: { hmake weather 50 |  if ($exists(weatherhash.txt)) { hload weather weatherhash.txt } }
on *:exit: { hfree weather }
on *:text:*:#: {
  var %text $regsubex($1-, /\[(?:style\x20.*?|/style)\]/gi,$null)
  tokenize 32 %text
  if ($1 == .w) && (!%flood.ck) && ($istok(%Weatherstore.Log,$chan,44)) {
    set -u3 %flood.ck on
    if (!$2) && (!$hget(weather,$address($nick,1))) { raw notice $chan $nick Sorry $nick there is no weather information saved for you. Please use .w <location/zip> | halt }
    if (!$2) && ($hget(weather,$address($nick,1))) { set %weather.search $hget(weather,$address($nick,1)) }
    if ($2) { set %weather.search $2- | hadd -m weather $address($nick,1) $2- }
    hsave -o weather weatherhash.txt | set %weather.chan $chan | getweather
  }
}
alias getweather { write -c weather.txt | sockclose weather | set %weather.check 1 | sockopen weather search.yahoo.com 80 }
alias converttemp {
  if ($right($1,1) == f) { return $round($calc((($remove($1,f) - 32) * 5) / 9),1) $+ C } 
  else { return $round($calc(($remove($1),c) * 1.8) + 32),1) $+ F }
}
on *:sockopen:weather:{
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -n $sockname GET /search?p=weather+ $+ $replace(%weather.search,$chr(32),+,$chr(44),$chr(37) $+ 2C) HTTP/1.1
  sockwrite -n $sockname HOST: search.yahoo.com
  sockwrite -n $sockname CONNECTION: Keep-alive
  sockwrite -n $sockname $str($crlf,2)
}
on *:sockread:weather: {
  if ($sockerr > 0) return
  var %weather
  sockread -f %weather
  if ($regex(%weather,/Extended <b>weather <\/b>forecast for (.*?)<\/a>/)) { set %weather.info $chr(91) $remove($regml(1),<b>,</b>) $chr(93) | inc %weather.check }
  if ($regex(%weather,/<\/div><p>Currently: (.*?)<\/p><p>(.*?)<\/p><p>/)) { set %weather.info %weather.info Today: $remove($regml(1),&deg;) / $converttemp($remove($regml(1),&deg;)) - $regml(2) | inc %weather.check }
  if ($regex(%weather,/<p>Tomorrow<\/p><p>(.*?)<\/p><p>(.*?) \| (.*?)<\/p>/)) { set %weather.info %weather.info -- Tomorrow: $regml(1) - High: $remove($regml(2),&deg;) / $converttemp($remove($regml(2),&deg;)) - Low: $remove($regml(3),&deg;) / $converttemp($remove($regml(3),&deg;)) }

  if (%weather == 0) || (%weather.check = 4) {
    sockclose $sockname
    .msg %weather.chan $iif(%weather.info,$v1,Search for $replace(%weather.search,$chr(37) $+ 20,$chr(32)) was not successful. Please refine your search.)
    unset %weather.*
  }
}
alias weatherlog {
  if (!$window(@weatherlog)) { /window -blk -t2,21 +benstx @weatherlog verdana 11 }
  clear @weatherlog | aline @weatherlog $chr(9) Address $chr(9) Weather Search | aline @weatherlog $chr(160)
  %hh = 1 | %hhn = $hget(weather, 0).item
  while (%hh <= %hhn) { aline -p @weatherlog $+(%hh,.) $chr(9) $hget(weather,%hh).item $chr(9) $hget(weather,%hh).data | inc %hh  }
}
