Communauté Eggdrop
[Résolu] erreur sur un tcl - Version imprimable

+- Communauté Eggdrop (https://forum.eggdrop.fr)
+-- Forum : Eggdrop et TCL (https://forum.eggdrop.fr/forumdisplay.php?fid=8)
+--- Forum : Scripts TCL (https://forum.eggdrop.fr/forumdisplay.php?fid=4)
+--- Sujet : [Résolu] erreur sur un tcl (/showthread.php?tid=1595)



erreur sur un tcl - BrYcOu - 04/10/2015

Bonjour j'essaye de faire un tcl pour annoncer des pubs sur plusieurs salons ça marche mais j'ai une erreur
voici le code tcl:
Code :
setudef flag Annonce
namespace eval ::SalonAnnonce {
   # Commande pour activer sur un chan
   variable onCmd "!annonce.on"
   # Commande pour désactiver sur un chan
   variable offCmd "!annonce.off"
   # Flags requis pour activer ou désactiver
   variable cmdFlags o
}

bind pub $::SalonAnnonce::cmdFlags $::SalonAnnonce::onCmd ::SalonAnnonce::pubOn
bind pub $::SalonAnnonce::cmdFlags $::SalonAnnonce::offCmd ::SalonAnnonce::pubOff

#
proc SalonAnnonce::pubOn {nick host hand chan arg} {
       if {[channel get $chan Annonce] == 0} {
               channel set $chan +Annonce
               puthelp "PRIVMSG $chan :\00314Activation des Annonces sur\00302 $chan" } {
               puthelp "PRIVMSG $chan :\00314Les Annonces sont déjà activées sur\00302 $chan"
       }
}
     
#
proc SalonAnnonce::pubOff {nick host hand chan arg} {
       if {[channel get $chan Annonce] == 1} {
               channel set $chan -Annonce
               puthelp "PRIVMSG $chan :\00314Désactivation des Annonces sur\00302 $chan" } {
               puthelp "PRIVMSG $chan :\00314Les Annonces sont déjà désactivées sur\00302 $chan"
       }
}


bind cron - "*/5 * * * *" advertise

set advertisetext {
"annonce1"
"annonce2"
"annonce3"
"annonce4"
}

proc advertise { nick uhost hand chan arg } {
global advertisetext
if {[channel get $chan Annonce]} {
set msg_s [lindex $::advertisetext [expr {int(rand() * [llength $::advertisetext])}]]
putserv "privmsg $chan : $msg_s"
}
}

et mon erreur
Code :
Tcl error [advertise]: no such channel record

Merci


RE: erreur sur un tcl - CrazyCat - 04/10/2015

Ta procédure advertise n'est pas bonne. Elle est déclenchée par un bind cron donc elle ne reçoit pas un canal en argument.
Il faudrait que tu fasses une boucle sur les canaux connus de l'eggdrop pour tester le flag et annoncer ou pas:
tcl
proc advertise {n h d m y} {
   foreach chan [channels] {
      if {[channel get $chan Annonce]} {
         set msg_s [lindex $::advertisetext [expr {int(rand() * [llength $::advertisetext])}]]
         putserv "privmsg $chan : $msg_s"
      }
   }
}





RE: erreur sur un tcl - BrYcOu - 04/10/2015

Merci CrazyCat ça marche niquel avec un foreach j'avais essayé mais surement pas comme il fallait puisque j'avais les annonces en double et l'erreur avec.
Mais tout est rentré dans l'ordre encore merci Smile


RE: erreur sur un tcl - ZarTek - 04/10/2015

Message sans intérêt que je post ici, mais je trouve le code plutôt pas mal et intéressant. en faite je parle surtout de :
tcl
[expr {int(rand() * [llength $::advertisetext])}]]