This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Help - tcl addtrigger

Help for those learning Tcl or writing their own scripts.
Post Reply
s
sekai
Voice
Posts: 7
Joined: Sat Feb 25, 2012 6:09 am
Location: Brazil - SP

Help - tcl addtrigger

Post by sekai »

Hi, i need help, this tcl don't works for me:

Code: Select all

#set here the character that should beggins every trigger:
set triggerchar "!"

#####channels where the triggers will be used:####
bind pubm - "#sala $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] foi adicionada com sucesso a lista de trigger do $chan."
   set tlog [open $triggerlog a]
   puts $tlog "Logger:$nick adicionou uma trigger no $chan. ($arg)"
   close $tlog
   putlog "Logger:$nick adicionou uma trigger no $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 :Iniciando: Removendo 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 removeu uma trigger do $chan. ($helpwanted [string range $line [expr [string first # $line]+1] end])"
         close $tlog
         putlog "Logger:$nick removeu uma trigger do $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 :Fim: Trigger removida."
}



####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."
I need that tcl in my help chan.

Thks for help! :D
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Could you describe the issue or error you get? Or maybe what's not working at all or properly?
Once the game is over, the king and the pawn go back in the same box.
s
sekai
Voice
Posts: 7
Joined: Sat Feb 25, 2012 6:09 am
Location: Brazil - SP

Post by sekai »

caesar wrote:Could you describe the issue or error you get? Or maybe what's not working at all or properly?
Not work, i type "!addtrigger teste messenger" and.... nothing :(
s
sekai
Voice
Posts: 7
Joined: Sat Feb 25, 2012 6:09 am
Location: Brazil - SP

Post by sekai »

If not how to fix, would use another command that works like this?
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

You can try this script http://forum.egghelp.org/viewtopic.php?t=19313
It does what you want and more
s
sekai
Voice
Posts: 7
Joined: Sat Feb 25, 2012 6:09 am
Location: Brazil - SP

Post by sekai »

Thank you for reply, i will test now 8)
s
sekai
Voice
Posts: 7
Joined: Sat Feb 25, 2012 6:09 am
Location: Brazil - SP

is ok now!

Post by sekai »

Hi!

2 years ago i make this topic requesting help, today, i found the "error" in this tcl lol .

the error is in 5º line:
bind pubm - "#sala $triggerchar*" triggers:pubm:trigger
remove this * :
bind pubm - "#sala $triggerchar" triggers:pubm:trigger
save the tcl and rehash your bot.

Now, type:

!addtrigger command text here

and your bot will create and add the trigger "command" in "channel.txt" .

after type:

!comand

and your bot will send the text in your channel :D .

I do not know who created this tcl, but thank you for sharing with us all.
Post Reply