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 

TLS invalid command

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


Joined: 09 Apr 2006
Posts: 11

PostPosted: Fri Jun 18, 2021 8:41 am    Post subject: TLS invalid command Reply with quote

Hi,

I have this crypto currency TCL, but I'm getting this error on telnet.
what could it be?


Quote:
[14:33:54] Cryptocurrency check: nick requested [bitcoin] at #channel
[14:33:54] Tcl error [::cryptocheck::cryptocheckpub]: invalid command name "tls:socket"



Code:

# antsy's cryptocurrency price check script

package require Tcl
package require http
package require json
package require tls
package require tls 1.6.7


namespace eval cryptocheck {

# Eggdrop bindings
bind pub - !crypto [namespace current]::cryptocheckpub
bind msg f !crypto [namespace current]::cryptocheckmsg

# Global variables
set ccVersion "Cryptocurrency price check script 1.0"
set outputCurrency "eur"
set outputSymbol ""

putlog "Loaded script $ccVersion"

##
# Handler for calling the script via public message
#
# @param nick    User nickname
# @param host    User hostname
# @param handle  User in bot
# @param channel Channel
# @param text    Parameters
proc cryptocheckpub {nick host handle channel text} {
  putlog "Cryptocurrency check: $nick ($handle/$host) requested \[$text\] at $channel"
  if {$text == ""} {
    variable ccVersion
    msg $channel "$ccVersion - Usage: !crypto <bitcoin/ethereum/ripple/etc...> (you can query multiple, separated by space)"
    return
  }
  # Clean input
  set text [string trim $text]

  set currency [split $text " "]
  set output [fetch $currency]
  putlog $output
  set output [prettyPrint $output]
  putlog $output

  set length [string length $output]
  if {$length > 1} {
    msg $channel $output
  }
}

##
# Handler for calling the script via public message
#
# @param nick    User nickname
# @param uhost   User hostname
# @param handle  User in bot
# @param text    Parameters
proc cryptocheckmsg {nick uhost handle text} {
  putlog "Cryptocurrency check: $nick ($handle!$uhost) requested \[$text\] as privmsg"
  if {$text == ""} {
    variable ccVersion
    msg $nick "$ccVersion - Usage: !crypto <bitcoin/ethereum/ripple/etc...> (you can query multiple, separated by space)"
    return
  }
  # Clean input
  set text [string trim $text]

  set currency [split $text " "]
  set output [fetch $currency]
  set output [prettyPrint $output]

  set length [string length $output]
  if {$length > 1} {
    msg $nick $output
  }
}

##
# Send response to user.
# Separates output to multiple lines if the message is too long (for IRCnet)
#
# @param dest   Target, can be nick or channel.
# @param data   The message.
proc msg {dest data} {
   set len [expr {512-[string len ":$::botname PRIVMSG $dest :\r\n"]}]
   foreach line [wordwrap $data $len] {
      puthelp "PRIVMSG $dest :$line"
   }
}

proc wordwrap {data len} {
   set out {}
   foreach line [split [string trim $data] \n] {
      set curr {}
      set i 0
      foreach word [split [string trim $line]] {
         if {[incr i [string len $word]]>$len} {
            lappend out [join $curr]
            set curr [list $word]
            set i [string len $word]
         } {
            lappend curr $word
         }
         incr i
      }
      if {[llength $curr]} {
         lappend out [join $curr]
      }
   }
   set out
}

##
# Format the result data
#
# @param coinData   Result data Dictionary from Coingecko
# @return           Message formatted for IRC
proc prettyPrint { data } {
  set output [list]
  variable outputCurrency
  variable outputSymbol
  dict for {coinName coinData} $data {
    dict with coinData {
      set coinValue [subst $$outputCurrency]
      if {$coinValue > 0.001} {
        # Round to 3 decimals unless value is really small
        set coinValue [format {%0.3f} $coinValue]
      }
      set valueChange [formatValueChange $eur_24h_change]
      set outdatedWarning [checkLastUpdated $last_updated_at]
      set additionalInfo [join [list " (" $valueChange "%)"] ""]
      if {$outdatedWarning != ""} {
        # Really it makes no sense to display 24h values if the value is old so let's display warning message there instead
        set additionalInfo [join [list " (" [colorize $outdatedWarning 5] ")"] ""]
      }

      set str [join [list $coinName ": " [bold $coinValue] $outputSymbol $additionalInfo] ""]
      lappend output $str
    }
  }

  return [join $output " "]
}

##
# Format value change percentage
#
# @param  eur_24h_change  Change in the last twenty four hours
# @return                 Formatted string
proc formatValueChange {eur_24h_change} {
  set valueChange "0.0"
  if [string is double -strict $eur_24h_change] {
    set valueChange [format {%+0.2f} $eur_24h_change]
  }

  if {$eur_24h_change > 0} {
    # Value gone up, color it green
    set valueChange [colorize $valueChange 3]
  } else {
    # Value gone down, color it red
    set valueChange [colorize $valueChange 4]
  }

  return $valueChange
}

##
# Check if the value is too old (older than one hour)
#
# @param  last_updated_at  UNIX timestamp
# @return                  Error message
proc checkLastUpdated {last_updated_at} {
  set now [clock seconds]
  set oneHour 3600
  set timeDiff [expr {$now - $last_updated_at}]
  if {$timeDiff > $oneHour} {
    set hours [expr {$timeDiff / $oneHour}]
    set hours [expr {round($hours)}]
    if {$hours == 1} {
      set warningText "Warning! the value is hour old"
    } else {
      set warningText "Warning! the value is $hours hours old"
    }
    if {$hours > 23} {
      set days [expr {$hours / 24}]
      set days [expr round($days)]
      if {$days == 1} {
        set warningText "Warning! the value is day old"
      } else {
        set warningText "Warning! the value is $days days old"
      }
    }
    return [colorize $warningText 6]
  }
  return ""
}

##
# Colorize string and reset back to default color
#
# @param str    String to be colorized
# @param color  VGA color
proc colorize {str color} {
  set output "\003$color"
  append output $str
  append output "\003"
  return $output
}

##
# Bold string
#
# @param  str   Input string
# @return       Formatted string
proc bold {str} {
  return "\002$str\002"
}

##
# Fetches the prices from the Coingecko's free API.
#
# @see https://www.coingecko.com/api/documentations/v3
#
# @param currency    Currency or currencies to check
# @return {dict}     Result from request
proc fetch { currency } {
  variable ccVersion
  variable outputCurrency
  set ids [join $currency "%2C"]
  set url "https://api.coingecko.com/api/v3/simple/price?ids=${ids}&vs_currencies=${outputCurrency}&include_last_updated_at=true&include_24hr_change=true"

#  ::http::register https 443 [list ::tls::socket -autoservername true -require 0 -request 1]

proc tls:socket args {
    set opts [lrange $args 0 end-2]
    set host [lindex $args end-1]
    set port [lindex $args end]

    # From version 1.6.7, it shouldn't be necessary to specify any ciphers.  If
    # that's not true, please report your experience on this page.
    # [APN] I think you misunderstand the full motivation for -ssl3 false. If you leave
    # it out, you will afaik land up talking SSL3 if the server does not mind SSL3.
    # That's something you generally don't want. Unless 1.6.7 has completely disabled
    # SSL3 support which I don't think it has.
    ::tls::socket -servername $host {*}$opts $host $port

    #If that doesn't work, try this
    ::tls::socket -ssl3 false -ssl2 false -tls1 true -servername $host {*}$opts $host $port

    # And if that doesn't work, try this
    # ::tls::socket -ssl3 false -ssl2 false -tls1 true -tls1.2 false -tls1.1 false \
    #    -servername $host {*}$opts $host $port
   
}

# using the http package also needs this:
package require http
http::register https 443 tls:socket

  set token [http::config -useragent "$ccVersion"]
  set token [http::geturl $url]

  set result [json::json2dict [http::data $token]]

  http::cleanup $token
  return $result
}

} ;#end namespace
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3734
Location: Mint Factory

PostPosted: Fri Jun 18, 2021 10:00 am    Post subject: Reply with quote

Replace:
Code:

http::register https 443 tls:socket

with:
Code:

http::register https 443 [namespace current]::tls:socket

_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
fauves
Voice


Joined: 09 Apr 2006
Posts: 11

PostPosted: Fri Jun 18, 2021 10:35 am    Post subject: Reply with quote

Works like a charm.
Thanks
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