Guest User

Untitled

a guest
Jul 1st, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 1.06 KB | None | 0 0
  1.  
  2. bind pubm - "*\[*" chooseproc
  3. #bind pubm - "*\[\ \]*" chooseproc
  4.  
  5. proc myRand { min max } {
  6.     set maxFactor [expr [expr $max + 1] - $min]
  7.     set value [expr int([expr rand() * 100])]
  8.     set value [expr [expr $value % $maxFactor] + $min]
  9. return $value
  10. }
  11.  
  12. proc chooseproc {nick host hand chan rest} {
  13.  
  14. set reglist [regexp -all -inline -- {(.*?) \[?\]} $rest]
  15.  
  16. if {[llength $reglist] <= 2 } {
  17.     putlog "list too short"
  18.     return;
  19. }
  20.  
  21. putlog $reglist
  22.  
  23. set choose_list [list]
  24. foreach match $reglist {
  25.     regsub {^\ } $match "" match
  26.     regsub {\[\ \]} $match "" match
  27.  
  28.     if { [string first "\[" $match] != -1 } { continue; }
  29.     set choose_list [linsert $choose_list end $match]
  30. }
  31.  
  32.  
  33. set choosen [lindex $choose_list [myRand 0 [llength $choose_list]-1]]
  34.  
  35.  
  36. set lst [list]
  37. set fin false
  38. foreach element $choose_list {
  39. #putlog "element: $element"
  40.     if {$element == $choosen && !$fin } {
  41.         append element " \[x\]"
  42.         set fin true
  43.     } else {
  44.         append element " \[ \]"
  45.     }
  46.     set lst [linsert $lst end $element]
  47. }
  48.  
  49.  
  50. putserv "PRIVMSG $chan :[join $lst " "]"
  51.  
  52.  
  53. }
Add Comment
Please, Sign In to add comment