Jump to content

Archived

This topic is now archived and is closed to further replies.

chain

Weather snippet for client Peace&Protection only

Recommended Posts

  • Administrators
; #= ppweather -rs
; ########################################
; Peace and Protection
; PnP Weather (standard addon)
; ########################################

#.ppa.info off
[addon]
name=Weather
group=Tutorial
popup=Weather
author=acvxqs
version=1.12
url=https://github.com/acvxqs/PnPAddons422
email=
id=ppweather
ppver=4.22
config=weather
unload=weather.unload
vars2=weather.apiurl weather.apikey weather.pchar weather.qstring weather.ustring weather.astring weather.mstring weather.kstring weather.istring weather.trigger
windows=
dialogs=weather
[files]
1=weather.ppa
[notes]
1=This addon allows you to retrieve weather information from OpenWeatherMap.org using command: /weather {city},{country code} or respond in channel to a !weather {city},{country code} trigger.
2=Please note that city name and country code are divided by comma, use ISO 3166 country codes.
#.ppa.info end

on *:LOAD:{
  ; PnP check
  if (!$_ispnp) {
    echo 4 -ati2 *** This addon requires Peace and Protection by pai to use.
    echo 4 -ati2 *** You can download Peace and Protection at http://www.kristshell.net/pnp/
    .timer -mio 1 0 .unload -rs " $+ $script $+ "
    halt
  }
  ; Invalid load method check
  if (!$istok($_cfgx(addons,ids),$readini($script,n,addon,id),32)) {
    .timer -mio 1 0 .unload -rs " $+ $script $+ "
    dispa Unloading ' $+ $script $+ ' $chr(40) $+ addon is not properly loaded; use /addon to load it $+ $chr(41)
    halt
  }
  if ($version < 7.52) {
    .timer -mio 1 0 .unload -rs " $+ $script $+ "
    dispa Unloading ' $+ $script $+ ' $chr(40) $+ This script requires mIRC version 7.52+ $+ $chr(41)    
    halt
  }
  if ($version < 7.56) { 
    dispa This script requires SReject's JSON For mIRC! 
    dispa Please get it from: https://github.com/SReject/JSON-For-Mirc/archive/v1.0.4000.zip
  }
  else getJFM
}
dialog weather {
  title "Weather Central"
  size -1 -1 202 214
  option dbu
  icon script\pnp.ico

  box "Respond to trigger on networks:", 1, 5 5 95 90
  combo 2, 10 15 50 50, size
  button "Add", 3, 65 15 27 11, disable
  button "Remove", 4, 65 30 27 11, disable
  radio "Whitelist channels", 5, 10 70 60 10, group disable
  radio "Blacklist channels", 6, 10 80 60 10, disable

  box "Specify channels:", 7, 103 5 95 90
  combo 8, 108 15 50 50, size disable
  button "Add", 9, 163 15 27 11, disable
  button "Remove", 10, 163 30 27 11, disable

  box "", 11, 5 100 193 90
  check "City", 12, 10 110 50 10, disable
  check "Country", 13, 10 120 50 10, disable
  check "Weather short", 14, 10 130 50 10, disable
  check "Weather long", 15, 10 140 50 10, disable
  check "Humidity", 16, 10 150 50 10, disable

  check "Temperature", 17, 65 110 50 10, disable
  check "Temp. min.", 18, 65 120 50 10, disable
  check "Temp. max.", 19, 65 130 50 10, disable
  check "Pressure", 20, 65 140 50 10, disable
  check "Visibility", 21, 65 150 50 10, disable

  check "Wind speed", 22, 120 110 50 10, disable
  check "Wind degree", 23, 120 120 50 10, disable
  check "Sunrise", 24, 120 130 50 10, disable
  check "Sunset", 25, 120 140 50 10, disable
  check "Clouds", 26, 120 150 50 10, disable

  radio "Kelvin", 27, 10 175 50 10, group disable
  radio "Metric", 28, 65 175 50 10, disable
  radio "Imperial", 29, 120 175 50 10, disable
  text "Unit format:", 30, 10 165 37 8

  button "OK", 100, 5 195 40 12, ok
  button "Cancel", 101, 65 195 37 12, cancel
  button "API Key", 102, 120 195 37 12
}
on *:DIALOG:weather:init:0:{
  ; convert active entries to entries the dialog can work with

  var %anetworks $hget(pnp.weather,anetworks)
  hadd pnp.weather networks %anetworks

  if (%anetworks) {
    ; iterate over networks
    var %n 1
    while ($gettok(%anetworks,%n,44)) {

      ; there's two net specific hashes: -opt and -channels
      ; make sure they are ported from 'anet' to 'net'
      ; data should exist in them already, but cannot hurt to check:
      var %network $v1
      if ($hget(pnp.weather,$+(anet-,%network,-opt))) hadd pnp.weather $+(net-,%network,-opt) $v1
      if ($hget(pnp.weather,$+(anet-,%network,-channels))) hadd pnp.weather $+(net-,%network,-channels) $v1

      ; now let's focus on all the channels for the network, if
      ; they exist!

      ; grab $v1 from previous if-check, handy!
      var %achannels $v1
      if (%achannels) {
        var %c 1
        while ($gettok(%achannels,%c,44)) {
          var %chan $v1
          if ($hget(pnp.weather,$+(achan-,%network,-,%chan))) hadd pnp.weather $+(chan-,%network,-,%chan) $v1
          inc %c
        }
      }
      inc %n
    }
    ; well we have to load networks if they exist!
    didtok $dname 2 44 %anetworks
  }
}

alias -l wedloadnet {
  var %network $1
  if (!$hget(pnp.weather,$+(net-,%network,-opt))) hadd pnp.weather $+(net-,%network,-opt) 1,1100010000000001
  tokenize 44 $hget(pnp.weather,$+(net-,%network,-opt))
  if ($1) {
    did -u $dname 5
    did -c $dname 6
    wesetopt $2
  }
  else {
    did -c $dname 5
    did -u $dname 6
  }
  did -r $dname 8
  if ($hget(pnp.weather,$+(net-,%network,-channels))) {
    didtok $dname 8 44 $v1
  }
  did -u $dname 8
}
alias -l wedloadchan {
  var %network $1
  var %chan $2
  if (!$hget(pnp.weather,$+(chan-,%network,-,%chan))) hadd pnp.weather $+(chan-,%network,-,%chan) 1100010000000001
  if ($did(5).state) wesetopt $hget(pnp.weather,$+(chan-,%network,-,%chan))
}
alias -l wedu {
  goto $did(2,0).sel $+ $did(8,0).sel $+ $did(6).state

  :000 | :001 | :010
  ;echo -a 000 001 010 $caller
  did -b $dname 4,5,6,8,9,10,12-29
  did -r $dname 8
  return

  :011
  ;echo -a 011 $caller
  did -r $dname 8
  did -ra $dname 11 Settings
  did -b $dname 5,6,8,9,10,12-29
  did -u $dname 12-29
  return

  :100
  ;echo -a 100 $caller
  did -bu $dname 12-29
  did -e $dname 4,5,6,8
  did -ra $dname 11 Settings 
  return

  :101
  ;echo -a 101 $caller
  did -e $dname 4,5,6,8,12-29
  did -ra $dname 11 Settings for network: $did(2,0).text
  return

  :110
  ;echo -a 110 $caller
  did -e $dname 8,10,12-29
  did -ra $dname 11 Settings for channel: $replace($did(8,0).text,&,&&) on network: $did(2,0).text
  return

  :111
  ;echo -a 111 $caller
  did -e $dname 10
  did -ra $dname 11 Settings for network: $did(2,0).text
  return
}
on *:DIALOG:weather:sclick:*:{
  if ($did < 1) return

  elseif ($did == 2) {
    if ($did(2,0).sel) wedloadnet $did(2,0).text | wedu
  }
  elseif ($did == 3) {
    _ddadd $dname 2 $did(2,0).text
    hadd pnp.weather networks $addtok($hget(pnp.weather,networks),$did(2,0).text,44)
    did -uf $dname 2
  }
  elseif ($did == 4) {
    hadd pnp.weather networks $remtok($hget(pnp.weather,networks),$did(2,0).text,1,44)
    did -d $dname 2 $did(2,1).sel
    did -r $dname 8
    did -uf $dname 2
    did -b $dname 3,4,5,6,8,9,10,12-29
    did -ra $dname 11 Settings
  }
  elseif ($did == 5) {
    var %do $+(net-,$did(2,0).text,-opt)
    hadd pnp.weather %do $puttok($hget(pnp.weather,$+(net-,$did(2,0).text,-opt)),0,1,44)
    if ($did(8,0).text) wedloadchan $did(2,0).text $did(8,0).text
    wedu 
  }
  elseif ($did == 6) {
    var %do $+(net-,$did(2,0).text,-opt)
    hadd pnp.weather %do $puttok($hget(pnp.weather,$+(net-,$did(2,0).text,-opt)),1,1,44)
    wedloadnet $did(2,0).text
    wedu
  } 
  elseif ($did == 8) {
    if ($did(8,0).sel) wedloadchan $did(2,0).text $did(8,0).text | wedu
  }
  elseif ($did == 9) {
    _ddadd $dname 8 $did(8,0).text
    hadd pnp.weather $+(net-,$did(2,0).text,-channels) $addtok($hget(pnp.weather,$+(net-,$did(2,0).text,-channels)),$did(8,0).text,44)
    did -uf $dname 8
  }
  elseif ($did == 10) {
    hadd pnp.weather $+(net-,$did(2,0).text,-channels) $remtok($hget(pnp.weather,$+(net-,$did(2,0).text,-channels)),$did(8,0).text,1,44)
    hdel pnp.weather $+(chan-,$did(2,0).text,-,$did(8,0).text)
    did -d $dname 8 $did(8,1).sel
    did -uf $dname 8
    if ($did(5).state) did -b $dname 12-29
    else did -e $dname 12-29
    did -b $dname 10
    did -ra $dname 11 Settings    
  }
  elseif ($istok(12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29,$did,32)) {
    ;editing for channel? 
    if ($did(5).state) {
      hadd pnp.weather $+(chan-,$did(2,0).text,-,$did(8,0).text) $wegetopt
    }
    ; editing for network?
    elseif ($did(6).state) {
      var %do $+(net-,$did(2,0).text,-opt)
      hadd pnp.weather %do $puttok($hget(pnp.weather,%do),$wegetopt,2,44)
    }
  }
  elseif ($did == 100) {

    ; purging channels that were removed...
    var %rn 1
    while ($gettok($hget(pnp.weather,anetworks),%rn,44)) {
      var %rc 1,%rnetwork $v1
      while ($gettok($hget(pnp.weather,$+(anet-,%rnetwork,-channels)),%rc,44)) {
        var %rchan $v1
        if (!$istok($hget(pnp.weather,$+(net-,%rnetwork,-channels)),%rchan,44)) {
          hdel pnp.weather $+(achan-,%rnetwork,-,%rchan))
        }
        inc %rc
      }
      inc %rn
    }    

    var %networks $hget(pnp.weather,networks)
    hadd pnp.weather anetworks %networks
    if (%networks) {
      ; iterate over networks
      var %n 1
      while ($gettok(%networks,%n,44)) {

        ; there's two net specific hashes: -opt and -channels
        ; make sure they are ported from 'net' to 'anet'

        var %network $v1
        `weather $+(anet-,%network,-opt) $hget(pnp.weather,$+(net-,%network,-opt))
        `weather $+(anet-,%network,-channels) $hget(pnp.weather,$+(net-,%network,-channels))

        ; now let's focus on all the channels for the network, if
        ; they exist!

        ; grab $v1 from previous if-check, handy!
        var %channels $hget(pnp.weather,$+(net-,%network,-channels))
        if (%channels) {
          var %c 1
          while ($gettok(%channels,%c,44)) {
            var %chan $v1
            if ($hget(pnp.weather,$+(chan-,%network,-,%chan))) `weather $+(achan-,%network,-,%chan) $v1
            inc %c
          }
        }        
        inc %n
      }
    }
    ; throw away dialog data
    hdel -w pnp.weather net-*
    hdel -w pnp.weather chan-*
    hdel pnp.weather networks
  }
  elseif ($did == 101) {
    ; throw away changes
    hdel -w pnp.weather net-*
    hdel -w pnp.weather chan-*
    hdel pnp.weather networks
  }
  elseif ($did == 102) {
    `set weather.apikey $_entry(-1,$hget(pnp.config,weather.apikey),What is your API key?)
  }
}
on *:DIALOG:weather:edit:2:{
  if ($did(2,0).text == $null) {
    did -b $dname 3
  }
  elseif ($_scandid($dname,2,$did(2,0).text)) {
    did -c $dname 2 $v1
    did -b $dname 3
    did -e $dname 4
    wedloadnet $did(2,0).text
  }
  else {
    did -e $dname 3
    did -b $dname 4,8
  }
  wedu
}
on *:DIALOG:weather:edit:8:{
  if ($did(8,0).text == $null) {
    did -b $dname 9 
    did -ra $dname 11 Settings
  }
  elseif ($_scandid($dname,8,$did(8,0).text)) {
    did -c $dname 8 $v1
    did -b $dname 9
    wedloadchan $did(8,0).text
    wedu
  }
  else {
    did -e $dname 9
    did -b $dname 10
  }
  wedu
}

alias -l wesetopt {
  if ($left($1,1)) did -c $dname 12
  else did -u $dname 12
  if ($mid($1,2,1)) did -c $dname 13
  else did -u $dname 13
  if ($mid($1,3,1)) did -c $dname 14
  else did -u $dname 14
  if ($mid($1,4,1)) did -c $dname 15
  else did -u $dname 15
  if ($mid($1,5,1)) did -c $dname 16
  else did -u $dname 16
  if ($mid($1,6,1)) did -c $dname 17
  else did -u $dname 17
  if ($mid($1,7,1)) did -c $dname 18
  else did -u $dname 18
  if ($mid($1,8,1)) did -c $dname 19
  else did -u $dname 19
  if ($mid($1,9,1)) did -c $dname 20
  else did -u $dname 20
  if ($mid($1,10,1)) did -c $dname 21
  else did -u $dname 21
  if ($mid($1,11,1)) did -c $dname 22
  else did -u $dname 22
  if ($mid($1,12,1)) did -c $dname 23
  else did -u $dname 23
  if ($mid($1,13,1)) did -c $dname 24
  else did -u $dname 24
  if ($mid($1,14,1)) did -c $dname 25
  else did -u $dname 25
  if ($mid($1,15,1)) did -c $dname 26
  else did -u $dname 26
  if ($right($1,1) == 1) { 
    did -u $dname 27
    did -c $dname 28
    did -u $dname 29 
  }
  elseif ($right($1,1) == 2) {
    did -u $dname 27
    did -u $dname 28
    did -c $dname 29
  }
  else { 
    did -c $dname 27
    did -u $dname 28
    did -u $dname 29
  }
}
alias -l wegetopt {
  var %opt,%i 12
  while (%i <= 26) {
    %opt = %opt $+ $did(%i).state 
    inc %i
  }
  if ($did(27).state) %opt = %opt $+ 0
  elseif ($did(28).state) %opt = %opt $+ 1
  elseif ($did(29).state) %opt = %opt $+ 2
  else %opt = %opt $+ 1
  return %opt 
}
alias -l weather.load {
  if ($hget(pnp.weather)) hdel -w pnp.weather *
  else hmake pnp.weather 30
  var %file $_cfg(weather.dat)
  if ($isfile(%file)) hload pnp.weather " $+ %file $+ "
}
alias weather.unload {
  if ($islias(jsonclose)) jsonclose -w PPWEATHER.*
  weather.save 1
  if (!$_yesno(1,Would you like to keep weather configuration data?)) .remove $_cfg(weather.dat)
}
alias -l weather.save {
  var %file $_cfg(weather.dat)
  if ($hget(pnp.weather)) {
    hsave pnp.weather " $+ %file $+ "
    if ($1) hfree pnp.weather
  }
}
alias -l weather.setup {
  if ($hget(pnp.weather) == $null) weather.load
  if (!$hget(pnp.config,weather.apiurl)) `set weather.apiurl $weather.owm(apiurl)
  if (!$hget(pnp.config,weather.pchar)) `set weather.pchar $weather.owm(pchar)
  if (!$hget(pnp.config,weather.qstring)) `set weather.qstring $weather.owm(qstring)
  if (!$hget(pnp.config,weather.ustring)) `set weather.ustring $weather.owm(ustring)
  if (!$hget(pnp.config,weather.astring)) `set weather.astring $weather.owm(astring)
  if (!$hget(pnp.config,weather.mstring)) `set weather.mstring $weather.owm(mstring)
  if (!$hget(pnp.config,weather.istring)) `set weather.istring $weather.owm(istring)
  if (!$hget(pnp.config,weather.kstring)) `set weather.kstring $weather.owm(kstring)
  if (!$hget(pnp.config,weather.trigger)) `set weather.trigger !weather
}
alias weather.owm {
  if ($istok(apiurl dunits pchar qstring ustring astring mstring istring kstring,$1,32)) goto $1
  else return $null

  :apiurl | return http://api.openweathermap.org/data/2.5/weather
  :pchar | return ?
  :qstring | return q=
  :ustring | return &units=
  :astring | return &appid=
  :mstring | return metric
  :istring | return imperial
  :kstring | return kelvin
}
on *:START:{ if ($_ispnp) _startup.add _weather.start Initializing weather addon }
on *:EXIT:{ weather.save | jsonclose -w PPWEATHER.* }
alias _weather.start { weather.setup }
; `weather varname [value]
; varname should not include the %`
alias `weather {
  if ($hget(pnp.weather,$1) == $2-) return
  if ($2- == $null) {
    hdel pnp.weather $1
    write -ds [ $+ [ $1 ] ] config\ $+ $hget(pnp,user) $+ \weather.dat
    _broadcastp hdel pnp.weather $1
  }
  else {
    hadd pnp.weather $1 $2-
    write -s [ $+ [ $1 ] ] config\ $+ $hget(pnp,user) $+ \weather.dat $1-
    _broadcastp _`weather $1
  }
}
alias _`weather hadd pnp.config $1 $read(config\ $+ $hget(pnp,user) $+ \weather.dat,nts,$1)
alias weather {
  var %caller $caller
  if ($isid) return

  var %switch,%rest
  if (+* iswm $1) {
    %switch = $mid($1,2)
    %rest = $2-
  }
  else {
    if (%caller == editbox) %switch = m
    elseif (%caller == event) {

      if ($istok($hget(pnp.weather,anetworks),$network,44)) {
        var %netopt $hget(pnp.weather,$+(anet-,$network,-opt))
        if ($gettok(%netopt,1,44)) {
          if ($right($gettok(%netopt,2,44),1) == 0) %switch = k
          elseif ($right($gettok(%netopt,2,44),1) == 1) %switch = m
          elseif ($right($gettok(%netopt,2,44),1) == 2) %switch = i
          else halt
        }
        elseif ($istok($hget(pnp.weather,$+(anet-,$network,-channels)),$chan,44)) {
          var %chanopt $hget(pnp.weather,$+(achan-,$network,-,$chan))
          if ($right(%chanopt,1) == 0) %switch = k
          elseif ($right(%chanopt,1) == 1) %switch = m
          elseif ($right(%chanopt,1) == 2) %switch = i          
          else halt
        }
        else halt
      }
      else halt
    }
    else %switch = m
    %rest = $1-
  }
  if (%rest) {
    if (%switch === m) {
      var %units $+($hget(pnp.config,weather.ustring),$hget(pnp.config,weather.mstring))
      %switch = metric
    }
    elseif (%switch === i) { 
      var %units $+($hget(pnp.config,weather.ustring),$hget(pnp.config,weather.istring))
      %switch = imperial
    }
    elseif (%switch === k) { 
      var %units $+($hget(pnp.config,weather.ustring),$hget(pnp.config,weather.kstring))
      %switch = kelvin
    }
    if (!$hget(pnp.config,weather.apikey)) {
      dispa Weather: API key not set! 
      halt
    }

    var %city $gettok(%rest,1,44)
    %city = $replace(%city,$chr(32),$chr(37) $+ 20)
    var %cc $gettok(%rest,2,44)
    var %pattern /^[-%20a-z]{2,}$/i

    if (($regex(%city,%pattern)) && ($regex(%cc,/^[a-z]{2}$/i))) {
      var %jsonname $lower($+(PPWEATHER.,%city,.,%cc,.,%switch))
      if (!$JSON(%jsonname)) {
        weatherfetch %caller %jsonname %city %cc %units
      }
      else {
        var %dt $json(%jsonname,dt).value
        if ((!%dt) || ($calc($ctime - %dt) >= 600)) { 
          JSONCLOSE %jsonname 
          weatherfetch %caller %jsonname %city %cc %units
        }
        else {
          if (%caller == editbox) dispa [Weather] (cached) $regsubex($json(%jsonname).string,/(\d)/g,$:t(\1)))
          elseif (%caller == event) {
          if ($_weatherfetchresult(%jsonname)) msg $chan [Weather] (cached) $v1          }
        }
      }
    }
    else {
      if (%caller == editbox) dispa Usage: /weather <+m|i|k> <city>,<country code>
      elseif (%caller == event) notice $nick Usage: $hget(pnp.config,weather.trigger ) <city>,<country code> | notice $nick Example: $hget(pnp.config,weather.trigger) Vlissingen,nl
    }
  }
  else _dialog -am weather weather 
}
alias -l _weatherfetchresult {
  var %jsonname $1, %result 

  ; respond to network?
  if ($istok($hget(pnp.weather,anetworks),$network,44)) {
    ; blacklist channels? If so, respond to all channels!
    var %netopt $hget(pnp.weather,$+(anet-,$network,-opt))
    if ($gettok(%netopt,1,44)) {
      ; if channel not blacklisted, then proceed
      if (!$istok($hget(pnp.weather,$+(anet-,$network,-channels)),$chan,44)) {
        if ($gettok(%netopt,2,44)) {
          var %opt $v1
          %result = $_weatherfetchresult2(%jsonname,%opt)
        }
      }
    }
    ; whitelist channels?
    ; check if channel is in the list and if it is
    ; check its options
    elseif ($istok($hget(pnp.weather,$+(anet-,$network,-channels)),$chan,44)) {
      var %opt $hget(pnp.weather,$+(achan-,$network,-,$chan))
      %result = $_weatherfetchresult2(%jsonname,%opt)
    }
    else %result = $null  
  }
  else %result = $null

  return %result
}
alias -l _weatherfetchresult2 {
  var %jsonname $1
  var %opt $2

  var %city $json(%jsonname,name).value
  var %cc $json(%jsonname,sys,country).value
  var %short $json(%jsonname,weather,0,main).value
  var %long $json(%jsonname,weather,0,description).value
  var %hum $json(%jsonname,main,humidity).value
  var %temp $json(%jsonname,main,temp).value
  var %min_temp $json(%jsonname,main,temp_min).value
  var %max_temp $json(%jsonname,main,temp_max).value
  var %pressure $json(%jsonname,main,pressure).value
  var %vis $json(%jsonname,visibility).value
  var %wspeed $json(%jsonname,wind,speed).value
  var %wdegree $json(%jsonname,wind,deg).value
  var %sunrise $json(%jsonname,sys,sunrise).value
  var %sunset $json(%jsonname,sys,sunset).value
  var %clouds $json(%jsonname,clouds,all).value            
  var %result 

  if ($left(%opt,1)) %result = City: %city •
  if ($mid(%opt,2,1)) %result = %result Country: %cc •
  if ($mid(%opt,3,1)) %result = %result Weather: %short •
  if ($mid(%opt,4,1)) %result = %result Description: %long •
  if ($mid(%opt,5,1)) %result = %result Humidity: %hum •
  if ($mid(%opt,6,1)) %result = %result Temperature: %temp •
  if ($mid(%opt,7,1)) %result = %result Min. temp.: %min_temp •
  if ($mid(%opt,8,1)) %result = %result Max. temp: %max_temp •
  if ($mid(%opt,9,1)) %result = %result Pressure: %pressure •
  if ($mid(%opt,10,1)) %result = %result Visibility: %vis •
  if ($mid(%opt,11,1)) %result = %result Wind speed: %wspeed •
  if ($mid(%opt,12,1)) %result = %result Wind degree: %wdegree •
  if ($mid(%opt,13,1)) %result = %result Sunrise: ETA $duration($remove($calc($ctime - %sunrise),-),3) •
  if ($mid(%opt,14,1)) %result = %result Sunset: ETA $duration($remove($calc($ctime - %sunset),-),3) •
  if ($mid(%opt,15,1)) %result = %result Clouds: %clouds •

  return %result
}
alias -l weatherfetch {
  var %caller $1
  var %jsonname $2
  var %city $3
  var %cc $4
  var %units $5
  var %page $+($hget(pnp.config,weather.apiurl),$hget(pnp.config,weather.pchar))
  %page = $+(%page,$hget(pnp.config,weather.qstring),%city,$chr(44),%cc)
  %page = $+(%page,%units))
  %page = $+(%page,$hget(pnp.config,weather.astring),$hget(pnp.config,weather.apikey))    
  JSONOPEN -u %jsonname %page
  if ($json(%jsonname).httpStatus == 200) {
    if (%caller == editbox) dispa [Weather] $regsubex($json(%jsonname).string,/(\d)/g,$:t(\1)))
    elseif (%caller == event) { 
      if ($_weatherfetchresult(%jsonname)) msg $chan [Weather] $v1
    }
    else dispa %caller
  }
  elseif ($json(%jsonname).string) {
    if (%caller == editbox) dispa Weather: $json(%jsonname).string
    elseif (%caller == event) msg $chan [Weather] $json(%jsonname).string
  }
  else dispa Weather: $json(%jsonname).httpStatus - $json(%jsonname).httpStatusText
}
on *:TEXT:$($hget(pnp.config,weather.trigger) *):#:weather $2-
alias getJFM {

  ; sha-512 of JSON For mIRC.mrc v1.0.4000
  var %sha512-1 b29de8c964b002d089fa030a9a5357e3c737f17cd16309c0fa82142120a590db2223d4703cafe97f37b65de170bb4d9dbf7bb508f4052a47a2127fc74c10a6d6
  ; group enabled hash
  var %sha512-2 183153806705c99fce8fb3003ea7e5522e9f67c40b3e064280ad83111e3d8f92b4cfae106b8827a9d99c2377c32d6d6892fe878a027bcaea24a466450cfeead8

  ; check if JSON For mIRC is loaded
  if ($isalias(JSONVersion)) {
    ; script is loaded, but what version?
    var %file $isalias(JSONVersion).fname
    if (!$istok(%sha512-1 %sha512-2,$sha512(%file,2),32)) {
      dispa Unloading $JSONVersion ...
      .unload -rs $qt(%file) | .timer -mio 1 0 getJFM 
    }
    else return 0
  }
  elseif ($1 isnum) {
    if ($urlget($1).state == fail) { dispa Downloading JSON For mIRC failed. Are you connected to the internet? | halt }
    elseif ($zip($urlget($1).target,eo,scripts)) { 
      var %file $qt($findfile(scripts\JSON-For-Mirc-1.0.4000,JSON For mIRC.mrc,1))
      if ($sha512(%file,2) == %sha512-1) dispa Loading JSON For mIRC ver1.0.4000 | .load -rs %file
      else dispa Wrong sha512 hash for %file $+ !      
      .remove $urlget($1).target
    }
    else { dispa Something went wrong unzipping $:t($urlget($1).target) }
  }
  else { 
    var %url https://github.com/SReject/JSON-For-Mirc/archive/v1.0.4000.zip
    var %target JFM.zip
    dispa Obtaining JSON For mIRC...
    return $urlget(%url,gf,%target,getJFM)
  }
}

 

Link to comment
Share on other sites



×
×
  • Create New...