# weatherbot.irc: a weather bot for epic # # written by nsx (jburks@gmail.com) # # commands this script responds to (msg or notice): # # .wz: # Display current conditions and a short forecast. Location name, # ZIP code (for US locations) or weather code may be used. # # flags: # -d save defaults (flags and location name) # -n display non-US units # -o omit forecast # -r remove defaults # -s single-line output # -u display US units # -v verbose output # # .wzc: # Display weather codes for location names which match the provided # search string. # # .wzf: # Display (in private msg or notice) an 8-day forecast. # # flags: # -d save defaults (flags and location name) # -n display non-US units # -r remove defaults # -u display US units # # .wzi: # Display a location's local time, geographic coordinates, sunrise, # sunset, and weather station location. # # flags: # -d save defaults (location name) # -r remove defaults # # /set variables this script uses: # # WEATHER_NONUS_UNITS: # Determines when non-US units will be displayed. May be set to # ON, OFF, or NONUS (non-US units will be used only for non-US # locations). This config variable is overridden by the command # options -n and -u. # # WEATHER_US_UNITS: # Determines when standard units will be displayed. May be set to # ON, OFF, or US (standard units will be used only for US # locations). This config variable is overridden by the command # options -n and -u. # # WEATHER_SEARCH_CACHE: # Turns on or off caching of location lookups and location search # results. This affects .wz, .wzf, and .wzi when location names # are used instead of weather or ZIP codes. It's probably a good # idea to leave this on. # # # $Id: weatherbot.irc,v 1.72 2008-10-27 08:30:25 nsx Exp $ # if (word(2 $loadinfo()) != [pf]) { load -pf $word(1 $loadinfo()); return; }; @weather_user_file = [weatherusers.conf]; # partner id and key # visit http://www.weather.com/services/xmloap.html to sign up @partner_id = [xxxxxxxxxx]; @partner_key = [xxxxxxxxxxxxxxxx]; # weather.com's name servers seem to get pretty hammered. DNS requests # frequently time out, and if they do succeed, they usually take several # seconds. The TTL on the A record for xoap.weather.com is only 60 seconds, # so that doesn't help things, either. So, to prevent some serious latency # and reliability problems, we only look this host up occasionally, instead # of looking it up every time we connect. @weather_host = [xoap.weather.com]; @weather_ip = nametoip($weather_host); if (weather_ip == []) { xecho -b 4ERROR: unable to resolve host $weather_host; xecho -b 4ERROR: weather script not loaded!; return; }; if (!timerctl(REFNUM wdns)) { ^timer -refnum wdns -rep -1 7200 { @:new_weather_ip = nametoip($weather_host); if (new_weather_ip != []) { ^on ^dcc_raw -"% $weather_ip e 80"; ^on ^dcc_raw ^"% $new_weather_ip e 80"; @weather_ip = new_weather_ip; }; }; }; # temporary global variables @search_vars = [flags userflags servernum command target searchstring userhost index search_data]; @weather_vars = [error_count flags servernum command target locid weather_data fnstart]; # config variables @WEATHER_NONUS_UNITS = [NONUS]; @WEATHER_US_UNITS = [US]; @WEATHER_SEARCH_CACHE = [ON]; xdebug +new_math; alias clean_up_ccvars (fd) { ^assign -loc_dnam[$fd]; ^assign -cc_lsup[$fd]; ^assign -cc_tmp[$fd]; ^assign -cc_flik[$fd]; ^assign -cc_t[$fd]; ^assign -cc_bar_r[$fd]; ^assign -cc_bar_d[$fd]; ^assign -cc_wvel[$fd]; ^assign -cc_wdir[$fd]; ^assign -cc_gust[$fd]; ^assign -cc_hmid[$fd]; ^assign -cc_vis[$fd]; ^assign -cc_uv_i[$fd]; ^assign -cc_uv_t[$fd]; ^assign -cc_dewp[$fd]; ^assign -cc_moon_phase[$fd]; ^assign -loc_sunr[$fd]; ^assign -loc_suns[$fd]; }; alias clean_up_forecast_vars (fd, dayf) { ^assign -fnstart[$fd]; ^assign -loc_dnam[$fd]; ^assign -dayf_lsup[$fd]; @:i = 0; while (i <= dayf) { ^assign -dayf_hi[$i][$fd]; ^assign -dayf_low[$i][$fd]; fe (d n) part { ^assign -dayf_t[$i][$part][$fd]; ^assign -dayf_gust[$i][$part][$fd]; ^assign -dayf_ppcp[$i][$part][$fd]; ^assign -dayf_hmid[$i][$part][$fd]; ^assign -dayf_name[$i][$part][$fd]; ^assign -dayf_wdir[$i][$part][$fd]; ^assign -dayf_wvel[$i][$part][$fd]; }; @:i++; }; }; alias clean_up_locinfo_vars (fd) { ^assign -loc_dnam[$fd]; ^assign -loc_tm[$fd]; ^assign -loc_lat[$fd]; ^assign -loc_lon[$fd]; ^assign -loc_sunr[$fd]; ^assign -loc_suns[$fd]; ^assign -loc_zone[$fd]; ^assign -cc_obst[$fd]; }; alias clean_up_search_vars (fd, host) { fe ($search_vars) search_var { ^assign -${search_var}[$fd]; }; ^on ^dcc_raw -"$fd $host d *"; ^on ^dcc_raw -"$fd $host d **"; ^on ^dcc_raw -"$fd $host d **" ; ^on ^dcc_raw -"$fd $host c"; }; alias clean_up_weather_vars (fd, host) { fe ($weather_vars) weather_var { ^assign -${weather_var}[$fd]; }; ^on ^dcc_raw -"$fd $host c"; ^on ^dcc_raw -"$fd $host d *"; ^on ^dcc_raw -"$fd $host d **"; ^on ^dcc_raw -"$fd $host d **"; }; alias do_search (flags, command, sender, target, searchstring) { if (!ischannel($target)) { @:target = sender; }; @:servernum = servernum(); if (searchstring == []) { @wzc_usage($servernum $command $target); return; }; @search_location($servernum $command $target $flags NULL NULL $searchstring); }; # flags are as follows: # # c: display current conditions # d: save location name # f: display forecast # i: display location information # n: display non-US units # o: omit weather forecast # s: single-line output # u: display US units # v: verbose output # alias do_weather (flags, wcmd, command, sender, target, args) { @:servernum = servernum(); if (!ischannel($target)) { @:target = sender; } elsif (index(f $flags) > -1) { @:target = sender; @:command = [NOTICE]; }; @getopt(); while (:option = getopt(:optopt :optarg "dhnorsuv" $args)) { switch ($option) { (d) { @:userflags #= [d]; }; (h) { if (index(c $flags) > -1) { @wz_usage($servernum $command $target); } elsif (index(f $flags) > -1) { @wzf_usage($servernum $command $target); } elsif (index(i $flags) > -1) { @wzi_usage($servernum $command $target); } else { xquote -s $servernum $command $target :no help available for this command; }; return; }; (n) { @:userflags #= [n]; }; (o) { if (index(c $flags) > -1) { @:userflags #= [o]; } else { xquote -s $servernum $command $target :error: -o is an invalid option; @getopt(); return; }; }; (r) { if (index(d $userflags) > -1) { xquote -s $servernum $command $target :error: -d and -r are mutually exclusive; return; }; @:umask = remove_user_location($sender!$userhost() $flags); if (umask == -1) { xquote -s $servernum $command $target :error: no defaults found; } else { xquote -s $servernum $command $target :defaults for $umask removed; }; return; }; (s) { if (index(c $flags) > -1) { @:userflags #= [s]; } else { xquote -s $servernum $command $target :error: -s is an invalid option; @getopt(); return; }; }; (u) { @:userflags #= [u]; }; (v) { if (index(c $flags) > -1) { @:userflags #= [v]; } else { xquote -s $servernum $command $target :error: -v is an invalid option; @getopt(); return; }; }; (!) { xquote -s $servernum $command $target :error: -$optopt is an invalid option; @getopt(); return; }; (-) { xquote -s $servernum $command $target :error: option -$optopt requires an argument; @getopt(); return; }; }; }; @:optarg = left(${@optarg - 1} $optarg); if (index(d $userflags) > -1 && optarg != []) { if (iszip($optarg) || islocid($optarg)) { @:umask = save_user_location($sender!$userhost() $flags "$strip(d $userflags)" $optarg); xquote -s $servernum $command $target :defaults for $umask saved; return; } else { @search_location($servernum $command $target $flags $userflags $sender $optarg); return; }; }; if (optarg == []) { if (index(d $userflags) > -1) { xquote -s $servernum $command $target :error: no location provided; return; }; @:refnum = get_user_info($sender!$userhost()); if (refnum == -1) { xquote -s $servernum $command $target :error: No default location set. Use -d to set one. See $wcmd -h for more information.; return; }; if (flags == [c]) { @:optarg = weather_user_clocation[$refnum]; @:dflags = weather_user_cflags[$refnum]; } elsif (flags == [f]) { @:optarg = weather_user_flocation[$refnum]; @:dflags = weather_user_fflags[$refnum]; } elsif (flags == [i]) { @:optarg = weather_user_ilocation[$refnum]; }; if (optarg == []) { xquote -s $servernum $command $target :error: No default location set. Use -d to set one. See $wcmd -h for more information.; return; }; if (userflags == []) { @:flags #= dflags; } else { @:flags #= userflags; }; } elsif (userflags == []) { @:refnum = get_user_info($sender!$userhost()); if (refnum > -1) { if (flags == [c]) { @:flags #= weather_user_cflags[$refnum]; } elsif (flags == [f]) { @:flags #= weather_user_fflags[$refnum]; } elsif (flags == [i]) { @:flags #= weather_user_iflags[$refnum]; }; }; } else { @:flags #= userflags; }; if (islocid($optarg) || iszip($optarg)) { @get_weather($flags $servernum $command $target $optarg); } else { @search_location($servernum $command $target $flags NULL NULL $optarg); }; }; alias dump_conditions_data (fd) { if (index(v $flags[$fd]) > -1) { @:detailed_output = 1; } else { @:detailed_output = 0; }; if (index(s $flags[$fd]) > -1) { @:single_line_output = 1; } else { @:single_line_output = 0; }; if (single_line_output) { xquote -s $servernum[$fd] $command[$fd] $target[$fd] :$loc_dnam[$fd] \(updated $cc_lsup[$fd] ago\): $tolower($cc_t[$fd]), $format_temp($flags[$fd] $cc_tmp[$fd])${cc_tmp[$fd] != cc_flik[$fd] ? [, feels like $format_temp($flags[$fd] $cc_flik[$fd])] : []}, winds $format_wind($flags[$fd] $cc_wvel[$fd] $cc_wdir[$fd])${isnumber(b10 $cc_gust[$fd]) ? [, gusts up to $format_wind($flags[$fd] $cc_gust[$fd])] : []}, $cc_hmid[$fd] relative humidity, $format_distance($flags[$fd] $cc_vis[$fd]) visibility${detailed_output ? [, $format_temp($flags[$fd] $cc_dewp[$fd]) dewpoint, $format_pressure($flags[$fd] $cc_bar_r[$fd]) pressure \($cc_bar_d[$fd]\), UV index $cc_uv_i[$fd] $tolower(\($cc_uv_t[$fd]\), $loc_sunr[$fd] sunrise, $loc_suns[$fd] sunset, $cc_moon_phase[$fd] moon)] : []}; } else { xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Current conditions for $loc_dnam[$fd] \(updated $cc_lsup[$fd] ago\):; xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Conditions: $cc_t[$fd] Temperature: $format_temp($flags[$fd] $cc_tmp[$fd]) Feels like: $format_temp($flags[$fd] $cc_flik[$fd]); xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Humidity: $cc_hmid[$fd] Wind: $format_wind($flags[$fd] $cc_wvel[$fd] $cc_wdir[$fd]) Gusts: $format_wind($flags[$fd] $cc_gust[$fd]) Visibility: $format_distance($flags[$fd] $cc_vis[$fd]); if (detailed_output) { xquote -s $servernum[$fd] $command[$fd] $target[$fd] :UV Index: $cc_uv_i[$fd] \($cc_uv_t[$fd]\) Dewpoint: $format_temp($flags[$fd] $cc_dewp[$fd]) Pressure: $format_pressure($flags[$fd] $cc_bar_r[$fd]) \($cc_bar_d[$fd]\); xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Sunrise: $loc_sunr[$fd] Sunset: $loc_suns[$fd] Moon: $cc_moon_phase[$fd] Station: $cc_obst[$fd]; }; }; if (index(o $flags[$fd]) == -1) { @flags[$fd] #= [f]; @get_forecast_data($fd); @:start = fnstart[$fd]; if (dayf_t[$start][d][$fd] == [N/A] || dayf_hi[$start][$fd] == [N/A]) { xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Tonight: $dayf_t[$start][n][$fd]. Low of $format_temp($flags[$fd] $dayf_low[$start][$fd]). Winds $format_wind($flags[$fd] $dayf_wvel[$start][n][$fd] $dayf_wdir[$start][n][$fd]). Chance of precipitation $dayf_ppcp[$start][n][$fd]. Tomorrow: $dayf_t[${start + 1}][d][$fd]. High of $format_temp($flags[$fd] $dayf_hi[${start + 1}][$fd]). Winds $format_wind($flags[$fd] $dayf_wvel[${start + 1}][d][$fd] $dayf_wdir[${start + 1}][d][$fd]). Chance of precipitation $dayf_ppcp[${start + 1}][d][$fd].; } else { xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Today: $dayf_t[$start][d][$fd]. High of $format_temp($flags[$fd] $dayf_hi[$start][$fd]). Winds $format_wind($flags[$fd] $dayf_wvel[$start][d][$fd] $dayf_wdir[$start][d][$fd]). Chance of precipitation $dayf_ppcp[$start][d][$fd]. Tonight: $dayf_t[$start][n][$fd]. Low of $format_temp($flags[$fd] $dayf_low[$start][$fd]). Winds $format_wind($flags[$fd] $dayf_wvel[$start][n][$fd] $dayf_wdir[$start][n][$fd]). Chance of precipitation $dayf_ppcp[$start][n][$fd].; }; @clean_up_forecast_vars($fd 3); }; }; alias dump_forecast_data (fd) { @:i = fnstart[$fd]; @:output_line = []; xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Forecast for $loc_dnam[$fd] \(updated $dayf_lsup[$fd] ago\):; while (i <= 4) { @:finfo[$i][d] = [$chr(31)$dayf_name[$i][d][$fd]$chr(31): $dayf_t[$i][d][$fd]. High of $format_temp($flags[$fd] $dayf_hi[$i][$fd]). Winds $format_wind($flags[$fd] $dayf_wvel[$i][d][$fd] $dayf_wdir[$i][d][$fd]). Chance of precipitation $dayf_ppcp[$i][d][$fd].]; @:finfo[$i][n] = [$chr(31)$dayf_name[$i][n][$fd]$chr(31): $dayf_t[$i][n][$fd]. Low of $format_temp($flags[$fd] $dayf_low[$i][$fd]). Winds $format_wind($flags[$fd] $dayf_wvel[$i][n][$fd] $dayf_wdir[$i][n][$fd]). Chance of precipitation $dayf_ppcp[$i][n][$fd].]; @:i++; }; @:i = fnstart[$fd]; if (dayf_t[$i][d][$fd] == [N/A] || dayf_hi[$i][$fd] == [N/A]) { xquote -s $servernum[$fd] $command[$fd] $target[$fd] :$finfo[$i][n]; @:i++; }; while (i < 4) { xquote -s $servernum[$fd] $command[$fd] $target[$fd] :$finfo[$i][d] $finfo[$i][n]; @:i++; }; }; alias dump_locinfo_data (fd) { xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Location information for $loc_dnam[$fd]:; xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Latitude: $loc_lat[$fd] Longitude: $loc_lon[$fd] Weather Station: $cc_obst[$fd]; xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Local Time: $loc_tm[$fd] Time Zone: $loc_zone[$fd] Sunrise: $loc_sunr[$fd] Sunset: $loc_suns[$fd]; }; alias dump_search_cache (servernum, command, target, search_hash, search_string) { xquote -s $servernum $command $target :Possible results for $search_string \(cached\):; @:i = 0; while (i < (index[$search_hash] > 4 ? 4 : index[$search_hash])) { @:locname = locname[$search_hash][$i]; xquote -s $servernum $command $target :$locname: $locid[$encode($toupper($locname))]; @:i++; }; if (index[$search_hash] > 4) { xquote -s $servernum $command $target :Too many results -- output truncated. Please revise your search criteria.; }; }; alias fah2cel (temp) { stack push set FLOATING_POINT_MATH; stack push set FLOATING_POINT_PRECISION; ^set FLOATING_POINT_MATH ON; ^set FLOATING_POINT_PRECISION 16; @:result = trunc(1 ${(temp - 32) / 1.8}); stack pop set FLOATING_POINT_MATH; stack pop set FLOATING_POINT_PRECISION; return $result; }; alias format_distance (flags, miles) { if (!isnumber(b10 $miles)) { return $miles; }; @:i = 0; while (i < @flags) { switch ($mid($i 1 $flags)) { (n) { if (:formatted_distance == []) { @:formatted_distance = [$mi2km($miles 1) km]; } else { @:formatted_distance = [$formatted_distance \($mi2km($miles 1) km\)]; }; }; (u) { if (:formatted_distance == []) { @:formatted_distance = [$miles mi]; } else { @:formatted_distance = [$formatted_distance \($miles mi\)]; }; }; }; @:i++; }; return $formatted_distance; }; alias format_pressure (flags, inhg) { @:i = 0; while (i < @flags) { switch ($mid($i 1 $flags)) { (n) { if (:formatted_pressure == []) { @:formatted_pressure = [$inhg2kpa($inhg) kPa]; } else { @:formatted_pressure = [$formatted_pressure \($inhg2kpa($inhg) kPa\)]; }; }; (u) { if (:formatted_pressure == []) { @:formatted_pressure = [$inhg in Hg]; } else { @:formatted_pressure = [$formatted_pressure \($inhg in Hg\)]; }; }; }; @:i++; }; return $formatted_pressure; }; alias format_temp (flags, ftemp) { if (!isnumber(b10 $ftemp)) { return $ftemp; }; @:i = 0; while (i < @flags) { switch ($mid($i 1 $flags)) { (n) { if (:formatted_temp == []) { @:formatted_temp = [$fah2cel($ftemp)$chr(176)C]; } else { @:formatted_temp = [$formatted_temp \($fah2cel($ftemp)$chr(176)C\)]; }; }; (u) { if (:formatted_temp == []) { @:formatted_temp = [$ftemp$chr(176)F]; } else { @:formatted_temp = [$formatted_temp \($ftemp$chr(176)F\)]; }; }; }; @:i++; }; return $formatted_temp; }; alias format_wind (flags, mph, direction) { if (direction == [VAR]) { if (index(s $flags) > -1) { @:direction = [variable]; } else { @:direction = [Variable]; }; } elsif (direction == [CALM]) { if (index(s $flags) > -1) { return calm; } else { return Calm; }; } elsif (!isnumber(b10 $mph)) { return $mph; }; if (index(n $flags) > -1) { @:kph = mi2km($mph 0); if (index(f $flags) > -1) { @:r = kph % 5; if (r) { @:kph_start = kph - r; @:kph_end = kph_start + 5; }; }; }; if (index(u $flags) > -1 && index(f $flags) > -1) { @:r = mph % 5; if (r) { @:mph_start = mph - r; @:mph_end = mph_start + 5; }; }; @:i = 0; while (i < @flags) { switch ($mid($i 1 $flags)) { (n) { if (:formatted_velocity == []) { if (:kph_start == []) { @:formatted_velocity = [$kph km/h]; } else { @:formatted_velocity = [$kph_start to $kph_end km/h]; }; } else { if (:kph_start == []) { @:formatted_velocity = [$formatted_velocity \($kph km/h\)]; } else { @:formatted_velocity = [$formatted_velocity \($kph_start to $kph_end km/h\)]; }; }; }; (u) { if (:formatted_velocity == []) { if (:mph_start == []) { @:formatted_velocity = [$mph mph]; } else { @:formatted_velocity = [$mph_start to $mph_end mph]; }; } else { if (:mph_start == []) { @:formatted_velocity = [$formatted_velocity \($mph mph\)]; } else { @:formatted_velocity = [$formatted_velocity \($mph_start to $mph_end mph\)]; }; }; }; }; @:i++; }; if (:direction != []) { @:formatted_velocity = [$direction at $formatted_velocity]; }; return $formatted_velocity; }; alias get_conditions_data (fd) { @:weather_data = read_tag_content(weather 0 $weather_data[$fd]); @:cc_data = read_tag_content(cc 0 $weather_data); @:bar_data = read_tag_content(bar 0 $weather_data); @:wind_data = read_tag_content(wind 0 $cc_data); @:uv_data = read_tag_content(uv 0 $cc_data); @:moon_data = read_tag_content(moon 0 $cc_data); @:loc_data = read_tag_content(loc 0 $weather_data); @:cc_lsup = read_tag_content(lsup 0 $cc_data); @:loc_tz = read_tag_content(zone 0 $loc_data); @cc_obst[$fd] = read_tag_content(obst 0 $cc_data); @cc_lsup[$fd] = reformat_last_update_time($loc_tz $cc_lsup); @cc_tmp[$fd] = read_tag_content(tmp 0 $cc_data); @cc_flik[$fd] = read_tag_content(flik 0 $cc_data); @cc_t[$fd] = read_tag_content(t 0 $cc_data); @cc_bar_r[$fd] = read_tag_content(r 0 $bar_data); @cc_bar_d[$fd] = read_tag_content(d 0 $bar_data); @cc_wvel[$fd] = read_tag_content(s 0 $wind_data); @cc_wdir[$fd] = read_tag_content(t 0 $wind_data); @cc_gust[$fd] = read_tag_content(gust 0 $wind_data); @cc_hmid[$fd] = read_tag_content(hmid 0 $cc_data); @cc_hmid[$fd] #= isnumber(b10 $cc_hmid[$fd]) ? chr(37) : []; @cc_vis[$fd] = read_tag_content(vis 0 $cc_data); @cc_uv_i[$fd] = read_tag_content(i 0 $uv_data); @cc_uv_t[$fd] = read_tag_content(t 0 $uv_data); @cc_dewp[$fd] = read_tag_content(dewp 0 $cc_data); @cc_moon_phase[$fd] = read_tag_content(t 0 $moon_data); @loc_dnam[$fd] = read_tag_content(dnam 0 $loc_data); @loc_sunr[$fd] = read_tag_content(sunr 0 $loc_data); @loc_suns[$fd] = read_tag_content(suns 0 $loc_data); if (!islocid($locid[$fd])) { @loc_dnam[$fd] = before(\( $loc_dnam[$fd]); @loc_dnam[$fd] = left(${@loc_dnam[$fd] - 1} $loc_dnam[$fd]); }; }; alias get_forecast_data (fd) { @:weather_data = read_tag_content(weather 0 $weather_data[$fd]); @:loc_tz = read_tag_content(zone 0 $read_tag_content(loc 0 $weather_data)); @:loc_time = time() + loc_tz * 3600; @:loc_day = get_weekday($loc_time); @:loc_tod = loc_time % 86400; @:cc_tmp = read_tag_content(tmp 0 $read_tag_content(cc 0 $weather_data)); @:dayf_data = read_tag_content(dayf 0 $weather_data); @:dayf_lsup = read_tag_content(lsup 0 $dayf_data); @dayf_lsup[$fd] = reformat_last_update_time($loc_tz $dayf_lsup); @loc_dnam[$fd] = read_tag_content(dnam 0 $read_tag_content(loc 0 $weather_data)); @fnstart[$fd] = -1; if (!islocid($locid[$fd])) { @loc_dnam[$fd] = before(\( $loc_dnam[$fd]); @loc_dnam[$fd] = left(${@loc_dnam[$fd] - 1} $loc_dnam[$fd]); }; @:i = 0; while (day_data = read_tag_content(day $i $dayf_data)) { @:daytime_data = read_tag_content(part 0 $day_data); @:dayf_dwind_data = read_tag_content(wind 0 $daytime_data); @dayf_hi[$i][$fd] = read_tag_content(hi $i $dayf_data); @dayf_low[$i][$fd] = read_tag_content(low $i $dayf_data); @dayf_t[$i][d][$fd] = read_tag_content(t 0 $daytime_data); @dayf_wvel[$i][d][$fd] = read_tag_content(s 0 $dayf_dwind_data); @dayf_wdir[$i][d][$fd] = read_tag_content(t 0 $dayf_dwind_data); @dayf_gust[$i][d][$fd] = read_tag_content(gust 0 $dayf_dwind_data); @dayf_ppcp[$i][d][$fd] = read_tag_content(ppcp 0 $daytime_data); @dayf_ppcp[$i][d][$fd] #= isnumber(b10 $dayf_ppcp[$i][d][$fd]) ? chr(37) : []; @dayf_hmid[$i][d][$fd] = read_tag_content(hmid 0 $daytime_data); @dayf_hmid[$i][d][$fd] #= isnumber(b10 $dayf_hmid[$i][d][$fd]) ? chr(37) : []; @dayf_name[$i][d][$fd] = read_tag_attribute(day t $i $dayf_data); @:nighttime_data = read_tag_content(part 1 $day_data); @:dayf_nwind_data = read_tag_content(wind 0 $nighttime_data); @dayf_t[$i][n][$fd] = read_tag_content(t 0 $nighttime_data); @dayf_wvel[$i][n][$fd] = read_tag_content(s 0 $dayf_nwind_data); @dayf_wdir[$i][n][$fd] = read_tag_content(t 0 $dayf_nwind_data); @dayf_gust[$i][n][$fd] = read_tag_content(gust 0 $dayf_nwind_data)); @dayf_ppcp[$i][n][$fd] = read_tag_content(ppcp 0 $nighttime_data); @dayf_ppcp[$i][n][$fd] #= isnumber(b10 $dayf_ppcp[$i][n][$fd]) ? chr(37) : []; @dayf_hmid[$i][n][$fd] = read_tag_content(hmid 0 $nighttime_data); @dayf_hmid[$i][n][$fd] #= isnumber(b10 $dayf_hmid[$i][n][$fd]) ? chr(37) : []; @dayf_name[$i][n][$fd] = [$dayf_name[$i][d][$fd] night]; @:i++; }; if (dayf_name[0][d][$fd] == loc_day) { @fnstart[$fd] = 0; @dayf_name[0][d][$fd] = [Today]; @dayf_name[0][n][$fd] = [Tonight]; if (loc_tod > 64800) { @dayf_t[0][d][$fd] = [N/A]; }; } elsif (dayf_name[1][d][$fd] == loc_day) { if (loc_tod > 7200) { @fnstart[$fd] = 1; @dayf_name[1][d][$fd] = [Today]; @dayf_name[1][n][$fd] = [Tonight]; } else { @fnstart[$fd] = 0; @dayf_t[0][d][$fd] = [N/A]; @dayf_name[0][n][$fd] = [Tonight]; }; } else { @fnstart[$fd] = 0; @dayf_t[0][d][$fd] = [Today]; @dayf_name[0][n][$fd] = [Tonight]; }; if (dayf_hi[$fnstart[$fd]][$fd] != [N/A] && cc_tmp != [N/A] && dayf_hi[$fnstart[$fd]][$fd] < cc_tmp) { @dayf_hi[$fnstart[$fd]][$fd] = cc_tmp; }; if (dayf_low[$fnstart[$fd]][$fd] != [N/A] && cc_tmp != [N/A] && dayf_low[$fnstart[$fd]][$fd] > cc_tmp) { @dayf_low[$fnstart[$fd]][$fd] = cc_tmp; }; return 0; }; alias get_locinfo_data (fd) { @:weather_data = read_tag_content(weather 0 $weather_data[$fd]); @:loc_data = read_tag_content(loc 0 $weather_data); @loc_dnam[$fd] = read_tag_content(dnam 0 $loc_data); @loc_tm[$fd] = read_tag_content(tm 0 $loc_data); @loc_lat[$fd] = read_tag_content(lat 0 $loc_data); @loc_lon[$fd] = read_tag_content(lon 0 $loc_data); @loc_sunr[$fd] = read_tag_content(sunr 0 $loc_data); @loc_suns[$fd] = read_tag_content(suns 0 $loc_data); @loc_zone[$fd] = read_tag_content(zone 0 $loc_data); @cc_obst[$fd] = read_tag_content(obst 0 $read_tag_content(cc 0 $weather_data)); if (!islocid($locid[$fd])) { @loc_dnam[$fd] = before(\( $loc_dnam[$fd]); @loc_dnam[$fd] = left(${@loc_dnam[$fd] - 1} $loc_dnam[$fd]); }; }; alias get_search_data (fd) { @:search_hash = encode($toupper($searchstring[$fd])); @:search_data = read_tag_content(search 0 $search_data[$fd]); @:first_result = left(4 $read_tag_attribute(loc id 0 $search_data)); @:multiple_results = 0; @:i = 0; while (:locname[$i] = read_tag_content(loc $i $search_data)) { @:locid[$i] = read_tag_attribute(loc id $i $search_data); if (left(4 $locid[$i]) != first_result) { @:multiple_results = 1; }; if (WEATHER_SEARCH_CACHE == [ON]) { @locid[$encode($toupper($locname[$i]))] = locid[$i]; @locname[$search_hash][$i] = locname[$i]; }; @:i++; }; @index[$fd] = i; if (WEATHER_SEARCH_CACHE == [ON]) { @index[$search_hash] = i; @flags[$search_hash] = multiple_results ? [cm] : [c]; }; if (!multiple_results) { if (index(d $userflags[$fd]) > -1) { @:umask = save_user_location($sender[$fd]!$userhost[$fd] $flags[$fd] "$strip(d $userflags[$fd])" $locid[0]); xquote -s $servernum[$fd] $command[$fd] $target[$fd] :defaults for $umask saved; return; } elsif (index(cfi $flags[$fd]) > -1) { @get_weather($flags[$fd] $servernum[$fd] $command[$fd] $target[$fd] $locid[0]); return; }; }; xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Possible results for $searchstring[$fd]:; @:j = 0; while (j < (i > 4 ? 4 : i)) { xquote -s $servernum[$fd] $command[$fd] $target[$fd] :$locname[$j]: $locid[$j]; @:j++; }; if (i > 4) { xquote -s $servernum[$fd] $command[$fd] $target[$fd] :Too many results -- output truncated. Please revise your search criteria.; }; }; alias get_user_info (user) { fe ($weather_users) refnum { if (match($weather_user_mask[$refnum] $user)) { return $refnum; }; }; return -1; }; alias get_weather (flags, servernum, command, target, locid) { @:locid = toupper($locid); @:fd = connect($weather_ip 80); if (fd == []) { xquote -s $servernum $command $target :error: can't connect to the weather server; return 1; }; fe ($weather_vars) weather_var { eval @${weather_var}[$fd] = []; }; if (index(nu $flags) == -1) { if (WEATHER_NONUS_UNITS == [ON] || (WEATHER_NONUS_UNITS == [NONUS] && !iszip($locid) && left(2 $locid) != [US])) { @:flags #= [n]; }; if (WEATHER_US_UNITS == [ON] || (WEATHER_US_UNITS == [US] && (iszip($locid) || left(2 $locid) == [US]))) { @:flags #= [u]; }; }; if (index(c $flags) > -1) { @:dayf = 3; } else { @:dayf = 5; }; @flags[$fd] = flags; @servernum[$fd] = servernum; @command[$fd] = command; @target[$fd] = target; @locid[$fd] = locid; @error_count[$fd] = 0; @weather_data[$fd] = []; @:getcmd = [GET /weather/local/${locid}?cc=*&dayf=${dayf}&link=xoap&prod=xoap&par=${partner_id}&key=$partner_key HTTP/1.1]; ^on ^dcc_raw "$fd $weather_ip c" { @clean_up_weather_vars($0 $1); }; ^on ^dcc_raw "$fd $weather_ip d *" { @weather_data[$0] #= [$3-]; }; ^on ^dcc_raw "$fd $weather_ip d **" { @weather_data[$0] #= [$3-]; xquote -s $servernum[$0] $command[$0] $target[$0] :error:${locid[$0] == [] ? [] : [ $locid[$0]:]} $read_tag_content(err 0 $read_tag_content(error 0 $weather_data[$0])); if (index(c $flags[$0]) > -1) { @clean_up_ccvars($0); } elsif (index(f $flags[$0]) > -1) { @clean_up_forecast_vars($0 9); }; @clean_up_weather_vars($0 $1); ^dcc close raw $0; }; ^on ^dcc_raw "$fd $weather_ip d **" { @weather_data[$0] #= [$3-]; if (index(c $flags[$0]) > -1) { @get_conditions_data($0); @dump_conditions_data($0); @clean_up_ccvars($0); } elsif (index(f $flags[$0]) > -1) { if (get_forecast_data($0) > -1) { @dump_forecast_data($0); }; @clean_up_forecast_vars($0 9); } elsif (index(i $flags[$0]) > -1) { @get_locinfo_data($0); @dump_locinfo_data($0); @clean_up_locinfo_vars($0); }; @clean_up_weather_vars($0 $1); ^dcc close raw $0; }; msg =$fd $getcmd$chr(13); msg =$fd Host: $weather_host$chr(13); msg =$fd $chr(13); msg =$fd $chr(13); }; alias get_weekday (time) { @:day = floor(${time / 86400}) % 7; switch ($day) { (0) { @:dayname = [Thursday]; }; (1) { @:dayname = [Friday]; }; (2) { @:dayname = [Saturday]; }; (3) { @:dayname = [Sunday]; }; (4) { @:dayname = [Monday]; }; (5) { @:dayname = [Tuesday]; }; (6) { @:dayname = [Wednesday]; }; }; return $dayname; }; alias inhg2kpa (inhg) { stack push set FLOATING_POINT_MATH; stack push set FLOATING_POINT_PRECISION; ^set FLOATING_POINT_MATH ON; ^set FLOATING_POINT_PRECISION 16; @:result = trunc(2 ${inhg * 3.386388640341}); stack pop set FLOATING_POINT_MATH; stack pop set FLOATING_POINT_PRECISION; return $result; }; alias islocid (locid) { if (isalpha($left(1 $locid)) && isalpha($mid(1 1 $locid)) && isalpha($mid(2 1 $locid)) && isalpha($mid(3 1 $locid)) && isnumber(b10 $right(4 $locid))) { return 1; } else { return 0; }; }; alias iszip (locid) { if (strlen($tr(/ //$locid)) == 5 && isnumber(b10 $locid)) { return 1; } else { return 0; }; }; alias mi2km (miles, prec) { stack push set FLOATING_POINT_MATH; stack push set FLOATING_POINT_PRECISION; ^set FLOATING_POINT_MATH ON; ^set FLOATING_POINT_PRECISION 16; @:result = trunc($prec ${miles * 1.609344}); stack pop set FLOATING_POINT_MATH; stack pop set FLOATING_POINT_PRECISION; return $result; }; alias my_mask (user_host, method) { @:nickname = before(! $user_host); @:user_name = after(! $before(@ $user_host)); @:host_name = after(@ $user_host); @:host_dots = count(. $host_name); if (index(: $host_name) > -1) { @:domain_mask = [${before(2 : $host_name)}:*]; } elsif (host_dots == 3 && isnumber($tr(/.//$host_name))) { @:domain_mask = [${before(3 . $host_name)}.*]; } else { if (host_dots < 2) { @:domain_mask = host_name; } else { @:domain_mask = [*.${after(-2 . $host_name)}]; }; }; switch ($method) { (1) { return ${nickname}!*@*; }; (2) { return *!*@${host_name}; }; (3) { return *!${user_name}@${domain_mask}; }; (4) { return *!*@${domain_mask}; }; (*) { return; }; }; }; alias my_mktime (year, month, day, hour, minute, second) { switch ($month) { (1) { @:daystm = 0; }; (2) { @:daystm = 31; }; (3) { @:daystm = 58; }; (4) { @:daystm = 90; }; (5) { @:daystm = 120; }; (6) { @:daystm = 151; }; (7) { @:daystm = 181; }; (8) { @:daystm = 212; }; (9) { @:daystm = 243; }; (10) { @:daystm = 273; }; (11) { @:daystm = 304; }; (12) { @:daystm = 334; }; }; @:i = 1970; @:leapyrs = 0; while (i < year) { if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) { @:leapyrs++; }; @:i++; }; if (month > 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) { @:daystm++; }; @:utime = ((year - 1970) * 365 + leapyrs + daystm + day - 1) * 86400 + hour * 3600 + minute * 60 + second; return $utime }; alias read_next_tag_content (tag, buff) { @:begin_tag = (substr(<${tag}> $buff) == -1 ? substr("<${tag} " $buff) : substr(<${tag}> $buff)); if (begin_tag == -1) { return; }; @:taglen = index(> $rest($begin_tag $buff)); if (taglen == -1) { return; }; @:end_tag = substr( $rest(${begin_tag + taglen} $buff)); if (@end_tag) { return ${begin_tag + taglen + 1} ${end_tag - 1}; }; }; alias read_tag_attribute (tag, attrib, skip, buff) { while (skip > 0) { @:next_tag_content = read_next_tag_content($tag $buff); if (next_tag_content == []) { return; }; @:buff = rest(${word(0 $next_tag_content) + word(1 $next_tag_content)} $buff); @:skip--; }; @:next_tag = substr("<${tag} " $buff); if (next_tag == -1) { return; }; @:buff = rest($next_tag $buff); @:begin_attrib = substr(${attrib}= $buff); if (begin_attrib == -1) { return; }; return $before(""" $rest(${begin_attrib + @attrib + 2} $buff)); }; alias read_tag_content (tag, skip, buff) { @:next_tag_content = [0 0]; while (skip > -1) { @:buff = rest(${word(0 $next_tag_content) + word(1 $next_tag_content)} $buff); @:next_tag_content = read_next_tag_content($tag $buff); if (next_tag_content == []) { return; }; @:skip--; }; return $mid($word(0 $next_tag_content) $word(1 $next_tag_content) $buff); }; alias read_wuser_conf { @:fd = open($weather_user_file R); if (fd == []) { xecho -b error reading file $weather_user_file; return; }; @weather_users = []; @:refnum = 0; while ((:line = read($fd)) != []) { @weather_user_mask[$refnum] = word(0 $line); @weather_user_cflags[$refnum] = tr(/"//$word(1 $line)); @weather_user_clocation[$refnum] = tr(/"//$word(2 $line)); @weather_user_fflags[$refnum] = tr(/"//$word(3 $line)); @weather_user_flocation[$refnum] = tr(/"//$word(4 $line)); @weather_user_iflags[$refnum] = tr(/"//$word(5 $line)); @weather_user_ilocation[$refnum] = tr(/"//$word(6 $line)); push weather_users $refnum; @:refnum++; }; @close($fd); }; alias reformat_last_update_time (tz, lsup_formatted) { @:now = time(); @:lsup_month = before(/ $lsup_formatted); @:lsup_day = before(/ $after(/ $lsup_formatted)); @:lsup_year = [20] ## after(2 / $leftw(1 $lsup_formatted)); @:lsup_hour = before(: $word(1 $lsup_formatted)); @:lsup_min = after(: $word(1 $lsup_formatted)); if (word(2 $lsup_formatted) == [PM] && lsup_hour != 12) { @:lsup_hour += 12; } elsif (word(2 $lsup_formatted) == [AM] && lsup_hour == 12) { @:lsup_hour = 0; }; @:lsup_utime_loc = my_mktime($lsup_year $lsup_month $lsup_day $lsup_hour $lsup_min 0); @:lsup_utime_utc = lsup_utime_loc - (tz * 3600); @:lsup = now - lsup_utime_utc; if (lsup < 0) { @:lsup = 0; }; if (lsup >= 3600) { @:lsup_hrs = trunc(0 ${lsup / 3600}); @:lsup_mins = trunc(0 ${(lsup % 3600) / 60}); @:lsup_reformat = [$lsup_hrs ${lsup_hrs == 1 ? [hour] : [hours]}, $lsup_mins ${lsup_mins == 1 ? [minute] : [minutes]}]; } elsif (lsup >= 60) { @:lsup_mins = trunc(0 ${lsup / 60}); @:lsup_reformat = [$lsup_mins ${lsup_mins == 1 ? [minute] : [minutes]}]; } else { @:lsup_reformat = [less than 1 minute]; }; return $lsup_reformat; }; alias remove_user_location (user, cmd) { @:refnum = get_user_info($user); if (refnum > -1) { if (cmd == [c]) { ^assign -weather_user_cflags[$refnum]; ^assign -weather_user_clocation[$refnum]; } elsif (cmd == [f]) { ^assign -weather_user_fflags[$refnum]; ^assign -weather_user_flocation[$refnum]; } elsif (cmd == [i]) { ^assign -weather_user_iflags[$refnum]; ^assign -weather_user_ilocation[$refnum]; }; @write_wuser_conf(); return $weather_user_mask[$refnum]; } else { return -1; }; }; alias save_user_location (user, cmd, flags, location) { @:refnum = get_user_info($user); @:umask = my_mask($user 3); if (refnum == -1) { @:refnum = 0; while (findw($refnum $weather_users) > -1) { @:refnum++; }; push weather_users $refnum; }; if (cmd == [c] || weather_user_clocation[$refnum] == []) { @weather_user_cflags[$refnum] = tr(/"//$flags); @weather_user_clocation[$refnum] = location; }; if (cmd == [f] || weather_user_flocation[$refnum] == []) { @weather_user_fflags[$refnum] = tr(/osv"//$flags); @weather_user_flocation[$refnum] = location; }; if (cmd == [i] || weather_user_ilocation[$refnum] == []) { @weather_user_iflags[$refnum] = []; @weather_user_ilocation[$refnum] = location; }; @weather_user_mask[$refnum] = umask; @write_wuser_conf(); return $umask; }; alias search_location (servernum, command, target, flags, userflags, sender, location) { if (WEATHER_SEARCH_CACHE == [ON]) { @:search_hash = encode($toupper($location)); if (index(d $userflags) > -1 && locid[$search_hash] != []) { @:umask = save_user_location($sender!$userhost() $flags "$strip(d $userflags)" $locid[$search_hash]); xquote -s $servernum $command $target :defaults for $umask saved; return; } elsif (index(cfi $flags) > -1 && locid[$search_hash] != []) { @get_weather($flags $servernum $command $target $locid[$search_hash]); return; } elsif (index(c $flags[$search_hash]) > -1) { if (index(m $flags[$search_hash]) == -1 && index(d $userflags) > -1) { @:umask = save_user_location($sender!$userhost() $flags "$strip(d $userflags)" $locid[$encode($toupper($locname[$search_hash][0]))]); xquote -s $servernum $command $target :defaults for $umask saved; } elsif (index(m $flags[$search_hash]) == -1 && index(cfi $flags) > -1) { @get_weather($flags $servernum $command $target $locid[$encode($toupper($locname[$search_hash][0]))]); } else { @dump_search_cache($servernum $command $target $search_hash $location); }; return; }; }; @:getcmd = [GET /search/search?where=$urlencode($location) HTTP/1.1]; @:fd = connect($weather_ip 80); if (fd == []) { xquote -s $servernum $command $target :error: can't connect to the weather server; return 1; }; @flags[$fd] = flags; @userflags[$fd] = userflags; @servernum[$fd] = servernum; @command[$fd] = command; @sender[$fd] = sender; @target[$fd] = target; @searchstring[$fd] = location; @userhost[$fd] = userhost(); @index[$fd] = 0; @search_data[$fd] = []; ^on ^dcc_raw "$fd $weather_ip c" { @clean_up_search_vars($0 $1); }; ^on ^dcc_raw "$fd $weather_ip d *" { @search_data[$0] #= [$3-]; }; ^on ^dcc_raw "$fd $weather_ip d **" { @search_data[$0] #= [$3-]; @get_search_data($0); ^dcc close raw $0; @clean_up_search_vars($0 $1); }; ^on ^dcc_raw "$fd $weather_ip d **" { xquote -s $servernum[$0] $command[$0] $target[$0] :no location results for $searchstring[$0]; ^dcc close raw $0; }; msg =$fd $getcmd$chr(13); msg =$fd Host: $weather_host$chr(13); msg =$fd $chr(13); msg =$fd $chr(13); }; alias write_wuser_conf { if (fexist($weather_user_file) == 1) { if (unlink($weather_user_file)) { xecho -b error removing file $weather_user_file; return; }; }; @:fd = open($weather_user_file W); if (fd == []) { xecho -b error opening file $weather_user_file; return; }; fe ($weather_users) refnum { @write($fd $weather_user_mask[$refnum] "$weather_user_cflags[$refnum]" "$weather_user_clocation[$refnum]" "$weather_user_fflags[$refnum]" "$weather_user_flocation[$refnum]" "$weather_user_iflags[$refnum]" "$weather_user_ilocation[$refnum]"); }; @close($fd); }; alias wz_usage (servernum, command, target) { xquote -s $servernum $command $target :Usage: .wz [-dnorsuv] ; xquote -s $servernum $command $target :Description: Displays current conditions and a short forecast; xquote -s $servernum $command $target :Options:; xquote -s $servernum $command $target : -d save defaults \(location name and flags\); xquote -s $servernum $command $target : -n display non-US units; xquote -s $servernum $command $target : -o omit forecast; xquote -s $servernum $command $target : -r remove defaults; xquote -s $servernum $command $target : -s single-line output; xquote -s $servernum $command $target : -u display US units; xquote -s $servernum $command $target : -v verbose output; }; alias wzc_usage (servernum, command, target) { xquote -s $servernum $command $target :Usage: .wzc ; xquote -s $servernum $command $target :Description: Display weather codes for location names which match the provided search string.; }; alias wzf_usage (servernum, command, target) { xquote -s $servernum $command $target :Usage: .wzf [-dnru] ; xquote -s $servernum $command $target :Description: Displays \(in private\) an 8-day forecast; xquote -s $servernum $command $target :Options:; xquote -s $servernum $command $target : -d save defaults \(location name and flags\); xquote -s $servernum $command $target : -n display non-US units; xquote -s $servernum $command $target : -r remove defaults; xquote -s $servernum $command $target : -u display US units; }; alias wzi_usage (servernum, command, target) { xquote -s $servernum $command $target :Usage: .wzi [-dr] ; xquote -s $servernum $command $target :Description: Displays geographic information, including local time and coordinates; xquote -s $servernum $command $target :Options:; xquote -s $servernum $command $target : -d save defaults \(location name\); xquote -s $servernum $command $target : -r remove defaults; }; on ^dcc_raw ^"% $weather_ip e 80"; if (weather_serial == [] || !isnumber(b10 $weather_serial)) { @weather_serial = getserial(HOOK + 0); }; eval on #^general_privmsg $weather_serial "% % .wz" { @do_weather(c .wz PRIVMSG $0 $1); }; eval on #^general_privmsg ${weather_serial + 1} "% % .wz *" { @do_weather(c .wz PRIVMSG $0 $1 $3-); }; eval on #^general_notice ${weather_serial + 2} "% % .wz" { @do_weather(c .wz NOTICE $0 $1); }; eval on #^general_notice ${weather_serial + 3} "% % .wz *" { @do_weather(c .wz NOTICE $0 $1 $3-); }; eval on #^general_privmsg ${weather_serial + 4} "% % .wzc" { @do_search(! PRIVMSG $0 $1); }; eval on #^general_privmsg ${weather_serial + 5} "% % .wzc *" { @do_search(! PRIVMSG $0 $1 $3-); }; eval on #^general_notice ${weather_serial + 6} "% % .wzc" { @do_search(! NOTICE $0 $1); }; eval on #^general_notice ${weather_serial + 7} "% % .wzc *" { @do_search(! NOTICE $0 $1 $3-); }; eval on #^general_privmsg ${weather_serial + 8} "% % .wzf" { @do_weather(f .wzf PRIVMSG $0 $1); }; eval on #^general_privmsg ${weather_serial + 9} "% % .wzf *" { @do_weather(f .wzf PRIVMSG $0 $1 $3-); }; eval on #^general_notice ${weather_serial + 10} "% % .wzf" { @do_weather(f .wzf NOTICE $0 $1); }; eval on #^general_notice ${weather_serial + 11} "% % .wzf *" { @do_weather(f .wzf NOTICE $0 $1 $3-); }; eval on #^general_privmsg ${weather_serial + 12} "% % .wzi" { @do_weather(i .wzi PRIVMSG $0 $1); }; eval on #^general_privmsg ${weather_serial + 13} "% % .wzi *" { @do_weather(i .wzi PRIVMSG $0 $1 $3-); }; eval on #^general_notice ${weather_serial + 14} "% % .wzi" { @do_weather(i .wzi NOTICE $0 $1); }; eval on #^general_notice ${weather_serial + 15} "% % .wzi *" { @do_weather(i .wzi NOTICE $0 $1 $3-); }; on ^set "WEATHER_NONUS_UNITS *" { if ([$1] == []) { xecho -b Current value of WEATHER_NONUS_UNITS is $WEATHER_NONUS_UNITS; return; }; switch ($1) { (ON) { @WEATHER_NONUS_UNITS = [ON]; xecho -b Value of WEATHER_NONUS_UNITS set to ON; }; (OFF) { if (WEATHER_STANDARD_UNITS != [ON]) { xecho -b Value of WEATHER_NONUS_UNITS cannot be OFF if WEATHER_STANDARD_UNITS is not set to ON; return; }; @WEATHER_NONUS_UNITS = [OFF]; xecho -b Value of WEATHER_NONUS_UNITS set to OFF; }; (NONUS) { if (WEATHER_STANDARD_UNITS == [OFF]) { xecho -b Value of WEATHER_NONUS_UNITS cannot be NONUS if WEATHER_STANDARD_UNITS is set to OFF; return; }; @WEATHER_NONUS_UNITS = [NONUS]; xecho -b Value of WEATHER_NONUS_UNITS set to NONUS; }; (*) { xecho -b Value of WEATHER_NONUS_UNITS must be either ON, OFF, or NONUS; }; }; }; on ^set "WEATHER_SEARCH_CACHE *" { if ([$1] == []) { if (WEATHER_SEARCH_CACHE == [ON]) { xecho -b Current value of WEATHER_SEARCH_CACHE is ON; } else { xecho -b Current value of WEATHER_SEARCH_CACHE is OFF; }; return; }; switch ($1) { (ON) { @WEATHER_SEARCH_CACHE = [ON]; xecho -b Value of WEATHER_SEARCH_CACHE set to ON; }; (OFF) { @WEATHER_SEARCH_CACHE = [OFF]; xecho -b Value of WEATHER_SEARCH_CACHE set to OFF; }; (TOGGLE) { @WEATHER_SEARCH_CACHE = WEATHER_SEARCH_CACHE == [OFF] ? [ON] : [OFF]; xecho -b Value of WEATHER_SEARCH_CACHE set to $WEATHER_SEARCH_CACHE; }; (*) { xecho -b Value of WEATHER_SEARCH_CACHE must be either ON, OFF, or TOGGLE; }; }; }; on ^set "WEATHER_US_UNITS *" { if ([$1] == []) { xecho -b Current value of WEATHER_US_UNITS is $WEATHER_US_UNITS; return; }; switch ($1) { (ON) { @WEATHER_US_UNITS = [ON]; xecho -b Value of WEATHER_US_UNITS set to ON; }; (OFF) { if (WEATHER_METRIC_OUTPUT != [ON]) { xecho -b Value of WEATHER_US_UNITS cannot be OFF if WEATHER_NONUS_UNITS is not set to ON; return; }; @WEATHER_US_UNITS = [OFF]; xecho -b Value of WEATHER_US_UNITS set to OFF; }; (US) { if (WEATHER_METRIC_OUTPUT == [OFF]) { xecho -b Value of WEATHER_US_UNITS cannot be US if WEATHER_NONUS_UNITS is set to OFF; return; }; @WEATHER_US_UNITS = [US]; xecho -b Value of WEATHER_US_UNITS set to US; }; (*) { xecho -b Value of WEATHER_US_UNITS must be either ON, OFF, or US; }; }; }; @read_wuser_conf();