############################### ## Horoscope TcL v2.0 ## ## By H4_Kim ## ############################### ############################### package require http 2.3 setudef flag horoscope # set configuration namespace eval incith { namespace eval horoscope { variable command_char "!" variable binds "zodiak" variable bind_signs 1 variable private_messages 1 variable split_length 500 variable bold_descriptions 1 variable ignore 1 variable flood 4:10 } } # end of configuration, script begins namespace eval incith { namespace eval horoscope { variable version "Astrologi.tcl v2.0" variable valid_signs "capricorn aquarius pisces aries taurus gemini cancer leo virgo libra scorpio sagitarius" } } # bind the public binds foreach bind [split $incith::horoscope::binds " "] { bind pub -|- "${incith::horoscope::command_char}$bind" incith::horoscope::public_message } # bind the private message binds if {$incith::horoscope::private_messages >= 1} { foreach bind [split $incith::horoscope::binds " "] { bind msg -|- "${incith::horoscope::command_char}$bind" incith::horoscope::private_message } } # bind each of the signs if {$incith::horoscope::bind_signs >= 1} { foreach sign [split $incith::horoscope::valid_signs " "] { bind pubm -|- "*${incith::horoscope::command_char}${sign}" incith::horoscope::public_message if {$incith::horoscope::private_messages >= 1} { bind msgm -|- "*${incith::horoscope::command_char}${sign}" incith::horoscope::private_message } } } namespace eval incith { namespace eval horoscope { # HOROSCOPE # performs a search on http://astaga.com/astrologi/ # proc horoscope {input} { # local variable initialization ; set results 0 ; set output "" # fetch the html set html [fetch_html $input] # parse the html regexp {
(.*?)
} $html - horoscope regexp {Asmara :(.*?)
} $html - asm regexp {Keuangan :(.*?)
} $html - keu regexp {Pekerjaan :(.*?)
} $html - pek # if we can't find the sign or the horoscope, assume the website probably changed if {[info exists sign] == 0 || [info exists horoscope] == 0} { return "waduh..Koneksi Ke Astaga.Com kOk GagaL! ya...cOba Lagi dEh" } # this removes trailing spaces from the horoscope set horoscope [string trimright $horoscope] append horoscope "\017" # bold the sign if wanted if {$incith::horoscope::bold_descriptions > 0} { set sign "\002\0038,4${sign}\002\003" set info "\002\00311,1.::zOdIaC TcL By H4_Kim::.\002\003" } # make a reply append output "${info} ${sign}: ${horoscope} \002\0030,1Asmara:\002\003 ${asm} \002\0030,1Keuangan:\002\003 ${keu} \002\0030,1Pekerjaan:\002\003 ${pek}" # make sure we have something to send if {[info exists output] == 0} { return "waduh..Koneksi Ke Astaga.Com kOk GagaL! ya...cOba Lagi dEh" } return $output } # FETCH_HTML # fetches html for http://astaga.com/astrologi/ # proc fetch_html {input} { set query "http://astaga.com/" set input [string tolower $input] # request the daily horoscope for $input set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e" set http [::http::config -useragent $ua] set chinese_signs "rat ox tiger rabbit dragon snake horse goat monkey rooster dog pig" set http [::http::geturl "${query}astrologi/index.php?cat=${input}" -timeout [expr 1000 * 15]] foreach sign [split $chinese_signs " "] { if {$input == $sign} { set http [::http::geturl "${query}dailychinese${input}.html" -timeout [expr 1000 * 15]] break } } set html [::http::data $http] if {[info exists html] == 0} { return "waduh..Koneksi Ke Astaga.Com kOk GagaL! ya...cOba Lagi yAkz" } # generic regsub -all "(?:\x91|\x92|')" $html {'} html regsub -all "(?:\x93|\x94|")" $html {"} html regsub -all "&" $html {\&} html regsub -all "×" $html {*} html regsub -all " " $html { } html regsub -all -nocase "×" $html "x" html regsub -all -nocase "<" $html "<" html regsub -all -nocase ">" $html ">" html regsub -all "\n" $html "" html return $html } # PUBLIC_MESSAGE # decides what to do with binds that get triggered # proc public_message {nick uhand hand chan input} { if {[lsearch -exact [channel info $chan] +horoscope] != -1} { # flood protection check if {[flood $nick $uhand]} { return } regsub -- "^${incith::horoscope::command_char}" $input "" input send_output $input $chan } } # PRIVATE_MESSAGE # decides what to do with binds that get triggered # proc private_message {nick uhand hand input} { if {$incith::horoscope::private_messages >= 1} { # flood protection check if {[flood $nick $uhand]} { return } regsub -- "^${incith::horoscope::command_char}" $input "" input send_output $input $nick } } } } # support routines namespace eval incith { namespace eval horoscope { # SEND_OUTPUT # no point having two copies of this in public/private_message{} # proc send_output {input where} { foreach line [incith::horoscope::parse_output [horoscope $input]] { putquick "PRIVMSG $where :$line" } } # PARSE_OUTPUT # prepares output for sending to a channel/user, calls line_wrap # proc parse_output {input} { set parsed_output [set parsed_current {}] regsub {\s*$} $input {} input foreach line [incith::horoscope::line_wrap $input] { lappend parsed_output $line } return $parsed_output } # LINE_WRAP # takes a long line in, and chops it before the specified length # http://forum.egghelp.org/viewtopic.php?t=6690 # proc line_wrap {str {splitChr { }}} { set out [set cur {}] set i 0 set len $incith::horoscope::split_length regsub -all "\002" $str "