Pages

Sunday, August 28, 2011

horoscope.tcl

# Script TCL pour obtenir l'horoscope sur IRC
# Version 0.3 Par CrazyCat (01/2006) <http://www.c-p-f.org>
#
# Basé sur Horoscope
# Ecrit par "laruiss" version 0.1 (2004)
# note : récupère l'horoscope du site linternaute.com

# MODIFICATIONS
# Version 0.3
# - Possibilité de demande par /msg
# - En canal, limitation à 1 demande par minute
# Version 0.2
# - Ajout de l'horoscope mensuel
# - Appel par !horo ou !horoscope

package require http

bind pub - !horoscope pub_horo
bind pub - !horo pub_horo
bind msg - !horoscope msg_horo
bind msg - !horo msg_horo

proc no_accent {code_text} {
   regsub -all é $code_text "e" code_text
   regsub -all è $code_text "e" code_text
   regsub -all ê $code_text "e" code_text
   regsub -all ï $code_text "i" code_text
   regsub -all ï $code_text "i" code_text
   regsub -all ù $code_text "u" code_text
   regsub -all ô $code_text "o" code_text
   regsub -all ç $code_text "c" code_text
   regsub -all à $code_text "a" code_text
   regsub -all â $code_text "a" code_text
   return $code_text
}

set working 0
unset working

proc pub_horo {nick uhost handle chan arg} {
if {[info exists ::working]} {
putquick "PRIVMSG $chan :Veuillez attendre 1 minute entre deux interrogations sur le canal"
return 0
}
horoscope $nick $arg "chan" $chan
set ::working 1
utimer 60 [list unset ::working]
}

proc msg_horo {nick uhost handle arg} {
horoscope $nick $arg "nick" $nick
}

proc horoscope {nick arg methode victim} {
if {[llength [split $arg]] > 1} {
set aduree [lindex [split $arg] 1]
} else {
set aduree "jour"
}
switch -regexp [lindex [split $arg] 0] {
^[Bb][ée]lier$ {
set disp_sign "Bélier"
}
^[Tt]aure?aux?$ {
set disp_sign "Taureau"
}
^[Gg][ée]meaux?$ {
set disp_sign "Gémeaux"
}
^[Cc]ancer$ {
set disp_sign "Cancer"
}
^[Ll]ions?$ {
set disp_sign "Lion"
}
^[Vv]ierges?$ {
set disp_sign "Vierge"
}
^[Bb]alances?$ {
set disp_sign "Balance"
}
^[Ss]corpions?$ {
set disp_sign "Scorpion"
}
^[Ss]agitt?airr?es?$ {
set disp_sign "Sagittaire"
}
^[Cc]apricornes?$ {
set disp_sign "Capricorne"
}
^[Vv]erse?aux?$ {
set disp_sign "Verseau"
}
^[Pp]oissons?$ {
set disp_sign "Poissons"
}
default {
putquick "PRIVMSG $nick :Utilisation du TCl: !horoscope \002<signe>\002 <période>"
putquick "PRIVMSG $nick :   signe: le signe pour lequel vous désirez l'horoscope (obligatoire)"
putquick "PRIVMSG $nick :   période: jour, semaine ou mois (par défaut: jour)"
putquick "PRIVMSG $nick :[lindex [split $arg] 0] n'est pas un signe connu"
return 0
}
}
switch $aduree {
"jour" {
set duree "jour"
}
"semaine" {
set duree "semaine"
}
"mois" {
set duree "mois"
}
default {
set duree "jour"
}
}
get_horoscope $disp_sign $duree $methode $victim
return
}

proc get_horoscope { disp_sign duree methode victim } {
set sign [string tolower [no_accent $disp_sign]]
set token [http::geturl http://www.linternaute.com/femmes/horoscope/$duree/$sign/]
set horoscope_page [::http::data $token]
if {$duree == "jour"} {
regsub -all {.*<font size="2" face="Arial, Helvetica, sans-serif" color="#941E38"><br>([^<]+)</font>.*Vie privée :.*size="2">([^<]+)</font>.*Vie quotidienne : .*size="2">([^<]+)</font>} $horoscope_page "=date\\1=viep\\2=vieq\\3" horoscope
regsub -all -- {=date([^=]+)=.*} $horoscope "\\1" ladate
regsub -all -- {.*=viep([^=]+)=.*} $horoscope "\\1" viep
regsub -all -- {.*=vieq(.+)} $horoscope "\\1" vieq
putquick "PRIVMSG $victim :\002$disp_sign\002 : horoscope du jour (\002$ladate\002)"
putquick "PRIVMSG $victim :\002Vie privée :\002 $viep"
putquick "PRIVMSG $victim :\002Vie quotidienne :\002 $vieq"
} elseif {$duree == "semaine"} {
regsub -all {.*<font size="2" face="Arial, Helvetica, sans-serif" color="#999999"><br>([^<]+)</font>.*Vie privée :.*size="2">([^<]+)</font>.*Vie quotidienne : .*size="2">([^<]+)</font>.*Vie professionnelle :.*size="2">([^<]+)</font>.*} $horoscope_page "=date\\1=viepriv\\2=viequot\\3=vieprof\\4" horoscope
regsub -all -- {=date([^=]+)=.*} $horoscope "\\1" ladate
regsub -all -- {.*=viepriv([^=]+)=.*} $horoscope "\\1" viepriv
regsub -all -- {.*=viequot([^=]+)=.*} $horoscope "\\1" viequot
regsub -all -- {.*=vieprof(.+)} $horoscope "\\1" vieprof
putquick "PRIVMSG $victim :\002$disp_sign : $ladate\002"
putquick "PRIVMSG $victim :\002Vie privée :\002 $viepriv"
putquick "PRIVMSG $victim :\002Vie quotidienne :\002 $viequot"
putquick "PRIVMSG $victim :\002Vie professionnelle :\002 $vieprof"
} else {
regsub -all {.*<font size="2" face="Arial, Helvetica, sans-serif" color="#999999">.*<br>([^<]+)</font>.*Vie privée :.*size="2">([^<]+)</font>.*Vie amoureuse : .*size="2">([^<]+)</font>.*Vie professionnelle :.*size="2">([^<]+)</font>.*} $horoscope_page "=date\\1=viepriv\\2=vieamo\\3=vieprof\\4" horoscope
regsub -all -- {=date([^=]+)=.*} $horoscope "\\1" ladate
regsub -all -- {.*=viepriv([^=]+)=.*} $horoscope "\\1" viepriv
regsub -all -- {.*=vieamo([^=]+)=.*} $horoscope "\\1" vieamo
regsub -all -- {.*=vieprof(.+)} $horoscope "\\1" vieprof
putquick "PRIVMSG $victim :\002$disp_sign : $ladate\002"
putquick "PRIVMSG $victim :\002Vie privée :\002 $viepriv"
putquick "PRIVMSG $victim :\002Vie amoureuse :\002 $vieamo"
putquick "PRIVMSG $victim :\002Vie professionnelle :\002 $vieprof"
}
}

putlog "Horoscope Version 0.3 Loaded"

No comments:

Post a Comment