Communauté sur les Eggdrops - Community about Eggdrops
script add trigger need help - Printable Version

+- Communauté sur les Eggdrops - Community about Eggdrops (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)
+--- Thread: script add trigger need help (/showthread.php?tid=1307)



script add trigger need help - Brooks - 25/01/2013

bonjours alors je viens vous voire car j'ai besoin d'un coup de moins , je suis une bille en codage TCL

donc voila j'ai recuperer un tcl d'addtrigger
et j'ai 2 petite chose a vous demander :

1 - j'aimerai que l'on m'aide a rajouté les couleur (non prise en compte)
2 resoudre un pb au niveau du .tcl = Tcl error [triggers:pubm:trigger]: invalid command name ""


tcl
#set here the character that should beggins every trigger:
set triggerchar "@"
 
#####channels where the triggers will be used:####
bind pubm - "#cannal $triggerchar*" triggers:pubm:trigger
#bind pubm - "#canal $triggerchar*" triggers:pubm:trigger
 
#####here starts the script######
 
####Procedure that puts a new line in the file of triggers for the channel where the trigger was written
proc triggers:add { nick chan arg } {
   set triggerlog "triggerlog.txt"
   set file "[string trimleft $chan #]triggers.txt"
   set write [open $file a]
   if { [string range $arg 0 [expr [string first " " $arg]-1]] == "" || [lrange $arg 1 end] == "" } {
      close $write
      return 0
   }
   puts $write "[string range $arg 0 [expr [string first " " $arg]-1]]#[lrange $arg 1 end]"
   close $write
   puthelp "NOTICE $nick : A trigger [lindex $arg 0] a été ajouté avec succès à la liste des trigger du chan $chan."
   set tlog [open $triggerlog a]
   puts $tlog "Logger:$nick ajout d'un trigger sur $chan. ($arg)"
   close $tlog
   putlog "Logger:$nick ajout d'un trigger sur $chan. ($arg)"
}
 
 
####This procedure will be in charge of removing triggers for the chan where the command was written.
proc triggers:rem { nick chan trigger } {
   set triggerlog "triggerlog.txt"
   set file [string trimleft $chan #]triggers.txt
   set tempfile [string trimleft $chan #]trigger.bak
   set readfirst [open $file r]
   set linenumb 0
   set count 0
   puthelp "NOTICE $nick :Indication: éffacement d'un trigger."
   while { ![eof $readfirst] } {
      gets $readfirst line
      set helpwanted [string range $line 0 [expr [string first # $line]-1]]
      if { $trigger != $helpwanted } {
         if { $linenumb==0 } {
            set writetemp [open $tempfile w]
            puts $writetemp $line
            close $writetemp
            incr linenumb
         } else {
            set writetemp [open $tempfile a]
            puts $writetemp $line
            close $writetemp
            incr linenumb
         }
      } else {
         incr count
         set tlog [open $triggerlog a]
         puts $tlog "Logger:$nick efface un trigger sur $chan. ($helpwanted [string range $line [expr [string first # $line]+1] end])"
         close $tlog
         putlog "Logger:$nick efface un trigger sur $chan. ($helpwanted [string range $line [expr [string first # $line]+1] end])"
         puthelp "NOTICE $nick :($count):!addtrigger $helpwanted [string range $line [expr [string first # $line]+1] end]"
      }
   }
   close $readfirst
   set readfirst2 [open $tempfile r]
   set linenumb2 0
   while { ![eof $readfirst2] } {
      gets $readfirst2 line
      if { [string first # $line] != -1 } {
         if { $linenumb2==0 } {
            set writetemp [open $file w]
            puts $writetemp $line
            close $writetemp
            incr linenumb2
         } else {
            set writetemp [open $file a]
            puts $writetemp $line
            close $writetemp
         }
      }
   }
   if { $linenumb2==0 } {
      set writetemp [open $file w]
      close $writetemp
   }  
   close $readfirst2
   puthelp "NOTICE $nick :Fin: Trigger éffacé."
}
 
 
 
####Procedure that will get all the triggers from the file and present them to the user who asked for the list of possible commands for the chan.
proc triggers:list { nick chan } {
   set read [open [string trimleft $chan #]triggers.txt r]
   set text ""
   while { ![eof $read] } {
      gets $read line
      set text "$text [lindex [split $line #] 0]"
   }
   close $read
   set finish [string range $text 1 [expr [string length $text]-2]]
   set long [split $finish]
   if { [llength $long] > 30 } {
      for { set c 0} { $c<[llength $long] } { incr c 30 } {
         if { $c==0 } {
            puthelp "NOTICE $nick : Triggers: 4[lrange $long $c [expr $c+29]]"
         } else {
            puthelp "NOTICE $nick : 4[lrange $long $c [expr $c+29]]"
         }
      }
   } else {
      puthelp "NOTICE $nick :Triggers: 4$finish"
   }
}
 
####Procedure that shows in the chan the text or the action associated with the trigger written in the channel
proc triggers:pubm:trigger { nick uhost handle chan arg } {
   global globalProtect nickProtect triggerchar
   set way ""
   set notice 0
   set ok 0
   set trigger "[string tolower [string range [lindex $arg 0] 1 end]]"
   if { [isop $nick $chan] || [ishalfop $nick $chan] } {
      if { $trigger=="listtrigger" } {
         [triggers:list $nick $chan]
         return 0
      } elseif { $trigger=="addtrigger" } {
         [triggers:add $nick $chan [join [lrange [split $arg] 1 end]]]
         return 0
      } elseif { $trigger=="remtrigger" } {
         [triggers:rem $nick $chan [join [lrange [split $arg] 1 end]]]
         return 0
      }
   } elseif { [isvoice $nick $chan] } {
      #Voices avoid protection.
   } else {
      if { [info exists nickProtect($uhost)] == 1 } {
         putlog "Nick Trigger flood($uhost,$nickProtect($uhost))"
         if { $nickProtect($uhost) == 2 } {
            return 0
         }
         incr nickProtect($uhost)
      } else {
         set nickProtect($uhost) 1
         utimer 5 "unset nickProtect($uhost)"
      }
      if { [info exists globalProtect] == 1 } {
         if { $globalProtect == 4 } {
            putlog "Global Trigger flood($uhost,$globalProtect)"
            return 0
         }
         incr globalProtect
      } else {
         set globalProtect 1
         utimer 10 "unset globalProtect"
      }
   }
   #ways the resulting help text should be sent
   if { [llength $arg] < 2 } {
      if { [isop $nick $chan] || [ishalfop $nick $chan] ||[isvoice $nick $chan] } {
         set way "PRIVMSG $chan :\001ACTION"
         set notice 0
      } else {
         set way "NOTICE $nick :$nick:"
         set notice 1
      }
   } else {
      if { [onchan [lindex $arg 1] $chan] && ( [isop $nick $chan] || [ishalfop $nick $chan] || [isvoice $nick $chan] ) } {
         if { [lindex $arg 2]=="c" } {
            set way "PRIVMSG $chan :\001ACTION [lindex $arg 1]"
            set notice 3
         } elseif { [lindex $arg 2]=="p" } {
            set way "PRIVMSG [lindex $arg 1] :"
            set notice 2
         } else {
            set way "NOTICE [lindex $arg 1] :$nick:"
            set notice 1
         }
      } else {
         return 0
      }
   }
   #now it searches the txt file for the trigger  wrotten in the channel and if it finds something associated with that trigger,
   #it sends it back to the server in the way it was define above.
   if { $way!="" && [file exists [string trimleft $chan #]triggers.txt] } {
      set read [open [string trimleft $chan #]triggers.txt r]
      while  { ![eof $read] } {
         gets $read line
         set helpwanted [string range $line 0 [expr [string first # $line]-1]]
         if { [string tolower [lindex $helpwanted 0]]==[string tolower [string trimleft [lindex $arg 0] $triggerchar]] } {
            set ok 1
            puthelp "$way [string range $line [expr [string first # $line]+1] end]"
         }
      }
      set final [not $notice $ok $nick $arg]
      close $read
   }
}
 
proc not { notice ok nick arg } {
   if { $notice==1 && $ok==1 } {
      puthelp "NOTICE $nick : :) [lindex $arg 1]"
   } elseif { $notice==2 && $ok==1 } {
      puthelp "NOTICE $nick : :) [lindex $arg 0] [lindex $arg 1]"
   }
}
 
putlog "Triggers.tcl script loaded."



en vous remerciant par avance


RE: script add trigger need help - CrazyCat - 26/01/2013

Bon, l'erreur est assez simple, et se trouve un peu partout dans le script. Il y a des lignes qui sont de la forme:

tcl
[triggers:add $nick $chan [join [lrange [split $arg] 1 end]]]

Les [ et ] qui encapsulent un appel de fonction servent uniquement lorsqu'on doit traiter le retour de la fonction. Il suffit d'enlever le [ initial et le ] final pour que ça fonctionne bien.
Voici les lignes 121 à 132 corrigées:

tcl
if { [isop $nick $chan] || [ishalfop $nick $chan] } {
      if { $trigger=="listtrigger" } {
         triggers:list $nick $chan
         return 0
      } elseif { $trigger=="addtrigger" } {
         triggers:add $nick $chan [join [lrange [split $arg] 1 end]]
         return 0
      } elseif { $trigger=="remtrigger" } {
         triggers:rem $nick $chan [join [lrange [split $arg] 1 end]]
         return 0
      }
   } elseif { [isvoice $nick $chan] } {


Concernant les couleurs, je ne suis pas certain de comprendre. Peux tu être plus explicite ?


RE: script add trigger need help - cestlemien - 26/01/2013

salut ,

concernant l'effacement d'un trigger , une chose m'interpel :


tcl
puthelp "NOTICE $nick <img src="images/smilies/icon_sad.gif" style="vertical-align: middle;" border="0" alt="Sad" title="Sad" />$count):!addtrigger $helpwanted [string range $line [expr [string first # $line]+1] end]"


ce script est à la base fait pour tout moderateur de là ou ce trouve l'eggdrop , comment un utilisateur de la commande fait il pour voir l'image ? De plus chaqu'un met ses images/smilley là ou bon lui semble. Meme en ayant un accés à la party line..
J'avoue ne pas comprendre .

Cordialement.


RE: script add trigger need help - CrazyCat - 26/01/2013

C'est un souci du forum dans la traduction du tcl.
Si tu vois

Code:
<img src="images/smilies/icon_sad.gif" style="vertical-align: middle;" border="0" alt="Sad" title="Sad" />
C'est en fait un:

Code:
:(



RE: script add trigger need help - cestlemien - 26/01/2013

salut,
oupss pardon ( j'ai pas eu l'idée remarque de telecharger le fichier joint ) ..

si les gens faisaient attention a desactiver les smilley aussi rhaaaa ! ( il faut des fautifs xD )

Cordialement.


RE: script add trigger need help - Brooks - 27/01/2013

ah oui pardon j'avais pas remarqué que cela avait charger le lien des smileys


et merci crazycat

pour apporté des explications a chaque fois que j'entre un trigger avec des couleur (ex : !addtrigger teste mon texte => !teste = mon texte)

voila