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.

somebody can help me to repair forex.tcl ??

Help for those learning Tcl or writing their own scripts.
Post Reply
p
planetdata
Voice
Posts: 5
Joined: Tue Nov 22, 2005 10:38 pm

somebody can help me to repair forex.tcl ??

Post by planetdata »

Code: Select all

set fx_debug 0
set fx_chans "*"
set fx_command "@rate"
set fx_search "@symbol"
set fx_flags "-|-"
# exempt from flood and can use commands on _any_ channel
set fx_exempt "n|n"
# number:seconds:disable
set fx_flood 5:20:120
set fx_maxresults 5
# %nick %mkttime %fromresult %fromsymbol %toresult %tosymbol %exrate %extime %timezone
set fx_format {
  "%nick: %fromresult (%fromsymbol) = %toresult (%tosymbol) \[Rate: %exrate at %extime %timezone\]  \[Updated: %mkttime\]"
}
set fx_timezone "SGT"
set fx_symbols {
  {AFA {Afghanistan Afghani}}
  {ALL {Albanian Lek}}
  {DZD {Algerian Dinar}}
  {ADF {Andorran Franc}}
  {ADP {Andorran Peseta}}
  {ARS {Argentine Peso}}
  {AWG {Aruba Florin}}
  {AUD {Australian Dollar}}
  {ATS {Austrian Schilling}}
  {BSD {Bahamian Dollar}}
  {BHD {Bahraini Dinar}}
  {BDT {Bangladesh Taka}}
  {BBD {Barbados Dollar}}
  {BEF {Belgian Franc}}
  {BZD {Belize Dollar}}
  {BMD {Bermuda Dollar}}
  {BTN {Bhutan Ngultrum}}
  {BOB {Bolivian Boliviano}}
  {BWP {Botswana Pula}}
  {BRL {Brazilian Real}}
  {GBP {British Pound}}
  {BND {Brunei Dollar}}
  {BIF {Burundi Franc}}
  {KHR {Cambodia Riel}}
  {CAD {Canadian Dollar}}
  {KYD {Cayman Islands Dollar}}
  {CLP {Chilean Peso}}
  {CNY {Chinese Yuan}}
  {COP {Colombian Peso}}
  {KMF {Comoros Franc}}
  {CRC {Costa Rica Colon}}
  {HRK {Croatian Kuna}}
  {CYP {Cyprus Pound}}
  {CUP {Cuban Peso}}
  {CZK {Czech Koruna}}
  {DKK {Danish Krone}}
  {DOP {Dominican Peso}}
  {NLG {Dutch Guilder}}
  {XCD {East Caribbean Dollar}}
  {ECS {Ecuadorian Sucre}}
  {EGP {Egyptian Pound}}
  {SVC {El Salvador Colon}}
  {EEK {Estonian Kroon}}
  {EUR {Euro}}
  {ETB {Ethiopian Birr}}
  {FKP {Falkland Islands Pound}}
  {FJD {Fiji Dollar}}
  {FIM {Finnish Mark}}
  {FRF {French Franc}}
  {GMD {Gambian Dalasi}}
  {DEM {German Mark}}
  {GHC {Ghanian Cedi}}
  {GIP {Gibraltar Pound}}
  {XAU {Gold Ounces}}
  {GRD {Greek Drachma}}
  {GTQ {Guatemala Quetzal}}
  {GNF {Guinea Franc}}
  {GYD {Guyana Dollar}}
  {HTG {Haiti Gourde}}
  {HNL {Honduras Lempira}}
  {HKD {Hong Kong Dollar}}
  {HUF {Hungarian Forint}}
  {ISK {Iceland Krona}}
  {IDR {Indonesian Rupiah}}
  {INR {Indian Rupee}}
  {IRD {Iragi Dinar}}
  {IEP {Irish Punt}}
  {ILS {Israeli Shekel}}
  {ITL {Italian Lira .L}}
  {JPY {Japanese Yen}}
  {JMD {Jamaican Dollar}}
  {JOD {Jordanian Dinar}}
  {KZT {Kazakhstan Tenge}}
  {KES {Kenyan Shilling}}
  {KRW {Korean Won}}
  {KWD {Kuwaiti Dinar}}
  {LBP {Lebanese Pound}}
  {LRD {Liberian Dollar}}
  {LYD {Libyan Dinar}}
  {LUF {Luxembourg Franc}}
  {MOP {Macau Pataca}}
  {MYR {Malaysian Ringgit}}
  {MVR {Maldives Rufiyaa}}
  {MUR {Mauritius Rupee}}
  {MXN {Mexican Nuevo Peso}}
  {MNT {Mongolian Tugrik}}
  {MAD {Moroccan Dirham}}
  {MZM {Mozambique Metical}}
  {MMK {Myanmar Kyat}}
  {NAD {Namibian Dollar}}
  {NZD {New Zealand Dollar}}
  {NPR {Nepalese Rupee}}
  {NIO {Nicaragua Cordoba}}
  {KPW {North Korean Won}}
  {NOK {Norwegian Krone}}
  {OMR {Omani Rial}}
  {PKR {Pakistani Rupee}}
  {PAB {Panama Balboa}}
  {PGK {Papua New Guinea Kina}}
  {PYG {Paraguayan Guarani}}
  {XPT {Platinum Ounces}}
  {PHP {Philippine Peso}}
  {PTE {Portuguese Escudo}}
  {QAR {Qatar Rial}}
  {RUB {Russian Rouble}}
  {SOS {Somali Shilling}}
  {ZAR {South African Rand}}
  {LKR {Sri Lanka Rupee}}
  {XAG {Silver Ounces}}
  {SGD {Singapore Dollar}}
  {ESP {Spanish Peseta}}
  {SDD {Sudanese Dinar}}
  {SRG {Surinam Guilder}}
  {SEK {Swedish Krona}}
  {CHF {Swiss Franc}}
  {TWD {Taiwan Dollar}}
  {THB {Thai Baht}}
  {TND {Tunisian Dinar}}
  {TRL {Turkish Lira}}
  {USD {U.S. Dollar}}
  {UYU {Uruguayan New Peso}}
  {UGX {Ugandan Shilling}}
  {UAH {Ukraine Hryvnia}}
  {VND {Vietnam Dong}}
  {VEB {Venezuelan Bolivar}}
  {YUM {Yogoslav Dinar}}
  {ZMK {Zambian Kwacha}}
  {ZWD {Zimbabwe Dollar}}
}


# Don't edit below unless you know what you're doing.

if {[catch {package require http}]} {
  putlog "forex: Error - could not find package 'http'. Script not loaded. Make sure you are running Tcl 8.0 or later."
}

proc fx_get {amount from to} {
  global fx_debug
  if {[catch {::http::geturl http://sg.finance.yahoo.com/m5?a=$amount&s=$from&t=$to} token]} {
    return "noconnect"
  }
  set lines [split [::http::data $token] \n]
  unset $token
  if {$fx_debug} {
    set wfile [open forex_debug.txt w]
    puts -nonewline $wfile [join $lines \n]
    close $wfile
  }
  if {[set firstline [lsearch -exact $lines "Conversion</font></b></big></td></tr></table>"]] != -1} {
    set lines [lrange $lines $firstline end]
  } else {
    return {baddata firstline}
  }
  set line [lindex $lines 3]
  set line [string range $line [expr [string first ">" $line] + 1] end]
  set mkttime [string range $line 0 [expr [string first "<" $line] - 1]]
  set line [lindex $lines 8]
  set line [string range $line [expr [string first "</a></th><th>" $line] + 13] end]
  set fromresult [string range $line 0 [expr [string first "<" $line] - 1]]
  set line [string range $line [expr [string first "<th nowrap>" $line] + 11] end]
  set extime [string range $line 0 [expr [string first "<" $line] - 1]]
  set line [string range $line [expr [string first "</th><td>" $line] + 9] end]
  set exrate [string range $line 0 [expr [string first "<" $line] - 1]]
  set line [string range $line [expr [string first "</td><td><b>" $line] + 12] end]
  set toresult [string range $line 0 [expr [string first "<" $line] - 1]]
  if {$mkttime == ""} {
    return {baddata mkttime}
  }
  if {$fromresult == ""} {
    return {baddata fromresult}
  }
  if {$extime == ""} {
    return {baddata extime}
  }
  if {$exrate == ""} {
    return {baddata exrate}
  }
  if {$toresult == ""} {
    return {baddata toresult}
  }
  return [list $mkttime $fromresult $toresult $exrate $extime]
}

proc fx_pubforex {nick uhost hand chan arg} {
  global fx_command fx_format fx_search fx_symbol fx_timezone
  if {[fx_cmdcheck $hand $chan]} {return 0}
  set splitarg [split $arg]
  if {[llength $splitarg] >= 3} {
    set amount [lindex $splitarg 0]
    set from [string toupper [lindex $splitarg 1]]
    set to [string toupper [lindex $splitarg 2]]
  } else {
    set amount 1
    set from [string toupper [lindex $splitarg 0]]
    set to [string toupper [lindex $splitarg 1]]
  }
  if {$amount == "" || $from == "" || $to == ""} {
    puthelp "NOTICE $nick :Usage: $fx_command \[amount\] <from currency> <to currency>"
    puthelp "NOTICE $nick :If no amount is specified, it will default to '1'. You must specify currency symbols (e.g. $fx_command 120 USD IND). To look up a symbol for a currency, type $fx_search <country name>"
    return 0
  }
  if {[catch {expr abs($amount)}]} {
    puthelp "NOTICE $nick :$amount is not a numeric value."
    return 0
  }
  if {[string length $amount] > 20} {
    puthelp "NOTICE $nick :Please limit the amount to 20 characters or less."
    return 0
  }
  if {![info exists fx_symbol($from)]} {
    puthelp "NOTICE $nick :$from is not a valid currency symbol. To look up a symbol for a currency, type $fx_search <country name>"
    return 0
  }
  if {![info exists fx_symbol($to)]} {
    puthelp "NOTICE $nick :$to is not a valid currency symbol. To look up a symbol for a currency, type $fx_search <country name>"
    return 0
  }
  set results [fx_get $amount $from $to]
  if {[lindex $results 0] == "noconnect"} {
    puthelp "PRIVMSG $chan :$nick: unable to connect to currency server."
    return 0
  } elseif {[lindex $results 0] == "baddata"} {
    puthelp "PRIVMSG $chan :$nick: bad data in '[lindex $results 1]' from currency server - please notify the bot admin."
    return 0
  }
  foreach line $fx_format {
    regsub -all -- "%nick" $line $nick line
    regsub -all -- "%mkttime" $line [lindex $results 0] line
    regsub -all -- "%fromresult" $line [lindex $results 1] line
    regsub -all -- "%fromsymbol" $line $fx_symbol($from) line
    regsub -all -- "%toresult" $line [lindex $results 2] line
    regsub -all -- "%tosymbol" $line $fx_symbol($to) line
    regsub -all -- "%exrate" $line [lindex $results 3] line
    regsub -all -- "%extime" $line [lindex $results 4] line
    regsub -all -- "%timezone" $line $fx_timezone line
    puthelp "PRIVMSG $chan :$line"
  }
  return 1
}

proc fx_pubsearch {nick uhost hand chan arg} {
  global fx_maxresults fx_search fx_symbol
  if {[fx_cmdcheck $hand $chan]} {return 0}
  if {$arg == ""} {
    puthelp "NOTICE $nick :Usage: $fx_search <search string>"
    return 0
  }
  foreach symbol [array names fx_symbol] {
    if {[string match *[string tolower $arg]* [string tolower $fx_symbol($symbol)]]} {
      lappend results "$symbol $fx_symbol($symbol)"
    }
  }
  if {[info exists results]} {
    if {[llength $results] > $fx_maxresults} {
      puthelp "NOTICE $nick :Found [llength $results] result(s) for '$arg', displaying first $fx_maxresults"
    } else {
      puthelp "NOTICE $nick :Found [llength $results] result(s) for '$arg'"
    }
    foreach result [lrange $results 0 [expr $fx_maxresults - 1]] {
      puthelp "NOTICE $nick :$result"
    }
  } else {
    puthelp "NOTICE $nick :No matches for '$arg'."
  }
  return 1
}

proc fx_cmdcheck {hand {chan ""}} {
  global fx_chans fx_exempt fx_flood fx_flooded fx_floodqueue
  if {$fx_flooded} {return 1}
  if {$chan != ""} {
    if {$fx_exempt != "" && [matchattr $hand $fx_exempt $chan]} {return 0}
    if {[lsearch -exact $fx_chans [string tolower $chan]] == -1} {return 1}
  } else {
    if {$fx_exempt != "" && [matchattr $hand $fx_exempt]} {return 0}
  }
  incr fx_floodqueue
  utimer [lindex $fx_flood 1] {incr fx_floodqueue -1}
  if {$fx_floodqueue >= [lindex $fx_flood 0]} {
    set fx_flooded 1
    utimer [lindex $fx_flood 2] {set fx_flooded 0}
    putlog "forex: Flooding detected - disabling commands for [lindex $fx_flood 2] seconds."
    return 1
  }
  return 0
}

foreach fx_tempsymbol $fx_symbols {
  set fx_symbol([lindex $fx_tempsymbol 0]) [lindex $fx_tempsymbol 1]
}

unset fx_symbols

set fx_chans [split [string tolower $fx_chans]]

set fx_flood [split $fx_flood :]
if {![info exists fx_flooded]} {
  set fx_flooded 0
}
if {![info exists fx_floodqueue]} {
  set fx_floodqueue 0
}

::http::config -useragent "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)"

bind pub $fx_flags $fx_command fx_pubforex
bind pub $fx_flags $fx_search fx_pubsearch

if {![info exists nb_component([file tail [file rootname [info script]]])]} {
  putlog "forex.tcl loaded"
}

return "nb_info 1.27.0"

the error msg from the bot :
bad data in 'firstline' from currency server - please notify the bot admin.

somebody can help me??
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

bad data in 'firstline' from currency server - please notify the bot admin.
Missing something?
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Post Reply