#### # AUTHOR: # AltBlue http://www.altblue.com/ ### # DESCRIPTION: # show money exchange rates #### # CHANGELOG: # * 2004.11.25: # - first version #### # # CONFIGURATION: # VERSION. do not carelessly modify it! set abv(version) "ABMoney/20042224" # database setup... set abv(db_host) "[HOSTNAME]" set abv(db) "[DATABASE]" set abv(db_user) "[USERNAME]" set abv(db_pass) "[PASSWORD]" set abv(table) "valute" set abv(cod) "cod" set abv(data) "data" set abv(curs) "curs" # flood protection, in the form x:y. Any queries beyond x in y seconds is considered a flood and ignored. set abv(flood) 6:15 # switch for ignoring flooders (1=on) set abv(ignore) 1 # define the amount of time a flooder is ignored (minutes). # (this is meaningless if abv(ignore) is 0) set abv(ignore_time) 2 ### bindings catch {unbind pub v !valuta abv_pub_curs} bind pub v !valuta abv_pub_curs catch {unbind pub v !valute abv_pub_curs} bind pub v !valute abv_pub_curs catch {unbind msg - valuta abv_msg_curs} bind msg - valuta abv_msg_curs catch {unbind msg - valute abv_msg_curs} bind msg - valute abv_msg_curs ########################################### #### BE SMART! Don't modify anything below. ################################################################## package require mysqltcl ########## Flood Protection proc abv_flood {nick uhost} { global abv abv_flood_array if {$abv(flood_num) == 0} {return 0} set i [expr $abv(flood_num) - 1] while {$i >= 1} { set abv_flood_array($i) $abv_flood_array([expr $i - 1]) incr i -1 } set abv_flood_array(0) [unixtime] if {[expr [unixtime] - $abv_flood_array([expr $abv(flood_num) - 1])] <= $abv(flood_time)} { putlog "$abv(version): Flood detected from $nick." if {$abv(ignore)} { newignore [join [maskhost *!*[string trimleft $uhost ~]]] $abv(version) flood $abv(ignore_time) } return 1 } {return 0} } proc abv_flood_init {} { global abv abv_flood_array if {![string match *:* $abv(flood)]} { putlog "$abv(version): var abv(flood) not set correctly." return 0 } set abv(flood_num) [lindex [split $abv(flood) :] 0] set abv(flood_time) [lindex [split $abv(flood) :] 1] set i [expr $abv(flood_num) - 1] while {$i >= 0} { set abv_flood_array($i) 0 incr i -1 } } abv_flood_init ############## VALUTE proc abv_pub_curs {nick uhost hand chan arg} { if {[abv_flood $nick $uhost]} {return 0} putcmdlog "($chan) $nick: VALUTE" putserv "PRIVMSG $chan :$nick: [abv_curs]" } proc abv_msg_curs {nick uhost hand arg} { if {[abv_flood $nick $uhost]} {return 0} putcmdlog "$nick: VALUTE" putserv "NOTICE $nick :[abv_curs]" } ############################################################################### ############################################################################### ######################## INTERNAL ROUTINES #################################### ############################################################################### ############################################################################### ########## SEARCH term proc abv_curs {} { global abv set res [catch {set dbh [mysqlconnect -host $abv(db_host) -user $abv(db_user) -password $abv(db_pass) -db $abv(db)]} msg] if {$res != 0} { putlog "$abv(version): ERROR!!! $msg" return "Ouch, cannot connect to database!" } set q [mysqlquery $dbh "SELECT $abv(cod),$abv(curs) FROM $abv(table) WHERE $abv(cod) IN ('USD','EUR') GROUP BY $abv(cod),$abv(data) ORDER BY $abv(data) DESC, $abv(cod) LIMIT 2"] set answer "" while {[set row [mysqlnext $q]] != ""} { append answer "[lindex $row 0]: [lindex $row 1], " } mysqlendquery $q mysqlclose $dbh set answer [string trimright $answer {, }] append answer . return $answer } putlog "$abv(version) loaded."