Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 15.02 KB | None | 0 0
  1. namespace eval ::BT {
  2.     set canal #testage
  3.     set winner_artiste ""
  4.     set winner_titre ""
  5.     set level 0
  6.     set playing 0
  7.     set timer ""
  8.     variable soundex_table ; array set soundex_table {}
  9.  
  10.     bind msgm - * ::BT::answer
  11.     bind msg nm !launchevent ::BT::start
  12.     bind pub - !score ::BT::score
  13.     bind pub - !top10 ::BT::top10
  14.     bind nick - * ::BT::update
  15.     bind join - * ::BT::join_update
  16.     bind part - * ::BT::watch
  17.     bind sign - * ::BT::watch
  18.     bind pub - !top10 ::BT::top10
  19.     proc ::BT::start { nick host hand text } {
  20.         putquick "PRIVMSG $::BT::canal :\002Le blind test commence dans quelques secondes !\002"
  21.         puthelp "PRIVMSG $::BT::canal :\002Nombre d'extraits :\037 116\037\002"
  22.         puthelp "PRIVMSG $::BT::canal :\002Nous commençons par la catégorie \037Général\037 !\002"
  23.         utimer 20 ::BT::choosesong
  24.         set ::BT::playing 1
  25.     }
  26.  
  27.  
  28.     proc ::BT::choosesong {} {
  29.         if { ::BT::playing == 0 } { return }
  30.         set file_ID [open scripts/bt/soundb.db a+]
  31.         seek $file_ID 0
  32.         set songlist [read $file_ID]
  33.         close $file_ID
  34.         set url [lindex $songlist 0]
  35.         set difficulte [lindex $songlist 1]
  36.         incr ::BT::level
  37.         putquick "PRIVMSG $::BT::canal :\002\037$::BT::level/116\037 - \002Difficulté : $difficulte"
  38.         putquick "PRIVMSG $::BT::canal :\002Vous avez 35 secondes pour charger la page et répondre.\002"
  39.         putquick "PRIVMSG $::BT::canal :\002\037Rappel\037 - Proposer une réponse : /msg $::botnick <réponse>.\002"
  40.         putquick "PRIVMSG $::BT::canal :\002---------------------------------------------"
  41.         putquick "PRIVMSG $::BT::canal :\002\037Lien : $url\037\002"
  42.         putquick "PRIVMSG $::BT::canal :\002---------------------------------------------"
  43.         set ::BT::timer [utimer 35 {::BT::bilan time}]
  44.     }
  45.  
  46.  
  47.     proc ::BT::answer { nick host hand text } {
  48.         if { ::BT::playing == 0 } { return }
  49.         set file_ID [open scripts/bt/soundb.db a+]
  50.         seek $file_ID 0
  51.         set songlist [read $file_ID]
  52.         close $file_ID             
  53.         set artiste [lindex [split [lindex $songlist 2] "/"] 0]
  54.         set titre [lindex [split [lindex $songlist 2] "/"] 1]
  55.         if { [string match "*/*" "$text"] == 1 } {
  56.             set prop1 [lindex [split $text "/"] 0]
  57.             set prop2 [lindex [split $text "/"] 1]
  58.             if { [expr ([levenshtein::distance [string tolower $prop1] [string tolower $artiste]].00/[string bytelength $artiste].00)*100.00] <= 15 } {
  59.                 ::BT::won $nick $host artiste
  60.             }
  61.             if { [expr ([levenshtein::distance [string tolower $prop1] [string tolower $titre]].00/[string bytelength $titre].00)*100.00] <= 15 } {
  62.                 ::BT::won $nick $host titre
  63.             }
  64.             if { [expr ([levenshtein::distance [string tolower $prop2] [string tolower $artiste]].00/[string bytelength $artiste].00)*100.00] <= 15 } {
  65.                 ::BT::won $nick $host artiste
  66.             }
  67.             if { [expr ([levenshtein::distance [string tolower $prop2] [string tolower $titre]].00/[string bytelength $titre].00)*100.00] <= 15 } {
  68.                 ::BT::won $nick $host titre
  69.             }
  70.  
  71.         } else {
  72.             set prop $text
  73.             if { [expr ([levenshtein::distance [string tolower $prop] [string tolower $artiste]].00/[string bytelength $artiste].00)*100.00] <= 15 } {
  74.                 ::BT::won $nick $host artiste
  75.             } else {
  76.                 if { [expr ([levenshtein::distance [string tolower $prop] [string tolower $titre]].00/[string bytelength $titre].00)*100.00] <= 15 } {
  77.                     ::BT::won $nick $host titre
  78.                 }
  79.             }
  80.         }
  81.     }
  82.  
  83.     proc ::BT::won { nick host what } {
  84.         if { [lsearch -exact -nocase [set ::BT::winner_$what] $host] != -1 } {
  85.             return
  86.         }
  87.         set ::BT::winner_$what [linsert [set ::BT::winner_$what] end $host]
  88.         set file_ID [open scripts/bt/winners.db a+]
  89.         seek $file_ID 0
  90.         set list [read $file_ID]
  91.         close $file_ID
  92.         if { [lsearch -glob $list "*$host*"] == -1 } {
  93.             set list [linsert $list [expr [lsearch -exact -nocase $list 1]+1] $nick%$host]
  94.         } elseif { [lsearch -glob $list "*$host*"] != -1 && [lsearch -exact $list 2] > [lsearch -glob $list "*$host*"] } {
  95.             set list [lreplace $list [lsearch -glob -nocase $list "*$host*"] [lsearch -glob -nocase $list "*$host*"]]
  96.             set list [linsert $list [expr [lsearch -exact -nocase $list 2]+1] $nick%$host]
  97.             if { [llength [lrange $list [expr [lsearch -exact -nocase $list 2]+1] end]] == 1 } {
  98.                 putquick "PRIVMSG $nick :\002\00303Vous êtes premier !"
  99.             } elseif { [llength [lrange $list [expr [lsearch -exact -nocase $list 2]+1] end]] == 2 } {
  100.                 putquick "PRIVMSG $nick :\002\00307Vous êtes deuxième !"
  101.             } elseif { [llength [lrange $list [expr [lsearch -exact -nocase $list 2]+1] end]] == 3 } {
  102.                 putquick "PRIVMSG $nick :\002\00305Vous êtes troisième !"
  103.                 killutimer $::BT::timer
  104.                 ::BT::bilan speed
  105.             }
  106.         } elseif { [lsearch -glob $list "*$host*"] != -1 && [lsearch -exact $list 2] < [lsearch -glob $list "*$host*"] } { return }
  107.             set file_ID [open scripts/bt/winners.db w+]
  108.             puts $file_ID "$list"
  109.             close $file_ID
  110.     }
  111.    
  112.     proc ::BT::bilan { type } {
  113.         if { ::BT::playing == 0 } { return }
  114.         if { $type == "time" } {
  115.             putquick "PRIVMSG $::BT::canal :\002Le temps est écoulé !"
  116.         } else {
  117.             putquick "PRIVMSG $::BT::canal :\002Les trois joueurs les plus rapides ont trouvé la réponse !"
  118.         }
  119.         set file_ID [open scripts/bt/soundb.db a+]
  120.         seek $file_ID 0
  121.         set songlist [read $file_ID]
  122.         close $file_ID
  123.         set answer [lindex $songlist 2]
  124.         set answer [string map "/ { - }" $answer]
  125.         putquick "PRIVMSG $::BT::canal :\002La réponse était : \037$answer\037"
  126.         if { $type == "time" } {
  127.             set file_ID [open scripts/bt/winners.db a+]
  128.             seek $file_ID 0
  129.             set list [read $file_ID]
  130.             close $file_ID
  131.             set file_ID [open scripts/bt/scores.db a+]
  132.             seek $file_ID 0
  133.             set scores [read $file_ID]
  134.             close $file_ID
  135.             set 1st "Personne"
  136.             set 2nd "Personne"
  137.             set 3rd "Personne"
  138.             set score1st "N/A"
  139.             set score2nd "N/A"
  140.             set score3rd "N/A"
  141.             set places 3
  142.             set winners [lrange $list [expr [lsearch -exact -nocase $list 2]+1] end]
  143.             if { [llength $winners] == 2 } {
  144.                 set 1st [lindex $winners 0]
  145.                 if { [lsearch -exact $scores $1st] == -1 } {
  146.                     set score1st 3
  147.                     set scores [linsert $scores end $1st $score1st]
  148.                 } else {
  149.                     set score1st [expr [lindex $scores [expr [lsearch -exact $scores $1st]+1]]+3]
  150.                     set scores [lreplace $scores [expr [lsearch -exact $scores $1st]+1] [expr [lsearch -exact $scores $1st]+1] $score1st]
  151.                 }
  152.                 set places 2
  153.             } elseif { [llength $winners] == 4 } {
  154.                 set 1st [lindex $winners 2]
  155.                 if { [lsearch -exact $scores $1st] == -1 } {
  156.                     set score1st 3
  157.                     set scores [linsert $scores end $1st $score1st]
  158.                 } else {
  159.                     set score1st [expr [lindex $scores [expr [lsearch -exact $scores $1st]+1]]+3]
  160.                     set scores [lreplace $scores [expr [lsearch -exact $scores $1st]+1] [expr [lsearch -exact $scores $1st]+1] $score1st]
  161.                 }
  162.                 set 2nd [lindex $winners 0]
  163.                 if { [lsearch -exact $scores $2nd] == -1 } {
  164.                     set score2nd 2
  165.                     set scores [linsert $scores end $2nd $score2nd]
  166.                 } else {
  167.                     set score2nd [expr [lindex $scores [expr [lsearch -exact $scores $2nd]+1]]+2]
  168.                     set scores [lreplace $scores [expr [lsearch -exact $scores $2nd]+1] [expr [lsearch -exact $scores $2nd]+1] $score2nd]      
  169.                 }
  170.                     set places 1
  171.             }
  172.             set winners2 [lrange $list [expr [lsearch -exact -nocase $list 1]+1] [expr [lsearch -exact -nocase $list 2]-1]]
  173.            
  174.            
  175.             if {$places == 3 && [llength $winners2] == 0 } {
  176.                 putquick "PRIVMSG $::BT::canal : Personne n'a trouvé la réponse..."
  177.             } else {
  178.             if {$places == 3 } {
  179.                 if { [llength $winners2] == 2 } {
  180.                     set 1st [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
  181.                     if { [lsearch -exact $scores $1st] == -1 } {
  182.                         set score1st 1
  183.                         set scores [linsert $scores end $1st $score1st]    
  184.                     } else {
  185.                         set score1st [expr [lindex $scores [expr [lsearch -exact $scores $1st]+1]]+1]
  186.                         set scores [lreplace $scores [expr [lsearch -exact $scores $1st]+1] [expr [lsearch -exact $scores $1st]+1] $score1st]
  187.                     }
  188.                 } elseif { [llength $winners2] == 4 } {
  189.                     set 2nd [lindex $list [expr [lsearch -exact -nocase $list 2]-4]]
  190.                     if { [lsearch -exact $scores $2nd] == -1 } {
  191.                         set score2nd 1
  192.                         set scores [linsert $scores end $2nd $score2nd]    
  193.                     } else {
  194.                         set score2nd [expr [lindex $scores [expr [lsearch -exact $scores [lindex $list [expr [lsearch -exact -nocase $list 2]-3]]]+1]]+1]
  195.                         set scores [lreplace $scores [expr [lsearch -exact $scores $2nd]+1] [expr [lsearch -exact $scores $2nd]+1] $score2nd]
  196.                     }
  197.                    
  198.                     set 1st [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
  199.                     if { [lsearch -exact $scores $1st] == -1 } {
  200.                         set score1st 1
  201.                         set scores [linsert $scores end $1st $score1st]    
  202.                     } else {
  203.                         set score1st [expr [lindex $scores [expr [lsearch -exact $scores $1st]+1]]+1]
  204.                         set scores [lreplace $scores [expr [lsearch -exact $scores $1st]+1] [expr [lsearch -exact $scores $1st]+1] $score1st]
  205.                     }
  206.                    
  207.                 } elseif { [llength $winners2] >= 6 } {
  208.                     set 3rd [lindex $list [expr [lsearch -exact -nocase $list 2]-6]]
  209.                     if { [lsearch -exact $scores $3rd] == -1 } {
  210.                         set score3rd 1
  211.                         set scores [linsert $scores end $3rd $score3rd]    
  212.                     } else {
  213.                         set score3rd [expr [lindex $scores [expr [lsearch -exact $scores $3rd]+1]]+1]
  214.                         set scores [lreplace $scores [expr [lsearch -exact $scores $3rd]+1] [expr [lsearch -exact $scores $3rd]+1] $score3rd]
  215.                     }
  216.                    
  217.                     set 2nd [lindex $list [expr [lsearch -exact -nocase $list 2]-4]]
  218.                     if { [lsearch -exact $scores [lindex $list [expr [lsearch -exact -nocase $list 2]-3]]] == -1 } {
  219.                         set score2nd 1
  220.                         set scores [linsert $scores end $2nd $score2nd]    
  221.                     } else {
  222.                         set score2nd [expr [lindex $scores [expr [lsearch -exact $scores $2nd]+1]]+1]
  223.                         set scores [lreplace $scores [expr [lsearch -exact $scores $2nd]+1] [expr [lsearch -exact $scores $2nd]+1] $score2nd]
  224.                     }
  225.  
  226.                     set 1st [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
  227.                     if { [lsearch -exact $scores [lindex $list [expr [lsearch -exact -nocase $list 2]-1]]] == -1 } {
  228.                         set score1st 1
  229.                         set scores [linsert $scores end $1st $score1st]    
  230.                     } else {
  231.                         set score1st [expr [lindex $scores [expr [lsearch -exact $scores $1st]+1]]+1]
  232.                         set scores [lreplace $scores [expr [lsearch -exact $scores $1st]+1] [expr [lsearch -exact $scores $1st]+1] $score1st]
  233.                     }
  234.                 }
  235.                
  236.  
  237.             } elseif { $places == 2 } {
  238.                 if { [llength $winners2] == 2 } {
  239.                     set 2nd [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
  240.                     if { [lsearch -exact $scores $2nd] == -1 } {
  241.                         set score2nd 1
  242.                         set scores [linsert $scores end $2nd $score2nd]    
  243.                     } else {
  244.                         set score2nd [expr [lindex $scores [expr [lsearch -exact $scores $2nd]+1]]+1]
  245.                         set scores [lreplace $scores [expr [lsearch -exact $scores $2nd]+1] [expr [lsearch -exact $scores $2nd]+1] $score2nd]
  246.                     }
  247.                 } elseif { [llength $winners2] >= 4 } {
  248.                     set 3rd [lindex $list [expr [lsearch -exact -nocase $list 2]-4]]
  249.                     if { [lsearch -exact $scores $3rd] == -1 } {
  250.                         set score3rd 1
  251.                         set scores [linsert $scores end $3rd $score3rd]    
  252.                     } else {
  253.                         set score3rd [expr [lindex $scores [expr [lsearch -exact $scores $3rd]+1]]+1]
  254.                         set scores [lreplace $scores [expr [lsearch -exact $scores $3rd]+1] [expr [lsearch -exact $scores $3rd]+1] $score3rd]
  255.                     }
  256.                    
  257.                     set 2nd [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
  258.                     if { [lsearch -exact $scores $2nd] == -1 } {
  259.                         set score2nd 1
  260.                         set scores [linsert $scores end $2nd $score2nd]    
  261.                     } else {
  262.                         set score2nd [expr [lindex $scores [expr [lsearch -exact $scores $2nd]+1]]+1]
  263.                         set scores [lreplace $scores [expr [lsearch -exact $scores $2nd]+1] [expr [lsearch -exact $scores $2nd]+1] $score2nd]
  264.                     }
  265.                    
  266.                 }
  267.                
  268.             } elseif { $places == 1 } {
  269.                     set 3rd [lindex $list [expr [lsearch -exact -nocase $list 2]-2]]
  270.                     if { [lsearch -exact $scores $3rd] == -1 } {
  271.                         set score3rd 1
  272.                         set scores [linsert $scores end $3rd $score3rd]    
  273.                     } else {
  274.                         set score3rd [expr [lindex $scores [expr [lsearch -exact $scores $3rd]+1]]+1]
  275.                         set scores [lreplace $scores [expr [lsearch -exact $scores $3rd]+1] [expr [lsearch -exact $scores $3rd]+1] $score3rd]
  276.                     }
  277.                
  278.             }
  279.        
  280.            
  281.             putquick "PRIVMSG $::BT::canal :\002---------------------------------------------"
  282.             putquick "PRIVMSG $::BT::canal :\002\037Premier : $1st ( $score1st pts )"
  283.             putquick "PRIVMSG $::BT::canal :\002\037Deuxième : $2nd ( $score2nd pts )"
  284.             putquick "PRIVMSG $::BT::canal :\002\037Troisième : $3rd ( $score3rd pts )"
  285.             putquick "PRIVMSG $::BT::canal :\002---------------------------------------------" 
  286.         }          
  287.         } else {
  288.             set file_ID [open scripts/bt/winners.db a+]
  289.             seek $file_ID 0
  290.             set list [read $file_ID]
  291.             close $file_ID
  292.             set file_ID [open scripts/bt/scores.db a+]
  293.             seek $file_ID 0
  294.             set scores [read $file_ID]
  295.             close $file_ID
  296.             set winners [lrange $list [expr [lsearch -exact -nocase $list 2]+1] end]
  297.             if { [lsearch -exact $scores [lindex $winners 4]] == -1 } {
  298.                 set score1st 3
  299.                 set scores [linsert $scores end [lindex $winners 4] $score1st]
  300.             } else {
  301.                 set score1st [expr [lindex $scores [expr [lsearch -exact $scores [lindex $winners 4]]+1]]+3]
  302.                 set scores [lreplace $scores [expr [lsearch -exact $scores [lindex $winners 4]]+1] [expr [lsearch -exact $scores [lindex $winners 4]]+1] $score1st]
  303.             }
  304.             if { [lsearch -exact $scores [lindex $winners 2]] == -1 } {
  305.                 set score2nd 2
  306.                 set scores [linsert $scores end [lindex $winners 2] $score2nd]
  307.             } else {
  308.                 set score2nd [expr [lindex $scores [expr [lsearch -exact $scores [lindex $winners 2]]+1]]+2]
  309.                 set scores [lreplace $scores [expr [lsearch -exact $scores [lindex $winners 2]]+1] [expr [lsearch -exact $scores [lindex $winners 2]]+1] $score2nd]
  310.             }
  311.             if { [lsearch -exact $scores [lindex $winners 0]] == -1 } {
  312.                 set score3rd 1
  313.                 set scores [linsert $scores end [lindex $winners 0] $score3rd]
  314.             } else {
  315.                 set score3rd [expr [lindex $scores [expr [lsearch -exact $scores [lindex $winners 0]]+1]]+1]
  316.                 set scores [lreplace $scores [expr [lsearch -exact $scores [lindex $winners 0]]+1] [expr [lsearch -exact $scores [lindex $winners 0]]+1] $score3rd]
  317.             }      
  318.             putquick "PRIVMSG $::BT::canal :\002---------------------------------------------"
  319.             putquick "PRIVMSG $::BT::canal :\002\037Premier : [lindex $winners 4] ( $score1st pts )"
  320.             putquick "PRIVMSG $::BT::canal :\002\037Deuxième : [lindex $winners 2] ( $score2nd pts )"
  321.             putquick "PRIVMSG $::BT::canal :\002\037Troisième : [lindex $winners 0] ( $score3rd pts )"
  322.             putquick "PRIVMSG $::BT::canal :\002---------------------------------------------"
  323.         }
  324.         set file_ID [open scripts/bt/scores.db w+]
  325.         puts $file_ID "$scores"
  326.         close $file_ID
  327.        
  328.         set file_ID [open scripts/bt/soundb.db a+]
  329.         seek $file_ID 0
  330.         set songlist [read $file_ID]
  331.         set songlist [lreplace $songlist 0 2]
  332.         close $file_ID
  333.         set file_ID [open scripts/bt/soundb.db w+]
  334.         puts $file_ID "$songlist"
  335.         close $file_ID
  336.         set file_ID [open scripts/bt/winners.db w+]
  337.         puts $file_ID "1 2"
  338.         close $file_ID
  339.        
  340.  
  341.         putquick "PRIVMSG $::BT::canal :\002Le blind test continue dans 10 secondes !\002"
  342.         set ::BT::timer [utimer 10 ::BT::choosesong]
  343.  
  344.  
  345.     }
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement