Advertisement
Guest User

weather-by-eq-runner-chromatic-paste

a guest
Oct 6th, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.35 KB | None | 0 0
  1.  
  2.  
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. ;;;;;; weather underground for mIRC ;;;;;;;;;;;;;;;;
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;by eqrunner ;;v5.3;;
  6.  
  7. /*
  8. -- REQUIRMENTS --
  9. - YOU MUST HAVE AN API CODE TO USE USE VERSION 5.0 AND ABOVE
  10. - Go to http://www.wunderground.com/weather/api/ and sign up for free.
  11. - Follow the steps to create a API Key ID.
  12. - When complete, Insert it into the code below in the 'Preperation' section set %wu_api
  13.  
  14. -- COMMANDS --
  15. !w or !weather [zipcode|city,state|city,country|airport] = will return weather current conditions.
  16. !current [zipcode|city,state|city,country|airport] = will return current conditions.
  17. !forecast [zipcode|city,state|city,country|airport] = will give detailed 3 day forecast (for us)
  18. !forecast[1-10] [zipcode|city,state|city,country|airport] = will send from 1 day up to 10 day forecast to $nick that requested. (to prevent chan flooding)
  19. !alerts [zipcode|city,state|city,country|airport] = will tell you if there are any weather alerts in your area.
  20. !alertinfo [zipcode|city,state|city,country|airport] = will send $nick the detailed report of alerts in said area
  21. !time [zipcode|city,state|city,country|airport] = will return current time.
  22. !almanac [zipcode|city,state|city,country|airport] = will return the record highs and lows.
  23.  
  24. -- REGISTER --
  25. Register - Each user can assign a default location with themself. So in the future they can use just the command ( !weather, or !forecast, or !alerts, etc)
  26. ![w|forecast|forecast5|alerts|alertinfo|time|current|almanac] REGISTER [zipcode|city,state|city,country|airport] = will link user to said default location
  27. ![w|forecast|forecast5|alerts|alertinfo|time|current|almanac] REGISTER [zipcode|city,state|city,country|airport] = will CHANGE users default if they already have registured.
  28. ![w|forecast|forecast5|alerts|alertinfo|time|current|almanac] REMOVE = will remove the users default location
  29. User can use any of the !commands to registure. !weather register 90210, will work just as well as !time register 90210
  30.  
  31. -- HELP --
  32. ![w|forecast|forecast5|alerts|alertinfo|time|current|almanac] [?|help] = Will message user the list of above commands just as they are written.
  33.  
  34. -- Switch --
  35. ![w|forecast|forecast5|alerts|alertinfo|time|current|almanac] [ON|OFF] = Will turn the script ON or OFF. Currently only set for Ops only.
  36.  
  37.  
  38. -- NOTES- -
  39. Notes from wunderground:
  40. We don't support old style abbreviations like Conn. for Connecticut, use CT
  41. If you are searching for an international city, try the name of the country or province
  42. Don't use provinces for non-us cities (ie: Vancouver, BC)
  43. Zipcodes only work in Canada, UK and the US
  44. */
  45.  
  46.  
  47. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  48. on *:CONNECT: {
  49. if ($hget(wu_reg) == $null) { hmake wu_reg 100 }
  50. if ($isfile(wu_reg.dat)) { hload wu_reg wu_reg.dat }
  51. }
  52. ON *:DISCONNECT: {
  53. if ($hget(wu_reg)) { hsave -o wu_reg wu_reg.dat }
  54. }
  55.  
  56. on $*:INPUT:#: {
  57. if ($regex($1,/^[!](w|weather|forecast|forecast5|alert|alerts|alertinfo|alertsinfo|time|current|almanac|a)/Si)) wunderground $1-
  58. }
  59.  
  60. on $*:text:/^[!](w|weather|forecast|forecast5|alert|alerts|alertinfo|alertsinfo|time|current|almanac|a)/Si:#: {
  61. wunderground $1-
  62. }
  63.  
  64. ;-----------------------------------------------------------------------------
  65. ; Preperation
  66. ;-----------------------------------------------------------------------------
  67.  
  68. alias wunderground {
  69. ;botabuse
  70. unset %wu_*
  71.  
  72. ;PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  73. ;--- Preperation. Sets up all the variables needed for the script ---
  74. set %wu_command $1
  75. set %wu_2 $2
  76. set %wu_location $2-
  77. set %wu_3 $3
  78. set %wu_3_long $3-
  79. set %wu_nick $nick
  80. set %wu_network $network
  81. set %wu_chan $chan
  82. set %wu_host api.wunderground.com
  83.  
  84.  
  85. ;APIKEYAPIKEYAPIKEYAPIKEYAPIKEYAPIKEYAPIKEYAPIKEYAPIKEYAPIKEY
  86. set %wu_api PUT YOUR API KEY HERE!!
  87. ;APIKEYAPIKEYAPIKEYAPIKEYAPIKEYAPIKEYAPIKEYAPIKEYAPIKEYAPIKEY
  88.  
  89.  
  90. ;PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  91. ;--- Registration Check. Checks to see if the $nick already has a 'default' location on file ---
  92. if ($2 == $null) {
  93. if ($hget(wu_reg,%wu_nick) != $null) {
  94. set %wu_location $hget(wu_reg,%wu_nick)
  95. }
  96. if ($hget(wu_reg,%wu_nick) == $null) {
  97. .notice $nick Please specify a location $1 [zipcode|city,state|city,country|airport]
  98. wu_cleanup
  99. }
  100. }
  101.  
  102. ;PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  103. ;--- Modify Registration and Help and ON/OFF Switch ---
  104. if ($2 != $null) {
  105. if (%wu_2 == register) && (%wu_3 != $null) {
  106. hadd -m wu_reg %wu_nick %wu_3_long
  107. .notice %wu_nick You are now linked to %wu_3_long
  108. set %wu_location $hget(wu_reg,%wu_nick)
  109. ;echo -s %wu_location
  110. }
  111. if (%wu_2 == remove) {
  112. hdel wu_reg %wu_nick
  113. .notice %wu_nick Your location association has been removed.
  114. wu_cleanup
  115. }
  116. ;;--- Checks to see if the $2 is an already registured nick. ----
  117. if ($hget(wu_reg,%wu_2) != $null) {
  118. set %wu_location $hget(wu_reg,%wu_2)
  119. }
  120. if (%wu_2 == ?) || (%wu_2 == help) {
  121. wu_help
  122.  
  123. }
  124. ;;;---Below is used to turn the script on or off, but only if user is an op of a channel ---
  125.  
  126. if (%wu_2 == on) || (%wu_2 == off) && (%wu_nick isop %wu_chan) {
  127. if (%wu_2 == on) {
  128. set $+(%,wunderground_,%wu_chan) ON
  129. .notice %wu_nick !weather script is now ON
  130. wu_cleanup
  131. halt
  132. }
  133. if (%wu_2 == off) {
  134. set $+(%,wunderground_,%wu_chan) OFF
  135. .notice %wu_nick !weather script is now OFF
  136. wu_cleanup
  137. halt
  138. }
  139. } ;end of %wu_on/off
  140.  
  141.  
  142. ;--- Default for a channel ---
  143. if ($2 == shoutdrive) && (%wu_network == iPocalypse) {
  144. set %wu_location 90046
  145. } ; end of Default for a channel
  146.  
  147. } ;end of ($2 != $null)
  148.  
  149. ;PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  150. ;--- Checks if wunderground is suppost to be OFF for the channel --
  151. if ($($+(%,wunderground_,%wu_chan),2) == OFF) {
  152. wu_cleanup
  153. halt
  154. }
  155.  
  156. ;PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  157. ;---Command Prep. Checks command to see which data file it will be pulling from depending on command entered ---
  158. ;NEW
  159. ;Reformats City, State to the corrected /State/City.xml
  160.  
  161. if ($chr(44) isin %wu_location) {
  162. ;set %wu_location_format $+(/,$remove($gettok(%wu_location,2,44),/,$gettok(%wu_location,1,44))
  163. var %wu_location_city $replace($gettok(%wu_location,1,44),$chr(32),$chr(95))
  164. var %wu_location_state $remove($gettok(%wu_location,2,44),$chr(32))
  165. ;echo -s %wu_location_city %wu_location_State
  166. set %wu_address $+(/,%wu_location_state,/,%wu_location_city)
  167.  
  168. ;echo -s %wu_address
  169. ;wu_cleanup
  170. ;halt
  171. }
  172. if ($chr(44) !isin %wu_location) {
  173. set %wu_address $replace(%wu_location,$chr(32),$chr(95))
  174. ;echo -s %wu_address
  175. ;wu_cleanup
  176. ;halt
  177. }
  178. ;/NEW
  179.  
  180. ;PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  181. ;-- Sets specific %wu_links depending on what is requested.
  182.  
  183. ;-- Weather --
  184. if (%wu_command == !w ) set %wu_command !weather
  185. if (%wu_command == !weather) || (%wu_command == !current) || (%wu_command == !time) {
  186. ;;OLD
  187. ;;set %wu_link $+(/auto/wui/geo/WXCurrentObXML/index.xml?query=,%wu_address)
  188. ;;set %wu_host api.wunderground.com
  189.  
  190. ;NEW
  191. ;Eample: set %wu_link $+(/api/154dfe245e155eee1/conditions/q/20721.xml)
  192. set %wu_link $+(/api/,%wu_api,/conditions/q/,%wu_address,.xml)
  193. }
  194. ;pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp
  195. ;-- Forecast --
  196. ;- Below finds out if it is a !forecast or a !forecast[1-10]. If there is a number,
  197. ; then it strips the number and sets %wu_command back to !forecast5 so remainder of the code
  198. ; works. and creates a %wu_forecast_count to be used after the sock closes.
  199.  
  200. if ($left(%wu_command,9) == !forecast) {
  201. if ($mid(%wu_command,10,0) > 0) {
  202. set %wu_forecast_count $remove(%wu_command,!forecast)
  203. ; ^ removes !forecast, leaving only the number
  204. if (%wu_forecast_count > 10) set %wu_forecast_count 10
  205. ; ^ If number is greater than 10. Changes it to 10. (no one wants 999 days of forecast)
  206. set %wu_command !forecast5
  207. ; ^ resets %wu_command back to !forecast5 so the rest of the code works.
  208. }
  209. }
  210.  
  211. if (%wu_command == !forecast) || (%wu_command == !forecast5) {
  212. ;;OLD
  213. ;;set %wu_link $+(/auto/wui/geo/ForecastXML/index.xml?query=,%wu_address)
  214. ;;set %wu_host www.wunderground.com
  215.  
  216. ;NEW
  217. set %wu_link $+(/api/,%wu_api,/forecast10day/q/,%wu_address,.xml)
  218. }
  219.  
  220. ;pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp
  221. ;-- Alerts --
  222. if (%wu_command == !alert) set %wu_command !alerts
  223. if (%wu_command == !alertsinfo) set %wu_command !alertinfo
  224. if (%wu_command == !alerts) || (%wu_command == !alertinfo) {
  225. ;;OLD
  226. ;;set %wu_link $+(/auto/wui/geo/AlertsXML/index.xml?query=,%wu_address)
  227. ;;set %wu_host www.wunderground.com
  228.  
  229. ;NEW
  230. set %wu_link $+(/api/,%wu_api,/alerts/q/,%wu_address,.xml)
  231. set %wu_a_count 0
  232. }
  233. ;pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp
  234. ;-- Almanac --
  235. ;if (%wu_command == !a) {
  236. ; set %wu_link $+(/api/,%wu_api,/almanac/q/,%wu_address,.xml)
  237. ;}
  238. if (%wu_command == !almanac) || (%wu_command == !a) {
  239. set %wu_link $+(/api/,%wu_api,/almanac/q/,%wu_address,.xml)
  240. }
  241. sockopen wunderground %wu_host 80
  242. ;echo -s LINK: %wu_link
  243. }
  244.  
  245. ;-----------------------------------------------------------------------------
  246. ;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  247. ; SOCKETS
  248. ;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  249. ;-----------------------------------------------------------------------------
  250.  
  251. on *:sockopen:wunderground: {
  252. ; OLD
  253. ;;sockwrite -n $sockname GET %wu_link XML/1.0
  254. ;;sockwrite -n $sockname GET %wu_link
  255. ;;sockwrite -n $sockname Host: %wu_host
  256.  
  257. ; NEW
  258. sockwrite -n $sockname GET %wu_link HTTP/1.1
  259. sockwrite -n $sockname Host: %wu_host
  260. sockwrite -n $sockname $crlf
  261.  
  262. }
  263.  
  264. ;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  265.  
  266. on *:sockread:wunderground: {
  267. sockread %wu_temp
  268. if ($regex(%wu_temp,/([[:xdigit:]]{2});/)) {
  269. set %wu_temp $replace(%wu_temp,$+(&#x,$regml(1),;),$chr($base($regml(1),16,10)))
  270. }
  271. set %wu_temp $regsubex(%wu_temp,/[\46\43](\d+)\73/g,$chr(\1))
  272. set %wu_temp $replacex(%wu_temp,&quot;,",&amp;lt;,<,&amp;rt;,>,&amp;deg;,�,&amp;,&)
  273. if (<name> isin %wu_temp) && (%wu_name == $null) %wu_name = $remove(%wu_temp,<name>,</name>,$chr(9))
  274.  
  275. ;checks for an error
  276. if (<error> isin %wu_temp) set %wu_error Error
  277. if (%wu_error == Error) && (<description> isin %wu_temp) {
  278. set %wu_error_description $remove(%wu_temp,<description>,</description>,$chr(9))
  279. }
  280.  
  281. ;set %wu_temp $regsubex(%wu_temp,/&#(\d+)\;/g,$chr(\1))
  282. ;echo -s %wu_temp
  283.  
  284. ;VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
  285. ;--- Variables for Weather, Current and Time Command ---
  286. if (%wu_command == !weather) || (%wu_command == !current) || (%wu_command == !time) {
  287. ; local info
  288. if (<full> isin %wu_temp) && (%wu_full == $null) %wu_full = $remove(%wu_temp,<full>,</full>,$chr(9))
  289. if (<city> isin %wu_temp) && (%wu_city == $null) %wu_city = $remove(%wu_temp,<city>,</city>,$chr(9))
  290. if (<state> isin %wu_temp) && (%wu_state == $null) %wu_state = $remove(%wu_temp,<state>,</state>,$chr(9))
  291. if (<state_name> isin %wu_temp) && (%wu_state_name == $null) %wu_state_name = $remove(%wu_temp,<state_name>,</state_name>,$chr(9))
  292. if (<country> isin %wu_temp) && (%wu_country == $null) %wu_country = $remove(%wu_temp,<country>,</country>,$chr(9))
  293. if (<country_iso3166> isin %wu_temp) && (%wu_country_iso3166 == $null) %wu_country_iso3166 = $remove(%wu_temp,<country_iso3166>,</country_iso3166>,$chr(9))
  294. if (<zip> isin %wu_temp) && (%wu_zip == $null) %wu_zip = $remove(%wu_temp,<zip>,</zip>,$chr(9))
  295. if (<latitude> isin %wu_temp) && (%wu_latitude == $null) %wu_latitude = $remove(%wu_temp,<latitude>,</latitude>,$chr(9))
  296. if (<longitude> isin %wu_temp) && (%wu_longitude == $null) %wu_longitude = $remove(%wu_temp,<longitude>,</longitude>,$chr(9))
  297. if (<elevation> isin %wu_temp) && (%wu_elevation == $null) %wu_elevation = $remove(%wu_temp,<elevation>,</elevation>,$chr(9))
  298.  
  299. ;; NO LONGER if (<local_time> isin %wu_temp) %wu_local_time = $remove(%wu_temp,<local_time>,</local_time>,$chr(9))
  300. if (<local_time_rfc822> isin %wu_temp) %wu_local_time_rfc822 = $remove(%wu_temp,<local_time_rfc822>,</local_time_rfc822>,$chr(9))
  301.  
  302. ; current weather
  303. if (<weather> isin %wu_temp) %wu_weather = $remove(%wu_temp,<weather>,</weather>,$chr(9))
  304. if (<temperature_string> isin %wu_temp) %wu_temperature_string = $remove(%wu_temp,<temperature_string>,</temperature_string>,$chr(9))
  305. if (<temp_f> isin %wu_temp) %wu_temp_f = $remove(%wu_temp,<temp_f>,</temp_f>,$chr(9))
  306. if (<temp_c> isin %wu_temp) %wu_temp_c = $remove(%wu_temp,<temp_c>,</temp_c>,$chr(9))
  307. if (<relative_humidity> isin %wu_temp) %wu_relative_humidity = $remove(%wu_temp,<relative_humidity>,</relative_humidity>,$chr(9))
  308.  
  309. ; wind
  310. if (<wind_string> isin %wu_temp) %wu_wind_string = $remove(%wu_temp,<wind_string>,</wind_string>,$chr(9))
  311. if (<wind_dir> isin %wu_temp) %wu_wind_dir = $remove(%wu_temp,<wind_dir>,</wind_dir>,$chr(9))
  312. if (<wind_degrees> isin %wu_temp) %wu_wind_degrees = $remove(%wu_temp,<wind_degrees>,</wind_degrees>,$chr(9))
  313. if (<wind_mph> isin %wu_temp) %wu_wind_mph = $remove(%wu_temp,<wind_mph>,</wind_mph>,$chr(9))
  314. if (<wind_gust_mph> isin %wu_temp) %wu_wind_gust_mph = $remove(%wu_temp,<wind_gust_mph>,</wind_gust_mph>,$chr(9))
  315.  
  316. if (<pressure_string> isin %wu_temp) %wu_pressure_string = $remove(%wu_temp,<pressure_string>,</pressure_string>,$chr(9))
  317. if (<pressure_mb> isin %wu_temp) %wu_pressure_mb = $remove(%wu_temp,<pressure_mb>,</pressure_mb>,$chr(9))
  318. if (<pressure_in> isin %wu_temp) %wu_pressure_in = $remove(%wu_temp,<pressure_in>,</pressure_in>,$chr(9))
  319. if (<dewpoint_string> isin %wu_temp) %wu_dewpoint_string = $remove(%wu_temp,<dewpoint_string>,</dewpoint_string>,$chr(9))
  320. if (<dewpoint_f> isin %wu_temp) %wu_dewpoint_f = $remove(%wu_temp,<dewpoint_f>,</dewpoint_f>,$chr(9))
  321. if (<dewpoint_c> isin %wu_temp) %wu_dewpoint_c = $remove(%wu_temp,<dewpoint_c>,</dewpoint_c>,$chr(9))
  322.  
  323. if (<heat_index_string> isin %wu_temp) %wu_heat_index_string = $remove(%wu_temp,<heat_index_string>,</heat_index_string>,$chr(9))
  324. if (<heat_index_f> isin %wu_temp) %wu_heat_index_f = $remove(%wu_temp,<heat_index_f>,</heat_index_f>,$chr(9))
  325. if (<heat_index_c> isin %wu_temp) %wu_heat_index_c = $remove(%wu_temp,<heat_index_c>,</heat_index_c>,$chr(9))
  326. if (<windchill_string> isin %wu_temp) %wu_windchill_string = $remove(%wu_temp,<windchill_string>,</windchill_string>,$chr(9))
  327. if (<windchill_f> isin %wu_temp) %wu_windchill_f = $remove(%wu_temp,<windchill_f>,</windchill_f>,$chr(9))
  328. if (<windchill_c> isin %wu_temp) %wu_windchill_c = $remove(%wu_temp,<windchill_c>,</windchill_c>,$chr(9))
  329.  
  330. if (<visibility_mi> isin %wu_temp) %wu_visibility_mi = $remove(%wu_temp,<visibility_mi>,</visibility_mi>,$chr(9))
  331. if (<visibility_km> isin %wu_temp) %wu_visibility_km = $remove(%wu_temp,<visibility_km>,</visibility_km>,$chr(9))
  332. }
  333.  
  334. ;VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
  335. ;--- Variables for Forecast Command ---
  336. if (%wu_command == !forecast) || (%wu_command == !forecast5) {
  337. if (<simpleforecast> isin %wu_temp) set %wu_period 1
  338. set %wu_temp $remove(%wu_temp,<![CDATA[,]]>)
  339. if (<period> isin %wu_temp) set %wu_period $remove(%wu_temp,<period>,</period>,$chr(9),$chr(32))
  340.  
  341. ;-- Detailed Forecast ---
  342. if (%wu_command == !forecast) {
  343. if (<title> isin %wu_temp) set $+(%,wu_df_title_,%wu_period) $remove(%wu_temp,<title>,</title>,$chr(9))
  344. if (<fcttext> isin %wu_temp) set $+(%,wu_df_fcttext_,%wu_period) $remove(%wu_temp,<fcttext>,</fcttext>,$chr(9))
  345. if (<fcttext_metric> isin %wu_temp) set $+(%,wu_df_fcttext_metric_,%wu_period) $remove(%wu_temp,<fcttext_metric>,</fcttext_metric>,$chr(9))
  346. if (<pop> isin %wu_temp) set $+(%,wu_df_pop_,%wu_period) $remove(%wu_temp,<pop>,</pop>,$chr(9))
  347. ; pop = possibility of precipitation
  348. }
  349.  
  350. ;-- Simple Forecast ---
  351. if (%wu_command == !forecast5) {
  352. if (<simpleforecast> isin %wu_temp) set %wu_period 1
  353. ;-- ^ Resets %wu_period to 1 when entering the <simpleforecast> section
  354. if (</forecastday> isin %wu_temp) inc %wu_period
  355. ;-- ^ Need the increase becasue the <period> is after the <weekday>
  356.  
  357. if (<weekday> isin %wu_temp) set $+(%,wu_sf_weekday_,%wu_period) $remove(%wu_temp,<weekday>,</weekday>,$chr(9))
  358. if (<high> isin %wu_temp) set %wu_sf_temp high
  359. if (<low> isin %wu_temp) set %wu_sf_temp low
  360. if (<fahrenheit> isin %wu_temp) set $+(%,wu_sf_fahrenheit_,%wu_sf_temp,_,%wu_period) $+($remove(%wu_temp,<fahrenheit>,</fahrenheit>,$chr(9)),$chr(176),F)
  361. if (<celsius> isin %wu_temp) set $+(%,wu_sf_celsius_,%wu_sf_temp,_,%wu_period) $+($remove(%wu_temp,<celsius>,</celsius>,$chr(9)),$chr(176),C)
  362. if (<conditions> isin %wu_temp) set $+(%,wu_sf_conditions_,%wu_period) $remove(%wu_temp,<conditions>,</conditions>,$chr(9))
  363. }
  364.  
  365.  
  366. }
  367. ;VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
  368. ;--- Variables for Alerts Command ---
  369. if (%wu_command == !alerts) || (%wu_command == !alertinfo) {
  370. ;echo -s %wu_temp
  371. ;set -n %wu_ac <alert count="
  372. ;-- Counts the amount of alerts.
  373. if (<alert> isin %wu_temp) { inc %wu_a_i | inc %wu_a_count }
  374.  
  375. ;-- Writes variables for each alert.
  376. if (<type> isin %wu_temp) set $+(%,wu_a,%wu_a_i,_type) $remove(%wu_temp,<type>,</type>,$chr(9))
  377. if (<description> isin %wu_temp) set $+(%,wu_a,%wu_a_i,_description) $remove(%wu_temp,<description>,</description>,$chr(9))
  378. if (<date> isin %wu_temp) set $+(%,wu_a,%wu_a_i,_date) $right($remove(%wu_temp,<date>,</date>,$chr(9)),-12)
  379. if (<expires> isin %wu_temp) set $+(%,wu_a,%wu_a_i,_expires) $right($remove(%wu_temp,<expires>,</expires>,$chr(9)),-10)
  380. if (</message> isin %wu_temp) { set %wu_msg OFF | set $+(%,wu_a,%wu_a_i,_count) $(%wu_msg_c,2) | set %wu_msg_c 0 }
  381. if (%wu_msg == ON) {
  382. inc %wu_msg_gc
  383. inc %wu_msg_c
  384. set $+(%,wu_a,%wu_a_i,_message,%wu_msg_c) %wu_temp
  385. }
  386. if (<message> isin %wu_temp) { set %wu_msg ON }
  387. }
  388.  
  389.  
  390. ;VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
  391. ;---- Variables for Almanac ----
  392. if (%wu_command == !almanac) || (%wu_command == !a) {
  393. if (<airport_code> isin %wu_temp) {
  394. set %wu_airport $remove(%wu_temp,<airport_code>,</airport_code>,$chr(9))
  395. if (%wu_airport == $null) {
  396. set %wu_almanac_error NotFound
  397. sockclose wunderground
  398. wu_sockclose
  399. }
  400. }
  401. if (<temp_high> isin %wu_temp) set %wu_almanac_temp high
  402. if (<temp_low> isin %wu_temp) set %wu_almanac_temp low
  403. if (<normal> isin %wu_temp) set %wu_almanac_rate normal
  404. if (<record> isin %wu_temp) set %wu_almanac_rate record
  405. if (<F> isin %wu_temp) set $+(%,wu_almanac_,%wu_almanac_rate,_,%wu_almanac_temp,_F) $+($remove(%wu_temp,<F>,</F>,$chr(9)),$chr(176),F)
  406. if (<C> isin %wu_temp) set $+(%,wu_almanac_,%wu_almanac_rate,_,%wu_almanac_temp,_C) $+($remove(%wu_temp,<C>,</C>,$chr(9)),$chr(176),C)
  407. if (<recordyear> isin %wu_temp) set $+(%,wu_almanac_,%wu_almanac_temp,_year) $remove(%wu_temp,<recordyear>,</recordyear>,$chr(9))
  408. }
  409. ;VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
  410. ;---- End of xml ----
  411. if (</response> isin %wu_temp) {
  412. ; This is so at the end of the reading, it immedely closes the socket and moves on, instead of waiting for the connection to time out.
  413. ;echo -s ---- wunderground sockclose ----
  414. sockclose wunderground
  415. wu_sockclose
  416. }
  417. }
  418.  
  419. ;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  420.  
  421. on *:sockclose:wunderground: {
  422. ; OLD
  423. ; This section has been changed to an alias.
  424. }
  425.  
  426. ;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  427. ; END SOCKETS
  428. ;SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  429.  
  430.  
  431. ;-----------------------------------------------------------------------------
  432. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  433. ; RESULT
  434. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  435. ;-----------------------------------------------------------------------------
  436.  
  437. alias wu_sockclose {
  438. ;echo -s Result: wu_sockclose
  439. ;--- Spacers. Such as -|- | and -|
  440. set %wu_space $+($chr(45),$chr(124),$chr(45))
  441. set %wu_space2 $+($chr(32),$chr(124),$chr(32))
  442. set %wu_spaceend $+($chr(45),$chr(124))
  443.  
  444. ;--- Removes + sign from address variable
  445. set %wu_address $replace(%wu_address,$chr(43),$chr(32))
  446. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  447. ; Error? Was there an error?
  448. if (%wu_error == error) {
  449. msg %wu_chan Location not found
  450. wu_cleanup
  451. halt
  452. }
  453. if (%wu_name != $null) {
  454. msg %wu_chan %wu_name Found. No data provided.
  455. wu_cleanup
  456. halt
  457. }
  458.  
  459. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  460. if (%wu_command == !weather) {
  461.  
  462. msg %wu_chan %wu_full $+ : %wu_weather and $+(%wu_temp_f,$chr(176),F,$chr(47),%wu_temp_c,$chr(176),C)
  463. }
  464. if (%wu_command == !current) {
  465. msg %wu_chan %wu_full $+ : %wu_weather and $+(%wu_temp_f,$chr(176),F,$chr(47),%wu_temp_c,$chr(176),C) $&
  466. $+ %wu_space2 Heat Index: $+(%wu_heat_index_f,$chr(176),F,$chr(47),%wu_heat_index_c,$chr(176),C)$&
  467. $+ %wu_space2 Winds %wu_wind_string $&
  468. $+ %wu_space2 Windchill: $+(%wu_windchill_f,$chr(176),F,$chr(47),%wu_windchill_c,$chr(176),C) $&
  469. $+ %wu_space2 Pressure: $+(%wu_pressure_in,in,$chr(47),%wu_pressure_mb,mb) $&
  470. $+ %wu_space2 Humidity: %wu_relative_humidity $&
  471. $+ %wu_space2 Dew: $+(%wu_dewpoint_f,$chr(176),F,$chr(47),%wu_dewpoint_c,$chr(176),C) $&
  472. $+ %wu_space2 Visiblity: $+(%wu_visibility_mi,mi,$chr(47),%wu_visibility_km,km)
  473. }
  474. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  475. if (%wu_command == !time) {
  476. ; Military time format (Strait from the code):
  477. msg %wu_chan %wu_full $+ : %wu_local_time_rfc822
  478.  
  479. ; Standard time format (modified):
  480. ;Coming soon, maybe.
  481.  
  482. }
  483.  
  484.  
  485. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  486. ;To Start, Let see if the location accually exists:
  487. if (%wu_command == !forecast) {
  488. .timer 1 0 msg %wu_chan %wu_df_title_0 $+ : %wu_df_fcttext_0 %wu_space %wu_df_title_1 $+ : %wu_df_fcttext_1
  489. .timer 1 1 msg %wu_chan %wu_df_title_2 $+ : %wu_df_fcttext_2 %wu_space %wu_df_title_3 $+ : %wu_df_fcttext_3
  490. }
  491.  
  492. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  493. if (%wu_command == !forecast5) {
  494. ;echo -s %wu_forecast_count
  495.  
  496. .timer 1 0 .msg %wu_nick Your forecast for %wu_location
  497.  
  498. set %wu_f_i 1
  499. while (%wu_f_i <= %wu_forecast_count) {
  500. ; Setup variables
  501. set %wu_sf_dow $($+(%,wu_sf_weekday_,%wu_f_i),2)
  502. set %wu_sf_con $($+(%,wu_sf_conditions_,%wu_f_i),2)
  503. set %wu_sf_fh $($+(%,wu_sf_fahrenheit_high_,%wu_f_i),2)
  504. set %wu_sf_ch $($+(%,wu_sf_celsius_high_,%wu_f_i),2)
  505. set %wu_sf_fl $($+(%,wu_sf_fahrenheit_low_,%wu_f_i),2)
  506. set %wu_sf_cl $($+(%,wu_sf_celsius_low_,%wu_f_i),2)
  507. ; msg nick: DayOfWeek: CurrentCondition. High: 00�F(00�C) - Low: 00�F(00�C)
  508. .timer 1 %wu_f_i .msg %wu_nick %wu_sf_dow $+ : %wu_sf_con $+ . High: $+(%wu_sf_fh,$chr(40),%wu_sf_ch,$chr(41)) - Low: $+(%wu_sf_fl,$chr(40),%wu_sf_cl,$chr(41))
  509. inc %wu_f_i
  510. }
  511. }
  512.  
  513.  
  514. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  515. if (%wu_command == !alerts) {
  516. ;echo -s --Start of alerts---
  517. if (%wu_a_count == 0) msg %wu_chan %wu_location $+ : No Alerts
  518. if (%wu_a_count > 0) {
  519. msg %wu_chan %wu_location $+ : %wu_a_count Alerts
  520. var %i 1
  521. while (%i <= %wu_a_count) {
  522. .timer 1 %i msg %wu_chan %wu_a_start $($+(%,wu_a,%i,_description),2) till $($+(%,wu_a,%i,_expires),2) %wu_a_end
  523. inc %i
  524. }
  525. .timer 1 %i .notice %wu_nick use $chr(2) !alertinfo $chr(2) [zipcode|city,state|city,country|airport] for alert details
  526. }
  527. }
  528. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  529. if (%wu_command == !alertinfo) {
  530. if (%wu_a_count == 0) msg %wu_chan %wu_location $+ : No Alerts
  531. if (%wu_a_count > 0) {
  532. ;msg %wu_chan %wu_location $+ : %wu_a_count Alerts - See PM for details
  533. .msg %wu_nick %wu_location $+ : %wu_a_count Alerts
  534. .msg %wu_nick Type STOP at any time to end.
  535. var %i 1 , %i_gc 1
  536. while (%i <= %wu_a_count) {
  537. .timer 1 %i_gc .msg %wu_nick $chr(2) $($+(%,wu_a,%i,_description),2) $chr(2) from $($+(%,wu_a,%i,_date),2) till $($+(%,wu_a,%i,_expires),2)
  538. var %i_msg 1
  539. while (%i_msg <= $($+(%,wu_a,%i,_count),2)) {
  540. ; -- Builds message timmers with users nick built in, so user can stop the messages directed at them later --
  541. $+(.,timer_wu_,%wu_nick,_,%i_msg) 1 %i_gc .msg %wu_nick $($+(%,wu_a,%i,_message,%i_msg),2)
  542. inc %i_gc
  543. inc %i_msg
  544. }
  545. inc %i
  546. }
  547. $+(.,timer_wu_,%wu_nick,_,%i_msg) %i_gc .msg %wu_nick --------- End of Alerts -------
  548. }
  549. }
  550. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  551.  
  552. if (%wu_command == !almanac) || (%wu_command == !a) {
  553. if (%wu_almanac_error == NotFound) && (%wu_name == $null) msg %wu_chan Location Not Found. Try location near an airport.
  554. if (%wu_almanac_error == $null) && (%wu_name != $null) msg %wu_chan %wu_name Found. No data provided.
  555.  
  556. if (%wu_almanac_error == $null) && (%wu_name == $null) {
  557. .timer 1 0 msg %wu_chan $+(%wu_airport,$chr(58)) Normal High: $+(%wu_almanac_normal_high_F,$chr(47),%wu_almanac_normal_high_C,$chr(46)) Normal Low: $+(%wu_almanac_normal_low_F,$chr(47),%wu_almanac_normal_low_C,$chr(46))
  558. .timer 1 1 msg %wu_chan $+(%wu_airport,$chr(58)) Record High: $+(%wu_almanac_record_high_F,$chr(47),%wu_almanac_record_high_C) in %wu_almanac_high_year - Record Low: $+(%wu_almanac_record_low_F,$chr(47),%wu_almanac_record_low_C,) in %wu_almanac_low_year
  559. }
  560. }
  561.  
  562. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  563.  
  564. ;echo -s End-------- of WU $time --------
  565. wu_cleanup
  566. }
  567.  
  568. ;RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
  569.  
  570. :MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  571.  
  572. ;--- Private Message ----
  573. ; -- If user requested !AlertsInfo, and wants to stop the long string of alerts. they can simply type STOP ---
  574. on 1:OPEN:?:*stop*:{
  575. $+(.,timer_wu_,$nick,$chr(42)) off
  576. .msg $nick --------- Alerts Stopped -------
  577.  
  578. }
  579.  
  580. :MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
  581.  
  582. alias wu_help {
  583. .timer 1 0 .msg %wu_nick $me $+ ' Weather Commands: (16 lines)
  584. .timer 1 1 .msg %wu_nick !weather !current !forecast !forecast5 !alerts !alertinfo !time !almanac !a
  585. .timer 1 2 .msg %wu_nick Use above commands with your desired location.
  586. .timer 1 3 .msg %wu_nick !weather [zipcode|city,state|city,country|airport]
  587. .timer 1 4 .msg %wu_nick Examples: !weather 90210 - !weather Beverly Hills, CA - !weather LAX - !weather E2J4C7
  588. .timer 1 5 .msg %wu_nick You can also set a default location for yourself. Just type: !weather REGISTER [location]
  589. .timer 1 6 .msg %wu_nick To remove from the list, simply type !weather REMOVE
  590. .timer 1 7 .msg %wu_nick After you have registure, You can simply use !weather and it will bring up your default
  591. .timer 1 8 .msg %wu_nick -----END OF WEATHER HELP -----
  592. wu_cleanup
  593. }
  594.  
  595. ;=============================================================================
  596. alias wu_cleanup {
  597. ;echo -s End-------- of WU $time --------
  598. unset %wu_*
  599. }
  600.  
  601.  
  602. ;=============================================================================
  603. /*
  604. ---- VERSION HISTORY -----
  605. 1.0
  606. - Original creation
  607.  
  608. 2.0
  609. - Added !current command
  610. - Unknown modifications (Did so many, I can't remember)
  611.  
  612. 3.0
  613. - Added REGISTER and HELP functions
  614. - Fixed !forecast, !forecast5, !alerts !alertinfo Address still including + sign error.
  615.  
  616. 3.1
  617. - Added !weather ON and OFF command to turn the script on or off. (set for OPS ONLY)
  618.  
  619. 3.2
  620. - Modified !weather ON/OFF command. Now the ON and OFF commands are Per #channel basis. (allowing it to be on in one chan, but off in another
  621.  
  622. 3.3
  623. - Line 238, TOS line had changed. Updated $remove() to reflect new text.
  624.  
  625. 4.0
  626. - Local Support. Now Local user (mIRC client hosting the script) can also activate and use the script. .
  627. 4.1
  628. - Fixed !w command. Now it works.
  629.  
  630. 5.0
  631. - New Format: Code now uses wunderground's API. YOU MUST HAVE AN API code in order for this to work.
  632. - Various parts changed to accomidate the new API requirments. OLD stuff commented out and NEW stuff noted (For those who read the code)
  633. - Current code uses CONDITIONS, FORECAST. But wunderground has more paramerters you can pull from not included in this code: http://www.wunderground.com/weather/api/d/docs?d=data/index&MR=1
  634. - Release to the public in Working order. But may still have bugs.
  635. 5.1
  636. - Added line spacers to each section. (I kept getting lost, so I decided to add spacers for each section so I knew where I was in the code)
  637. - Added !almanac for record highs and lows.
  638. 5.2
  639. - Fixed !alerts, !alertinfo, Now works with new API platform
  640. - Added STOP ablity to long !alertinfo. (Simply type STOP in the private message window)
  641. - Fixed !forecast and !forecast5 to new API platform.
  642. 5.3
  643. - Added !forecast[1-10] ablity. Now you can request up to 10 days of private messages. Instead of the default 5. Want 3 days? !forecast3. Want 10 days? !forecast10
  644. - Fixed Spelling issue with forecast. (forEcast)
  645. - Fixed Location Not Found to effect All commands. Added responce if city is found, but with out any information. Ex: ORD (Chicago-O'Hare International Airport)
  646.  
  647. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement