Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace eval AutoSpeak {
- variable channel "#Channel" ; # salon ou le bot vas parler.
- variable time 20 ; # temp d'innactivité avant que le bot commence (en minutes).
- variable file [file join scripts autospeak_chan.db] ; # fichier contenant les phrases.
- # Création de la base de données.
- if ![file exists $file] {
- catch {open $file w} p
- catch {close $p}
- }
- # Binds
- # bind pubm o * ::AutoSpeak::unsetimer
- bind pub o !addline ::AutoSpeak::addline
- bind pub o !autospeak ::AutoSpeak::startoff
- # Init
- if [info exists timerspeak] {killtimer $timerspeak}
- set timerspeak [timer $time ::AutoSpeak::autospeak]
- # Procedures
- proc unsetimer {nick host hand chan arg} {
- variable time
- variable timerspeak
- variable channel
- if {$chan!=$channel} {return}
- if [info exists timerspeak] {killtimer $timerspeak}
- set timerspeak [timer $time ::AutoSpeak::autospeak]
- }
- proc autospeak { } {
- variable file
- variable time
- variable timerspeak
- variable channel
- set a 0
- catch {open $file r} p
- while {![eof $p]} {
- gets $p data
- if {$data==""} {continue}
- set data [split $data]
- regsub -all -- {\"} $data "'" data
- regsub -all -- {\{|\}|\\{|[}{|]}} $data "" data
- regsub -all -- {\\\]} $data "\]" data
- regsub -all -- {\\\[} $data "\[" data
- regsub -all -- {\\'} $data "'" data
- lappend liste $data
- incr a
- }
- catch {close $p}
- if [info exists liste] {
- set x 0;set y [rand $a]
- foreach ligne $liste {
- if {$x==$y && $ligne!=""} {
- putserv "PRIVMSG $channel :[lrange $ligne 0 end]"
- break
- }
- incr x
- }
- }
- set timerspeak [timer $time ::AutoSpeak::autospeak]
- }
- proc startoff {nick host hand chan arg} {
- variable timerspeak
- variable time
- if {($arg!="on" || $arg!="off") && $arg==""} {putserv "NOTICE $nick :!autospeak on/off";return}
- if {$arg=="off"} {
- if [info exists timerspeak] {
- killtimer $timerspeak
- unset timerspeak
- putserv "NOTICE $nick :AutoSpeak désactivé."
- return
- } else {
- putserv "NOTICE $nick :AutoSpeak déjà désactivé."
- return
- }
- }
- if {$arg=="on"} {
- if [info exists timerspeak] {
- putserv "NOTICE $nick :AutoSpeak déjà activé."
- return
- } else {
- set timerspeak [timer $time ::AutoSpeak::autospeak]
- putserv "NOTICE $nick :AutoSpeak activé."
- return
- }
- }
- }
- proc addline {nick host hand chan arg} {
- variable file
- if {$arg==""} {putserv "NOTICE $nick :!addline <votre texte>";return}
- catch {open $file a} p
- puts $p $arg
- catch {close $p}
- putserv "NOTICE $nick :ligne ajouté."
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement