egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SayWeather : Support & Updates

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 572
Location: Tennessee, USA

PostPosted: Tue Aug 28, 2018 12:32 am    Post subject: SayWeather : Support & Updates Reply with quote

SayWeather ver. 6.01 is the next working version of The Script Formerly Known as WunderWeather
Get it Now at the Eggdrop Tcl Archive: https://tclarchive.org/view.php?id=1793

Please test the new script and see what we think:)


You can also get SayWeather version 6.01 here.
Code:

###############################################################
#  Important Notice about SayWeather ver. 6.01                #
#                                                             #
#  This is the next great version of:                         #
#  The Script Formerly Known as WunderWeather                 #
#                                                             #
www.wunderground.com is now the Weather Corporation and    #
#  is no longer providing free weather data to anyone!!       #
#  This version changes our weather provider to www.apixu.com #
###############################################################


###############################################################
## SayWeather  version 6.01                       25/08/2018 ##
## Original Script by (lily@disorg.net)                      ##
## Version 5.0+ updates by SpiKe^^      www.mytclscripts.com ##
##                                                           ##
## -> NEW IN VERSION 6.01 <-                                 ##
## - Changed the weather source page to www.apixu.com        ##
## - Changed script name from WunderWeather to SayWeather    ##
## - Script now requires a Free API Key from www.apixu.com   ##
## - Temporarily removed the forecast part of the reply.     ##
##     Recoded forecast will be available in next version    ##
##                                                           ##
################## - Version 5.0+ History - ###################
## VERSION 5.03  -  04/12/2017                               ##
## - Users can now set/save their default weather location.  ##
##     example:  !w set miami, fl                            ##
##     To use that saved weather location, just type:  !w    ##
##     Does Not use the Eggdrop user file (saves to a file)  ##
## - Added metric conversion of most forecast strings.       ##
## - Script now allows multiple public weather triggers.     ##
## VERSION 5.01  -  28/10/2017                               ##
## - All processes and globals are now in a namespace        ##
## - Replaced weather forecast (removed by Kiely Allen)      ##
## - Replaced metric setting (removed by Kiely &/or David)   ##
## - Added 3 new settings for removing colors and/or bolds   ##
## - Added Throttle Users - Thanks to user & speechles       ##
###############################################################

# International Weather script for Eggdrop.
# Displays in both F/C and MPH/KPH
# Will return weather from www.apixu.com
# Requires TCL8.5 or greater
# Has been tested on Eggdrop 1.8.3

# You must ".chanset #channel +weather" for each chan
# you wish to use this in.

# Usage: !w  :or: !w <input>
# Input can be <zip> <city, st> <city, country> <airport code>

###############################################################

package require http

namespace eval saywz { variable sayw
#######################################################
## - Begin Script Settings - Begin Script Settings - ##
#######################################################

# Set your Api Key from www.apixu.com (REQUIRED) #
set sayw(api_key) ""

# Command Char(s) to use for public binds
# Examples:  "!" or "."
# Or a Space Separated List: "! . ?"
set sayw(cmdchars) "! ."

# Set public Weather Command(s) #
set sayw(cmds_wz) "w weather"

# Set route/filename for the users default weather locations #
set sayw(usrfile) "scripts/sayweather.users"

# Use Metric as the Primary in channel output?? #
# 1 = Yes, use metric as primary output. (0=no) #
set sayw(metric) 0

# Use Color Changing Temperatures?? (1=yes 0=no) #
set sayw(colortemp) 1

# Use SayWeather Logo Color?? (1=yes 0=no)#
set sayw(colorlogo) 1

# Show Weather Item Names in Bold?? (1=yes 0=no) #
set sayw(boldnames) 1

# Amount user can issue before Throttle
set sayw(throttle_max) 2

# Throttle time (seconds)
set sayw(throttle_time) 30

# Set udef flag used to enable this script by channel
# Use:  .chanset #channel +weather
set sayw(udef_flag) "weather"


#######################################################
#### - End Script Settings - End Script Settings - ####
#######################################################

setudef flag $sayw(udef_flag)
set sayw(cmdchars) [split [string trim $sayw(cmdchars)]]
set sayw(cmds_wz) [split [string trim $sayw(cmds_wz)]]

variable nsc [namespace current]
variable name "SayWeather"
variable ver  "6.01"
variable auth "SpiKe^^"

proc say_w {nk uh hn ch input} {  variable sayw
  if {![channel get $ch $sayw(udef_flag)]} {  return 0  }

  set input [join [lassign [split [string trim $input]] cmd]]
  set do ""
  if {[string index $cmd 0] in $sayw(cmdchars)} {
    set c [string range $cmd 1 end]
    if {[lsearch -exact -nocase $sayw(cmds_wz) $c] > -1} {  set do wz  }
  }
  if {$do eq ""} {  return 0  }
  if {[throttle $uh $nk $ch]} {  return 0  }

  set input [split [regsub -all -- {\s{2,}} [string trim $input] { }]]
  lassign [split [string trim $uh ~] @] user host
  set id [string tolower "$nk,$user,$ch"]

  variable wusers
  if {[info exists wusers($id)]} {  set wusers(updated) 1
    set wusers($id) [lreplace $wusers($id) 0 0 [unixtime]]
    set udata $wusers($id)
  } else {  set udata ""  }
  if {![llength $input] && $udata eq ""} {
    puthelp "PRIVMSG $ch :You must provide a city or zip code or set a default location"
    return 0
  }

  set opt [string tolower [lindex $input 0]]  ;  set isset 0
  if {$opt in {set -set}} {  set isset 1
    set input [lrange $input 1 end]
    if {![llength $input]} {
      if {$udata eq ""} {
        puthelp "PRIVMSG $ch :You must provide a city or zip code to set as default location"
      } else {  unset wusers($id)
        puthelp "PRIVMSG $ch :Removed all custom settings for $nk"
      }
      return 0
    }
  } elseif {![llength $input]} {  set input [lindex $udata 1]  }

  set input [join $input]
  set query [::http::formatQuery q $input]
  set addr "http://api.apixu.com/v1/current.xml?key=$sayw(api_key)&$query"
  set token [::http::geturl $addr]
  set html  [::http::data $token]  ;  ::http::cleanup $token
  #set open [open scripts/saywz.xml.txt w]; puts $open $html; close $open

  ######### Get Error Data #########
  regexp {<error>(.*?)</error>} $html - err
  if {[info exists err]} {
    regexp {<code>(.*?)</code><message>(.*?)</message>} $err - code msg

    if {$code==1006} {  puthelp "PRIVMSG $ch :$input Not Found"
    } else {  puthelp "PRIVMSG $ch :\00313Error:\003 $code - $msg"  }
    return 0
  }

  ######## Get Location Data ########
  regexp {<location>(.*?)</location>} $html - loc
  if {![info exists loc]} {
    puthelp "PRIVMSG $ch :\00313Error:\003 No Error and No Location Data??"
    return 0
  }
  foreach term {name region country lat lon localtime} {
    regexp "<$term>(.*?)</$term>" $loc - $term
    if {![info exists $term]} {  set $term ""  }
  }
  unset loc

  set where "$name, "
  if {$region ne ""} {  append where "$region, "  }
  if {[string match -nocase "*united states*" $country]} {
    append where "United States"
  } else {  append where "$country"  }

  if {$isset==1} {  set wusers(updated) 1
    puthelp "PRIVMSG $ch :Set default weather location to: $where"
    set wusers($id) [list [unixtime] [split $where]]
    return 0
  }

  ######## Get Current Data ########
  regexp {<current>(.*?)</current>} $html - curr
  if {[info exists curr]} {
    set terms [list last_updated temp_f temp_c is_day text wind_mph wind_kph]
    lappend terms wind_dir pressure_in pressure_mb precip_in precip_mm
    lappend terms humidity cloud feelslike_f feelslike_c vis_miles vis_km

    foreach term $terms {
      regexp "<$term>(.*?)</$term>" $curr - $term
      if {![info exists $term]} {  set $term ""  }
    }
    unset curr
  }

  # // Build current weather string.
  if {$sayw(boldnames)==0} {  set b ""  } else {  set b "\002"  }
  if {$sayw(colorlogo)==0} {  set logo ""  ;  set endl ""
  } else {  set logo "\00313"  ;  set endl "\003"  }
  set puttx ""

  append puttx "${b}Temperature:$b[color $temp_f $temp_c]"
  if {$sayw(metric)==1} {  append puttx " (${temp_f}F) - "
  } else {  append puttx " (${temp_c}C) - "  }

  ## if {($tempf > $windcf) && (abs($tempf - $windcf) > 1.0)} ##
  append puttx "${b}Feels like:$b[color $feelslike_f $feelslike_c]"
  if {$sayw(metric)==1} {  append puttx " (${feelslike_f}F) - "
  } else {  append puttx " (${feelslike_c}C) - "  }

  append puttx "${b}Humidity:$b ${humidity}% - ${b}Wind:$b "

  # wind_dir wind_mph wind_kph #
  if {$wind_mph < 1} {  append puttx "Calm"
  } else {  append puttx "$wind_dir @ "
    if {$sayw(metric)==1} { append puttx "${wind_kph}KPH (${wind_mph}MPH)"
    } else {  append puttx "${wind_mph}MPH (${wind_kph}KPH)"  }
  }

  # pressure_in pressure_mb #
  append puttx " - ${b}Pressure:$b "
  if {$sayw(metric)==1} { append puttx "${pressure_mb}mb (${pressure_in}in)"
  } else {  append puttx "${pressure_in}in (${pressure_mb}mb)"  }
  append puttx " - ${b}Conditions:$b $text - ${b}Updated:$b $last_updated"

  puthelp "PRIVMSG $ch :${logo}$where:$endl $puttx"
} ;# End proc say_w #


#########################################################################
# // Primary Temperature Color Changing.
# // You can change colors based on fahrenheit temperatures.
# // IRC allows only 16 colors. See mIRC color chart.
proc color {temp tempc} {  variable sayw
  set x "${temp}F"
  if {$sayw(metric)==1} {  set x "${tempc}C"  }
  if {$sayw(colortemp)==0} {  return " $x"  }
  if {$temp < 20} {  return "\00312 $x\003"  }
  if {$temp < 45} {  return "\00311 $x\003"  }
  if {$temp < 70} {  return "\00309 $x\003"  }
  if {$temp < 85} {  return "\00307 $x\003"  }
  if {$temp < 100} { return "\00304 $x\003"  }
  return "\00313 $x\003"
}

#########################################################################
# // Throttle Proc (slightly altered, super action missles) - Thanks user & speechles
# // See this post: http://forum.egghelp.org/viewtopic.php?t=9009&start=3
proc throttle {id nk ch} {  variable throttle  ;  variable sayw
  set now [clock seconds]
  if {[info exists throttle($id)] && [lindex $throttle($id) 0] > $now} {
    lassign $throttle($id) ut cnt
    if {$cnt == $sayw(throttle_max)} {
      puthelp "PRIVMSG $ch :$nk, you have been Throttled (wait [expr {$ut-$now}] secs)"
    }
    set throttle($id) [list $ut [incr cnt]]
    if {$cnt > $sayw(throttle_max)} { set id 1 } { set id 0 }
  } else {
    set throttle($id) [list [expr {$now+$sayw(throttle_time)}] 1]
    set id 0
  }
}
# // sub - clean throttled users
proc throttleclean {} {  variable throttle
  set now [clock seconds]
  foreach {id time} [array get throttle] {
    if {[lindex $time 0]<=$now} { unset throttle($id) }
  }
}

#########################################################################
proc savewusers {} {  variable wusers  ;  variable sayw
  if {![info exists wusers(updated)]} {  return  }
  unset wusers(updated)
  if {![array size wusers]} {
    file delete $sayw(usrfile)
    return
  }
  set open [open $sayw(usrfile) w]
  puts $open "array set wusers [list [array get wusers]]"
  close $open
}

#########################################################################
proc wusersclean {} {  variable wusers
  if {![array size wusers]} {  return  }
  set old [expr {[unixtime] - (86400 * 45)}]   ;# 45 days #
  foreach {key val} [array get wusers] {
    if {$key eq "updated"} {  continue  }
    if {[lindex $val 0] <= $old} {
      unset wusers($key)
      set wusers(updated) 1
    }
  }
}

#########################################################################
proc bindtime {mn hr args} {  variable nsc
  if {$mn eq "02" && $hr in {00 12}} {  ${nsc}::wusersclean  }
  ${nsc}::savewusers
  if {[string match "*1" $mn]} {  ${nsc}::throttleclean  }
}

#########################################################################
# // Script reset (unbind/rebind all triggers).
proc w_reset {} {  variable sayw  ;  variable nsc  ;  set dead "wunder"
  foreach x {w say} { ;# remove all version 5+ binds #
    if {$x eq "w"} {  set wproc "::${dead}::*"
    } else {  set wproc "${nsc}::say_w"  }
    foreach wbind [binds $wproc] {
      lassign $wbind t f n h p
      unbind $t $f $n $p
    }
  }
  foreach char $sayw(cmdchars) {
    bind pubm - "?%~\\${char}*" $wproc
  }
  bind time - * ${nsc}::bindtime
  variable wusers
  if {[file exists "scripts/${dead}weather.users"]} {
    if {![file exists $sayw(usrfile)]} {  set newufile 1
      if {[array exists wusers]} {  unset wusers  }
      file rename "scripts/${dead}weather.users" $sayw(usrfile)
    }
  }
  if {![array exists wusers] || [info exists newufile]} {
    array set wusers ""
    if {[file exists $sayw(usrfile)]} {  source $sayw(usrfile)  }
  }
}
w_reset

putlog "\002S\002ay\002W\002eather v$ver Loaded."

} ;## - End namespace eval - End namespace eval - ##


_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
Back to top
View user's profile Send private message Visit poster's website
roger
Voice


Joined: 17 Jun 2018
Posts: 16

PostPosted: Sun Oct 14, 2018 3:01 pm    Post subject: VERSION 6.02 Reply with quote

hi. this is working ok, but doesn't set with zip code, which isn't a big prob but have one guy that sets his default to !w San Jacinto, California, USA

and bot responds that it is set
but when he does !w it gives him San Jacinto, Baja California, Mexico (31.46, -116.27): Partly cloudy and09 58.1F (14.5C) any ideas?


!w set 92583
You must provide a city or zip code to set as LocationID: @92583

this is what happens when trying to set with zip code

found a "fix" used airport code and it worked fine Smile

thanks, have a great day
roger
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 572
Location: Tennessee, USA

PostPosted: Sun Oct 14, 2018 7:05 pm    Post subject: SayWeather ver. 6.02 -set zipcode issue Reply with quote

oops

roger: Try this for me, search for this line in the script...
Code:
    if {[sdigit $op2]} {  set locid "@$op2"


And replace it with this...
Code:
    if {[sdigit $op2] && [string length $op2]<5} {  set locid "@$op2"

_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com


Last edited by SpiKe^^ on Sun Oct 14, 2018 8:01 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 572
Location: Tennessee, USA

PostPosted: Sun Oct 14, 2018 7:50 pm    Post subject: Get SayWeather ver. 6.02 at tclarchive.org Reply with quote

There is a newer version of SayWeather available at the Eggdrop Tcl Archive:)

Get SayWeather ver. 6.02 at: https://tclarchive.org/view.php?id=1793


Code:

Script Name:  SayWeather
Version:      6.02
Author:       SpiKe^^
Script Date:  29/09/2018
File Name:    sayweather.zip

Short Description:
International Weather script for Eggdrop, Based on Lilys Simple Weather. Users can now set/save multiple weather locations! Script does the current weather conditions, a 1 to 7 day forecast, world time, and more from the www.apixu.com API page. Displays in both F/C and MPH/KPH.

###############################################################
#  Important Notice about SayWeather ver. 6.02                #
#                                                             #
#  This is the next great version of:                         #
#  The Script Formerly Known as WunderWeather                 #
#                                                             #
www.wunderground.com is now the Weather Corporation and    #
#  is no longer providing free weather data to anyone!!       #
#  This version changes our weather provider to www.apixu.com #
###############################################################


# International Weather script for Eggdrop.
# Displays in both F/C and MPH/KPH
# Will return weather from www.apixu.com
# Requires a Free Api Key from www.apixu.com
# Requires TCL8.5 or greater
# Has been tested on Eggdrop 1.8.3

# You must ".chanset #channel +weather" for each chan
# you wish to use this in.

# Usage: !w  :or: !w <input>
# Input can be <city> <zip code> <airport code> <nick>, etc.


###############################################################
## SayWeather  version 6.02                       29/09/2018 ##
## Original Script by (lily@disorg.net)                      ##
## Version 5.0+ updates by SpiKe^^      www.mytclscripts.com ##
##                                                           ##
## -> NEW IN VERSION 6.02 <-                                 ##
## - Replaced the Weather Forecast (removed in versoin 6.01) ##
## - Script now has 3 Weather commands, the defaults are:    ##
##     !w   :Shows a Short version of the Current Weather.   ##
##     !wz  :Shows the Full Current Weather conditions.      ##
##     !w+  :Shows Full Current Weather plus 3 Day Forecast. ##
## - Script now has 2 Forecast commands, the defaults are:   ##
##     !f   :Shows a Short version of the 3 Day Forecast.    ##
##     !fc  :Shows the Full version of the 3 Day Forecast.   ##
## - Added a new Sky/Astro command, the default is: !sky     ##
## - You can specify the length of all Forecast/Sky results. ##
##     example:  !fc5 miami, fl   (5 day forecast for miami) ##
## - Added a global time & IP locator cmd, default is: !time ##
## - You can now specify a Nick as the location for commands ##
##    !ti bart      :see time at bart's saved def location.  ##
## - You can now save as many weather locations as you want: ##
##    !w set miami, fl   :set default location to miami, fl  ##
##    !w set @1 toledo   :set LocationID @01 to toledo, ohio ##
##    - To access the location saved as LocationID @01, use: ##
##    !fc5 @1       :see the 5 day forecast for toledo, ohio ##
##    - To delete the location saved as LocationID @01, use: ##
##    !w set @1     :Delete LocationID @01 (set @1 to empty) ##
## - Added command options to see/list your saved locations: ##
##    !w -see      :see the current default weather location ##
##    !w -list     :list the default & any saved LocationIDs ##
##                                                           ##
################## - Version 5.0+ History - ###################
## VERSION 6.01  -  25/08/2018                               ##
## - Changed the weather source page to www.apixu.com        ##
## - Changed script name from WunderWeather to SayWeather    ##
## - Script now requires a Free API Key from www.apixu.com   ##
## - Temporarily removed the forecast part of the reply.     ##
##     Recoded forecast will be available in next version    ##
## VERSION 5.03  -  04/12/2017                               ##
## - Users can now set/save their default weather location.  ##
##     example:  !w set miami, fl                            ##
##     To use that saved weather location, just type:  !w    ##
##     Does Not use the Eggdrop user file (saves to a file)  ##
## - Added metric conversion of most forecast strings.       ##
## - Script now allows multiple public weather triggers.     ##
## VERSION 5.01  -  28/10/2017                               ##
## - All processes and globals are now in a namespace        ##
## - Replaced weather forecast (removed by Kiely Allen)      ##
## - Replaced metric setting (removed by Kiely &/or David)   ##
## - Added 3 new settings for removing colors and/or bolds   ##
## - Added Throttle Users - Thanks to user & speechles       ##
###############################################################


package require Tcl 8.5
package require http



Get SayWeather ver. 6.02 at: https://tclarchive.org/view.php?id=1793
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
Back to top
View user's profile Send private message Visit poster's website
roger
Voice


Joined: 17 Jun 2018
Posts: 16

PostPosted: Sun Oct 14, 2018 10:45 pm    Post subject: thanks Reply with quote

Razz that did the trick for the zip code, thank you very much, ppl in my chat room sure like the weather script
roger
ohh downloaded earthquake again but having troubles installing tls, but i'll get it yet lol
Back to top
View user's profile Send private message
Sedition
Voice


Joined: 14 Dec 2011
Posts: 16
Location: Bolivia, Beni, Trinidad / DALnet

PostPosted: Mon Oct 22, 2018 1:54 am    Post subject: Re: thanks Reply with quote

is possible change
Code:

if {![channel get $ch $sayw(udef_flag)]} {  return 0  }

to read channel all
Code:

set "*" #all channels
or set "#chan1 #chan2"

_________________
good I wait for all that he learns more on tcl thanks for shaping a solid group of help
Back to top
View user's profile Send private message Send e-mail MSN Messenger
roger
Voice


Joined: 17 Jun 2018
Posts: 16

PostPosted: Mon Oct 22, 2018 3:02 am    Post subject: weather Reply with quote

wouldn't .chanset #channel #channel +weather enable it in the rooms your bot is in?

not sure if it would work but i would try it lol
i just tried it and it does work
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber