Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace eval ::BT {
- set canal #testage
- set winner_artiste ""
- set winner_titre ""
- set level 0
- set playing 0
- set timer ""
- variable soundex_table ; array set soundex_table {}
- bind msgm - * ::BT::answer
- bind msg nm !launchevent ::BT::start
- bind pub - !score ::BT::score
- bind pub - !top10 ::BT::top10
- bind nick - * ::BT::update
- bind join - * ::BT::join_update
- bind part - * ::BT::watch
- bind sign - * ::BT::watch
- bind pub - !top10 ::BT::top10
- proc ::BT::start { nick host hand text } {
- putquick "PRIVMSG $::BT::canal :\002Le blind test commence dans quelques secondes !\002"
- puthelp "PRIVMSG $::BT::canal :\002Nombre d'extraits :\037 116\037\002"
- puthelp "PRIVMSG $::BT::canal :\002Nous commençons par la catégorie \037Général\037 !\002"
- utimer 20 ::BT::choosesong
- set ::BT::playing 1
- }
- proc ::BT::choosesong {} {
- if { ::BT::playing == 0 } { return }
- set file_ID [open scripts/bt/soundb.db a+]
- seek $file_ID 0
- set songlist [read $file_ID]
- close $file_ID
- set url [lindex $songlist 0]
- set difficulte [lindex $songlist 1]
- incr ::BT::level
- putquick "PRIVMSG $::BT::canal :\002\037$::BT::level/116\037 - \002Difficulté : $difficulte"
- putquick "PRIVMSG $::BT::canal :\002Vous avez 35 secondes pour charger la page et répondre.\002"
- putquick "PRIVMSG $::BT::canal :\002\037Rappel\037 - Proposer une réponse : /msg $::botnick <réponse>.\002"
- putquick "PRIVMSG $::BT::canal :\002---------------------------------------------"
- putquick "PRIVMSG $::BT::canal :\002\037Lien : $url\037\002"
- putquick "PRIVMSG $::BT::canal :\002---------------------------------------------"
- set ::BT::timer [utimer 35 {::BT::bilan time}]
- }
- proc ::BT::answer { nick host hand text } {
- if { ::BT::playing == 0 } { return }
- set file_ID [open scripts/bt/soundb.db a+]
- seek $file_ID 0
- set songlist [read $file_ID]
- close $file_ID
- set artiste [lindex [split [lindex $songlist 2] "/"] 0]
- set titre [lindex [split [lindex $songlist 2] "/"] 1]
- if { [string match "*/*" "$text"] == 1 } {
- set prop1 [lindex [split $text "/"] 0]
- set prop2 [lindex [split $text "/"] 1]
- if { [expr ([levenshtein::distance [string tolower $prop1] [string tolower $artiste]].00/[string bytelength $artiste].00)*100.00] <= 15 } {
- ::BT::won $nick $host artiste
- }
- if { [expr ([levenshtein::distance [string tolower $prop1] [string tolower $titre]].00/[string bytelength $titre].00)*100.00] <= 15 } {
- ::BT::won $nick $host titre
- }
- if { [expr ([levenshtein::distance [string tolower $prop2] [string tolower $artiste]].00/[string bytelength $artiste].00)*100.00] <= 15 } {
- ::BT::won $nick $host artiste
- }
- if { [expr ([levenshtein::distance [string tolower $prop2] [string tolower $titre]].00/[string bytelength $titre].00)*100.00] <= 15 } {
- ::BT::won $nick $host titre
- }
- } else {
- set prop $text
- if { [expr ([levenshtein::distance [string tolower $prop] [string tolower $artiste]].00/[string bytelength $artiste].00)*100.00] <= 15 } {
- ::BT::won $nick $host artiste
- } else {
- if { [expr ([levenshtein::distance [string tolower $prop] [string tolower $titre]].00/[string bytelength $titre].00)*100.00] <= 15 } {
- ::BT::won $nick $host titre
- }
- }
- }
- }
- proc ::BT::won { nick host what } {
- if { [lsearch -exact -nocase [set ::BT::winner_$what] $host] != -1 } {
- return
- }
- set ::BT::winner_$what [linsert [set ::BT::winner_$what] end $host]
- set file_ID [open scripts/bt/winners.db a+]
- seek $file_ID 0
- set list [read $file_ID]
- close $file_ID
- if { [lsearch -glob $list "*$host*"] == -1 } {
- set list [linsert $list [expr [lsearch -exact -nocase $list 1]+1] $nick%$host]
- } elseif { [lsearch -glob $list "*$host*"] != -1 && [lsearch -exact $list 2] > [lsearch -glob $list "*$host*"] } {
- set list [lreplace $list [lsearch -glob -nocase $list "*$host*"] [lsearch -glob -nocase $list "*$host*"]]
- set list [linsert $list [expr [lsearch -exact -nocase $list 2]+1] $nick%$host]
- if { [llength [lrange $list [expr [lsearch -exact -nocase $list 2]+1] end]] == 1 } {
- putquick "PRIVMSG $nick :\002\00303Vous êtes premier !"
- } elseif { [llength [lrange $list [expr [lsearch -exact -nocase $list 2]+1] end]] == 2 } {
- putquick "PRIVMSG $nick :\002\00307Vous êtes deuxième !"
- } elseif { [llength [lrange $list [expr [lsearch -exact -nocase $list 2]+1] end]] == 3 } {
- putquick "PRIVMSG $nick :\002\00305Vous êtes troisième !"
- killutimer $::BT::timer
- ::BT::bilan speed
- }
- } elseif { [lsearch -glob $list "*$host*"] != -1 && [lsearch -exact $list 2] < [lsearch -glob $list "*$host*"] } { return }
- set file_ID [open scripts/bt/winners.db w+]
- puts $file_ID "$list"
- close $file_ID
- }
- proc ::BT::bilan { type } {
- if { ::BT::playing == 0 } { return }
- if { $type == "time" } {
- putquick "PRIVMSG $::BT::canal :\002Le temps est écoulé !"
- } else {
- putquick "PRIVMSG $::BT::canal :\002Les trois joueurs les plus rapides ont trouvé la réponse !"
- }
- set file_ID [open scripts/bt/soundb.db a+]
- seek $file_ID 0
- set songlist [read $file_ID]
- close $file_ID
- set answer [lindex $songlist 2]
- set answer [string map "/ { - }" $answer]
- putquick "PRIVMSG $::BT::canal :\002La réponse était : \037$answer\037"
- if { $type == "time" } {
- set file_ID [open scripts/bt/winners.db a+]
- seek $file_ID 0
- set list [read $file_ID]
- close $file_ID
- set file_ID [open scripts/bt/scores.db a+]
- seek $file_ID 0
- set scores [read $file_ID]
- close $file_ID
- set 1st "Personne"
- set 2nd "Personne"
- set 3rd "Personne"
- set score1st "N/A"
- set score2nd "N/A"
- set score3rd "N/A"
- set places 3
- set winners [lrange $list [expr [lsearch -exact -nocase $list 2]+1] end]
- if { [llength $winners] == 2 } {
- set 1st [lindex $winners 0]
- if { [lsearch -exact $scores $1st] == -1 } {
- set score1st 3
- set scores [linsert $scores end $1st $score1st]
- } else {
- set score1st [expr [lindex $scores [expr [lsearch -exact $scores $1st]+1]]+3]
- set scores [lreplace $scores [expr [lsearch -exact $scores $1st]+1] [expr [lsearch -exact $scores $1st]+1] $score1st]
- }
- set places 2
- } elseif { [llength $winners] == 4 } {
- set 1st [lindex $winners 2]
- if { [lsearch -exact $scores $1st] == -1 } {
- set score1st 3
- set scores [linsert $scores end $1st $score1st]
- } else {
- set score1st [expr [lindex $scores [expr [lsearch -exact $scores $1st]+1]]+3]
- set scores [lreplace $scores [expr [lsearch -exact $scores $1st]+1] [expr [lsearch -exact $scores $1st]+1] $score1st]
- }
- set 2nd [lindex $winners 0]
- if { [lsearch -exact $scores $2nd] == -1 } {
- set score2nd 2
- set scores [linsert $scores end $2nd $score2nd]
- } else {
- set score2nd [expr [lindex $scores [expr [lsearch -exact $scores $2nd]+1]]+2]
- set scores [lreplace $scores [expr [lsearch -exact $scores $2nd]+1] [expr [lsearch -exact $scores $2nd]+1] $score2nd]
- }
- set places 1
- }
- set winners2 [lrange $list [expr [lsearch -exact -nocase $list 1]+1] [expr [lsearch -exact -nocase $list 2]-1]]
- if {$places == 3 && [llength $winners2] == 0 } {
- putquick "PRIVMSG $::BT::canal : Personne n'a trouvé la réponse..."
- } else {
- if {$places == 3 } {
- if { [llength $winners2] == 2 } {
- set 1st [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
- if { [lsearch -exact $scores $1st] == -1 } {
- set score1st 1
- set scores [linsert $scores end $1st $score1st]
- } else {
- set score1st [expr [lindex $scores [expr [lsearch -exact $scores $1st]+1]]+1]
- set scores [lreplace $scores [expr [lsearch -exact $scores $1st]+1] [expr [lsearch -exact $scores $1st]+1] $score1st]
- }
- } elseif { [llength $winners2] == 4 } {
- set 2nd [lindex $list [expr [lsearch -exact -nocase $list 2]-4]]
- if { [lsearch -exact $scores $2nd] == -1 } {
- set score2nd 1
- set scores [linsert $scores end $2nd $score2nd]
- } else {
- set score2nd [expr [lindex $scores [expr [lsearch -exact $scores [lindex $list [expr [lsearch -exact -nocase $list 2]-3]]]+1]]+1]
- set scores [lreplace $scores [expr [lsearch -exact $scores $2nd]+1] [expr [lsearch -exact $scores $2nd]+1] $score2nd]
- }
- set 1st [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
- if { [lsearch -exact $scores $1st] == -1 } {
- set score1st 1
- set scores [linsert $scores end $1st $score1st]
- } else {
- set score1st [expr [lindex $scores [expr [lsearch -exact $scores $1st]+1]]+1]
- set scores [lreplace $scores [expr [lsearch -exact $scores $1st]+1] [expr [lsearch -exact $scores $1st]+1] $score1st]
- }
- } elseif { [llength $winners2] >= 6 } {
- set 3rd [lindex $list [expr [lsearch -exact -nocase $list 2]-6]]
- if { [lsearch -exact $scores $3rd] == -1 } {
- set score3rd 1
- set scores [linsert $scores end $3rd $score3rd]
- } else {
- set score3rd [expr [lindex $scores [expr [lsearch -exact $scores $3rd]+1]]+1]
- set scores [lreplace $scores [expr [lsearch -exact $scores $3rd]+1] [expr [lsearch -exact $scores $3rd]+1] $score3rd]
- }
- set 2nd [lindex $list [expr [lsearch -exact -nocase $list 2]-4]]
- if { [lsearch -exact $scores [lindex $list [expr [lsearch -exact -nocase $list 2]-3]]] == -1 } {
- set score2nd 1
- set scores [linsert $scores end $2nd $score2nd]
- } else {
- set score2nd [expr [lindex $scores [expr [lsearch -exact $scores $2nd]+1]]+1]
- set scores [lreplace $scores [expr [lsearch -exact $scores $2nd]+1] [expr [lsearch -exact $scores $2nd]+1] $score2nd]
- }
- set 1st [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
- if { [lsearch -exact $scores [lindex $list [expr [lsearch -exact -nocase $list 2]-1]]] == -1 } {
- set score1st 1
- set scores [linsert $scores end $1st $score1st]
- } else {
- set score1st [expr [lindex $scores [expr [lsearch -exact $scores $1st]+1]]+1]
- set scores [lreplace $scores [expr [lsearch -exact $scores $1st]+1] [expr [lsearch -exact $scores $1st]+1] $score1st]
- }
- }
- } elseif { $places == 2 } {
- if { [llength $winners2] == 2 } {
- set 2nd [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
- if { [lsearch -exact $scores $2nd] == -1 } {
- set score2nd 1
- set scores [linsert $scores end $2nd $score2nd]
- } else {
- set score2nd [expr [lindex $scores [expr [lsearch -exact $scores $2nd]+1]]+1]
- set scores [lreplace $scores [expr [lsearch -exact $scores $2nd]+1] [expr [lsearch -exact $scores $2nd]+1] $score2nd]
- }
- } elseif { [llength $winners2] >= 4 } {
- set 3rd [lindex $list [expr [lsearch -exact -nocase $list 2]-4]]
- if { [lsearch -exact $scores $3rd] == -1 } {
- set score3rd 1
- set scores [linsert $scores end $3rd $score3rd]
- } else {
- set score3rd [expr [lindex $scores [expr [lsearch -exact $scores $3rd]+1]]+1]
- set scores [lreplace $scores [expr [lsearch -exact $scores $3rd]+1] [expr [lsearch -exact $scores $3rd]+1] $score3rd]
- }
- set 2nd [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
- if { [lsearch -exact $scores $2nd] == -1 } {
- set score2nd 1
- set scores [linsert $scores end $2nd $score2nd]
- } else {
- set score2nd [expr [lindex $scores [expr [lsearch -exact $scores $2nd]+1]]+1]
- set scores [lreplace $scores [expr [lsearch -exact $scores $2nd]+1] [expr [lsearch -exact $scores $2nd]+1] $score2nd]
- }
- }
- } elseif { $places == 1 } {
- set 3rd [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
- if { [lsearch -exact $scores $3rd] == -1 } {
- set score3rd 1
- set scores [linsert $scores end $3rd $score3rd]
- } else {
- set score3rd [expr [lindex $scores [expr [lsearch -exact $scores $3rd]+1]]+1]
- set scores [lreplace $scores [expr [lsearch -exact $scores $3rd]+1] [expr [lsearch -exact $scores $3rd]+1] $score3rd]
- }
- }
- putquick "PRIVMSG $::BT::canal :\002---------------------------------------------"
- putquick "PRIVMSG $::BT::canal :\002\037Premier : $1st ( $score1st pts )"
- putquick "PRIVMSG $::BT::canal :\002\037Deuxième : $2nd ( $score2nd pts )"
- putquick "PRIVMSG $::BT::canal :\002\037Troisième : $3rd ( $score3rd pts )"
- putquick "PRIVMSG $::BT::canal :\002---------------------------------------------"
- }
- } else {
- set file_ID [open scripts/bt/winners.db a+]
- seek $file_ID 0
- set list [read $file_ID]
- close $file_ID
- set file_ID [open scripts/bt/scores.db a+]
- seek $file_ID 0
- set scores [read $file_ID]
- close $file_ID
- set winners [lrange $list [expr [lsearch -exact -nocase $list 2]+1] end]
- if { [lsearch -exact $scores [lindex $winners 4]] == -1 } {
- set score1st 3
- set scores [linsert $scores end [lindex $winners 4] $score1st]
- } else {
- set score1st [expr [lindex $scores [expr [lsearch -exact $scores [lindex $winners 4]]+1]]+3]
- set scores [lreplace $scores [expr [lsearch -exact $scores [lindex $winners 4]]+1] [expr [lsearch -exact $scores [lindex $winners 4]]+1] $score1st]
- }
- if { [lsearch -exact $scores [lindex $winners 2]] == -1 } {
- set score2nd 2
- set scores [linsert $scores end [lindex $winners 2] $score2nd]
- } else {
- set score2nd [expr [lindex $scores [expr [lsearch -exact $scores [lindex $winners 2]]+1]]+2]
- set scores [lreplace $scores [expr [lsearch -exact $scores [lindex $winners 2]]+1] [expr [lsearch -exact $scores [lindex $winners 2]]+1] $score2nd]
- }
- if { [lsearch -exact $scores [lindex $winners 0]] == -1 } {
- set score3rd 1
- set scores [linsert $scores end [lindex $winners 0] $score3rd]
- } else {
- set score3rd [expr [lindex $scores [expr [lsearch -exact $scores [lindex $winners 0]]+1]]+1]
- set scores [lreplace $scores [expr [lsearch -exact $scores [lindex $winners 0]]+1] [expr [lsearch -exact $scores [lindex $winners 0]]+1] $score3rd]
- }
- putquick "PRIVMSG $::BT::canal :\002---------------------------------------------"
- putquick "PRIVMSG $::BT::canal :\002\037Premier : [lindex $winners 4] ( $score1st pts )"
- putquick "PRIVMSG $::BT::canal :\002\037Deuxième : [lindex $winners 2] ( $score2nd pts )"
- putquick "PRIVMSG $::BT::canal :\002\037Troisième : [lindex $winners 0] ( $score3rd pts )"
- putquick "PRIVMSG $::BT::canal :\002---------------------------------------------"
- }
- set file_ID [open scripts/bt/scores.db w+]
- puts $file_ID "$scores"
- close $file_ID
- set file_ID [open scripts/bt/soundb.db a+]
- seek $file_ID 0
- set songlist [read $file_ID]
- set songlist [lreplace $songlist 0 2]
- close $file_ID
- set file_ID [open scripts/bt/soundb.db w+]
- puts $file_ID "$songlist"
- close $file_ID
- set file_ID [open scripts/bt/winners.db w+]
- puts $file_ID "1 2"
- close $file_ID
- putquick "PRIVMSG $::BT::canal :\002Le blind test continue dans 10 secondes !\002"
- set ::BT::timer [utimer 10 ::BT::choosesong]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement