Advertisement
Guest User

AutoSpeak.tcl

a guest
Oct 22nd, 2012
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. namespace eval AutoSpeak {
  2.  
  3. variable channel "#Channel" ; # salon ou le bot vas parler.
  4. variable time 20 ; # temp d'innactivité avant que le bot commence (en minutes).
  5. variable file [file join scripts autospeak_chan.db] ; # fichier contenant les phrases.
  6.  
  7. # Création de la base de données.
  8. if ![file exists $file] {
  9. catch {open $file w} p
  10. catch {close $p}
  11. }
  12.  
  13. # Binds
  14. # bind pubm o * ::AutoSpeak::unsetimer
  15. bind pub o !addline ::AutoSpeak::addline
  16. bind pub o !autospeak ::AutoSpeak::startoff
  17.  
  18. # Init
  19. if [info exists timerspeak] {killtimer $timerspeak}
  20. set timerspeak [timer $time ::AutoSpeak::autospeak]
  21.  
  22.  
  23. # Procedures
  24.  
  25.  
  26. proc unsetimer {nick host hand chan arg} {
  27. variable time
  28. variable timerspeak
  29. variable channel
  30. if {$chan!=$channel} {return}
  31. if [info exists timerspeak] {killtimer $timerspeak}
  32. set timerspeak [timer $time ::AutoSpeak::autospeak]
  33. }
  34.  
  35.  
  36. proc autospeak { } {
  37.  
  38. variable file
  39. variable time
  40. variable timerspeak
  41. variable channel
  42.  
  43. set a 0
  44. catch {open $file r} p
  45. while {![eof $p]} {
  46. gets $p data
  47. if {$data==""} {continue}
  48. set data [split $data]
  49. regsub -all -- {\"} $data "'" data
  50. regsub -all -- {\{|\}|\\{|[}{|]}} $data "" data
  51. regsub -all -- {\\\]} $data "\]" data
  52. regsub -all -- {\\\[} $data "\[" data
  53. regsub -all -- {\\'} $data "'" data
  54. lappend liste $data
  55. incr a
  56. }
  57. catch {close $p}
  58. if [info exists liste] {
  59. set x 0;set y [rand $a]
  60. foreach ligne $liste {
  61. if {$x==$y && $ligne!=""} {
  62. putserv "PRIVMSG $channel :[lrange $ligne 0 end]"
  63. break
  64. }
  65. incr x
  66. }
  67. }
  68.  
  69. set timerspeak [timer $time ::AutoSpeak::autospeak]
  70. }
  71.  
  72. proc startoff {nick host hand chan arg} {
  73. variable timerspeak
  74. variable time
  75. if {($arg!="on" || $arg!="off") && $arg==""} {putserv "NOTICE $nick :!autospeak on/off";return}
  76. if {$arg=="off"} {
  77. if [info exists timerspeak] {
  78. killtimer $timerspeak
  79. unset timerspeak
  80. putserv "NOTICE $nick :AutoSpeak désactivé."
  81. return
  82. } else {
  83. putserv "NOTICE $nick :AutoSpeak déjà désactivé."
  84. return
  85. }
  86. }
  87. if {$arg=="on"} {
  88. if [info exists timerspeak] {
  89. putserv "NOTICE $nick :AutoSpeak déjà activé."
  90. return
  91. } else {
  92. set timerspeak [timer $time ::AutoSpeak::autospeak]
  93. putserv "NOTICE $nick :AutoSpeak activé."
  94. return
  95. }
  96. }
  97. }
  98.  
  99. proc addline {nick host hand chan arg} {
  100. variable file
  101. if {$arg==""} {putserv "NOTICE $nick :!addline <votre texte>";return}
  102. catch {open $file a} p
  103. puts $p $arg
  104. catch {close $p}
  105. putserv "NOTICE $nick :ligne ajouté."
  106.  
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement