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
}