Je l'ai mis sur mon premier post Crazy, non ?
Voilà la dernière version !
Code PHP :
##############
# CONFIGURATION #
##############
# -> Login
set sql(login) ""
# -> Mot de passe
set sql(pass) ""
# -> Nom de la base de donnée
set sql(db) ""
# -> L'host a l'aquelle ce connecté
set sql(host) "localhost"
# -> Localisation de fichier mysql.sock
set sql(sock) "/path/to/mysqld.sock"
# Anti flood sur les commandes du Bot x:y (x=nombre de fois, y=secondes) :
set wdntw(flood) 3:5
# Ignorer l'utilisateur après son flood (0=non, 1=oui) :
set wdntw(ignore) 1
# Si oui, combien de temps (en minutes) :
set wdntw(ignoretime) 1
# Laisser faire les utilisateurs ayant certains flags :
set wdntw(ignflags) "h|h"
###########
# PAQUETAGE #
###########
catch {package require mysqltcl}
#######
# CODE #
#######
#########
# CONNECT #
#########
proc service:connect {} {
set ::mysqlink [::mysql::connect -host $::sql(host) -user $::sql(login) -password $::sql(pass) -sock $::sql(sock)]
::mysql::use $::mysqlink $::sql(db)
}
###########
# DECONNECT #
###########
proc service:deconnect {} {
::mysql::close $::mysqlink; unset -nocomplain ::mysqlink
}
########
# INFOS #
########
proc infos {donnees} {
service:connect
set query "SELECT v_artistes, v_titres, m_nom, m_link FROM v5_videos, v5_menus WHERE CONCAT(v_artistes, '%', v_titres) LIKE '%$donnees%' AND menus_id = idmenus"
set res [::mysql::sel $::mysqlink $query -flatlist]
service:deconnect
return $res
}
bind pub $wdntw(ignflags) !sound pub:wdntwcmd
proc pub:wdntwcmd {nick host hand chan arg} {
global wdntw botnick
set donnees [string_filter [string map {" " %} [join $arg]]]
# on transforme les espaces en %
if { [llength [split $arg]] == 0 } {
putserv "NOTICE $nick : Merci de préciser ta recherche. Exemple : !sound *artistes ou titres*"
return 0
}
if ![matchattr $nick $wdntw(ignflags) $chan] {
if {[wdntw:flood $nick $host]} {
return 0
}
}
set res [infos $donnees]
set artistes [lindex $res 0]
set titres [lindex $res 1]
set urlmenu [lindex $res 3]
set minartistes [string_filter [lindex $res 0]]
set mintitres [string_filter [lindex $res 1]]
foreach {artistes titres urlmenu minartistes mintitres} $res {
if { [llength $res] > 0 } {
#putlog "Résultat : [join $res]";
putlog "$artistes - $titres : http://www.wdntw.com/$urlmenu/$minartistes/$mintitres";
#putserv "PRIVMSG $chan : $artistes - $titres : http://www.wdntw.com/$urlmenu/$minartistes/$mintitres";
} else {
putserv "NOTICE $nick : Désolé mais ce son n'existe pas dans ma base de données.";
}
}
}
proc string_filter {str} {
set str [string map -nocase {
" " "-" "_" "-" "&" "-" "/" "-"
"." "-" "(" "-" ")" "-" "'" ""
"," "" "è" "e" "é" "e"
} $str]
regsub -all {<br />} $str " " str
regsub -all {<[^>]+>} $str "" str
regsub -all {\n} $str " " str
set str [encoding convertfrom utf-8 $str]
set str [string tolower $str]
return $str
}
proc wdntw:flood:init {} {
global wdntw wdntwflood
set wdntw(floodnum) [lindex [split $wdntw(flood) :] 0]
set wdntw(floodtime) [lindex [split $wdntw(flood) :] 1]
set i [expr $wdntw(floodnum) - 1]
while {$i >= 0} {
set wdntwflood($i) 0
incr i -1
}
}
wdntw:flood:init
proc wdntw:flood {nick host} {
global wdntw wdntwflood botnick
if {$wdntw(floodnum) == 0} {
return 0
}
set i [expr $wdntw(floodnum) - 1]
while {$i >= 1} {
set wdntwflood($i) $wdntwflood([expr $i - 1])
incr i -1
}
set wdntwflood(0) [unixtime]
if {[expr [unixtime] - $wdntwflood([expr $wdntw(floodnum) - 1])] <= $wdntw(floodtime)} {
if {$wdntw(ignore)} {
newignore [join [maskhost *!*[string trimleft $host ~]]] $botnick "Flood" $wdntw(ignoretime)
}
return 1
} {
return 0
}
}
putlog "Script WDNTW SQL by KiBa loaded!"
Voilà la dernière version !