qotd.tcl [solved]

Active 7 Replies 268 Views 2022-12-31 00:30:41 TCL Support
Hi Sir, can you help me to fixed this? Kudos Sir, Happy New Year!

# Procedure to retrieve a random quote from the website
proc get_random_quote {url} {
  package require http
  package require html
  package require tls
  http::register https 443 [list ::tls::socket -tls1 1]
  # Retrieve the HTML data from the website
  set cookie [http::geturl $url]
  set data [http::data $cookie]
  # Parse the HTML data using the html package
  set html [html::parse $data]
  # Extract the quote and author from the HTML
  set quote [html::select $html "div.quoteText"]
  set author [html::select $html "div.authorText"]
  # Return the quote and author
  return [list $quote $author]
}
# Procedure to handle the "!quote" command in the IRC channel
proc quote {nick uhost hand chan text} {
  # Get a random quote from the website
  set quote_info [get_random_quote "https://www.goodreads.com/quotes/random"]
  # Check if the quote was successfully retrieved
  if {[llength $quote_info] == 2} {
    # Extract the quote and author from the returned list
    set quote [lindex $quote_info 0]
    set author [lindex $quote_info 1]
    # Split the quote into a list of words
    set words [split $quote]
    # Initialize an empty list to store the colored words
    set colored_words {}
    # Iterate through each word in the quote
    foreach word $words {
      # Generate a random color code
      set color [format "#%02x%02x%02x" [expr {int(rand()*256)}] [expr {int(rand()*256)}] [expr {int(rand()*256)}]]
      # Add the colored word to the list of colored words
      lappend colored_words [format "\003%s%s" $color $word]
    }
    # Join the colored words into a single string
    set colored_quote [join $colored_words " "]
    # Send the colored quote to the channel
    putserv "PRIVMSG $chan :$colored_quote - $author"
  } else {
    # Send an error message if the quote was not retrieved
    putserv "PRIVMSG $chan :Unable to retrieve quote of the day"
  }
}
# Bind the "!quote" command to the quote procedure
bind pub -|- !quote quote
ventura.kevin52844 replied
1 Year
I'm using latest http tcl Sir. 
BLaCkShaDoW replied
1 Year
Both versions of the tcl worked for me. Please check If you have the latest http.tcl
ventura.kevin52844 replied
1 Year
Hello Sir,
Great, but another error appear the following:
Tcl error [goodreads:randomQuote]: list element in quotes followed by " Tcl error [goodreads:randomQuote]: list element in quotes followed by "Why" instead of space
Kudos Sir!
BLaCkShaDoW replied
1 Year
Download it and try it again.
ventura.kevin52844 replied
1 Year
Hi Sir,
Happy New Year, the qotd.tcl gets error
[23:03:03] Tcl error [goodreads:randomQuote]: list element in braces followed by "{}{—ShelSilverstei" instead of space
Kudos Sir!
BLaCkShaDoW replied
1 Year
It's done, downoad it from here: https://www.tclscripts.net/product/qotd-tcl/
BLaCkShaDoW replied
1 Year
i will see what i can do.
loading...