This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

DANGEROUS - weather tcl script snippet from http://wttr.in

Support & discussion of released scripts, and announcements of new releases.
Post Reply
n
nobody
Voice
Posts: 31
Joined: Fri Apr 03, 2020 10:01 pm

DANGEROUS - weather tcl script snippet from http://wttr.in

Post by nobody »

Hi,
you might find this useful for your channel, feel free to modified/enhance it

-Thanks to chatgpt for some debugging issue

Code: Select all

# part of my modified fzcommands.tcl by Opposing
# just #nobody
# feel free to enhance it


set logo "\00304ᵉ̲\003メ̲\00306ᵖ̲\00307ˡ̲\00308ᵒ̲\00309ᶦ̲\00310ᵗ̲\00311ᵉ̲\00313ʳ\003"
set trigger "`"

proc xpl {} {
  global logo
  return $logo
}
proc xplx {} {
  global trigger
  return $trigger
}
proc message {who what} {
	puthelp "PRIVMSG $who :$what"
}
proc notice {who what} {
	puthelp "NOTICE $who :$what"
}

bind pub - [xplx]w fz:weather
bind pub - [xplx]weather fz:weather

proc get_weather_report {location} {
    # Fetch weather data (including location and ASCII art) from wttr.in
    ### DANGEROUS USE OF EXEC ###
    set weather_data [exec curl -s "http://wttr.in/$location?0"]

    # Check if data was returned
    if {[string length $weather_data] == 0} {
        return "Error: Unable to fetch weather data for $location."
    }

    return $weather_data
}

# Function to handle the weather command in the chan
proc fz:weather {nick uhost hand chan arg} {
    global botnick

    # Get location from the argument (default to "Brisbane" if not provided)
    set location [string trim [lindex [split $arg] 0]]
    if {[string length $location] == 0} {
        set location "Brisbane"
    }

    # Fetch weather report for the location (with ASCII art)
    set weather_report [get_weather_report $location]
    if {[string first "Error" $weather_report] == 0} {
        message $chan "$nick: $weather_report [xpl]"
        return
    }

    # Clean up color codes if necessary (optional)
    set cleaned_weather_report [remove_color_codes $weather_report]

    # Split and send the weather report in multiple lines to the chan
    set weather_lines [split $cleaned_weather_report "\n"]
    foreach line $weather_lines {
        # Send each line as a separate message to avoid IRC message length limits
        message $chan "$line"
    }
    return 1
}

# Function to remove color codes (if necessary)
proc remove_color_codes {input} {
    regsub -all {\x1b\[[0-9;]*m} $input "" output
    return $output
}

ₙₒₜₕᵢₙg ᵢₛ ₕₐᵣₘ ₑₓcₑₚₜ yₒᵤᵣ ₚᵣᵢdₑ ☢ [ ᴇxᴘʟᴏɪᴛᴇʀ ] ☢
https://www.blackbug.org
User avatar
CrazyCat
Revered One
Posts: 1348
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: weather tcl script snippet from http://wttr.in

Post by CrazyCat »

Warning !
mortmann noticed this script uses exec without sanytizing $location, so it's possible to inject bad code.

@nobody: you'd better use the http package rather than curl: you'll won't have to use exec anymore and the script can also work with windrop. Or with shell which haven't curl installed.
Post Reply