All pastes #968065 Raw Edit

Mine

public text v1 · immutable
·published 2008-04-02 20:20 UTC
rendered paste body
bind pub - !def dico
bind pub - !dico dico

#### !dico <mot> ####
proc dico {nick host hand chan arg} {
	if {[lrange $arg 1 end] != ""} {
		putserv "PRIVMSG $chan Syntaxe : !dico <mot>"
		return
	}
	set mot [lindex $arg 0]
	if {$mot == ""} {
		set mot "boulet"
	}
  variable useragent
  variable paragraphs
  set URL_site "http://dictionnaire.tv5.org/dictionnaires.asp?Action=1&param=$mot&che=1"
  set res ""
  ::http::config -useragent $useragent
  catch { set token [::http::geturl "$URL_site" -timeout 5000] }
  if {![info exists token]} {
	putlog "\00304\002\[Definition\]\002\003 La connexion à \00312\037$URL_site\037\003 n'a pas pu s'établir. Impossible d'afficher la définition du mot."
    return
  }
  if {[::http::status $token] == "ok"} {
    regexp "<small>(.+?)</small>" [::http::data $token] res
    if { $res != "" && [lsearch -exact [split $res] "color='#911409'>Lexique"] == -1 } {
      regsub -all "\n" $res "" res
      regsub -all "<B>>" $res "" res
      regsub -all "</B></FONT><BR>" $res "" res
      regsub -all "</B></FONT><BR> <FONT COLOR=RED>" $res "" res
      regsub -all "</FONT><BR>" $res " |" res
      regsub -all "<FONT COLOR=RED>" $res "" res
      regsub -all "<BR>" $res "\n" res
      regsub -all "  " $res "" res
      regsub -all "<\[^<\]*>" $res "" res
      regsub -all "&#149" $res "|" res
      regsub -all "&#160;" $res " " res
      regsub -all "le dictionnaire multifonctions vous propose..." $res "" res
      regsub -all " D&Eacute;FINITIONS," $res "" res
      set res [encoding convertfrom "utf-8" $res ]
      if {[string length $res] > 448} {set res "[string range $res 0 [string first . $res 300]] \n [string range $res [expr {[string first . $res 300] +  1 }] [string first . $res 600]] \n [string range $res [expr {[string first . $res 600] + 1 }] [string first . $res 900]] \n [string range $res [expr {[string first . $res 900] + 1 }] [string first . $res 1200]]"}
      if {$res == ""} {
        set res {"La définition n'a pas pu être récupérée, erreur d'analyse des données.\003"}
      }
      set res [split $res "\n"]
      set counter 0
      set nores 0
			putquick "privmsg $chan :2Définition du mot $mot :"
		foreach line $res {
				set line [string trim $line]
        if {$line != "" && $line != " "} {
					if {[string range $line 0 1] == "| "} {
						set line [string range $line 2 end]
					}
          incr counter
					set nores 1
					putquick "privmsg $chan :2$line"
#          if {$counter >= $paragraphs} {
#            ::http::cleanup $token
#            return
#          }
        }
      }
    }
  }
  ::http::cleanup $token
  return
}