Guest User

Untitled

a guest
Mar 3rd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 9.23 KB | None | 0 0
  1. #mettre ici entre "" le caractere afin d'utiliser la commande sur le chan
  2. set triggerchar "!"
  3.  
  4. #####channels where the triggers will be used:####
  5. bind pubm - "#chan $triggerchar*" triggers:pubm:trigger
  6.  
  7. #####here starts the script######
  8.  
  9. ####Procedure that puts a new line in the file of triggers for the channel where the trigger was written
  10. proc triggers:add { nick chan arg } {
  11.         set triggerlog "triggerlog.txt"
  12.         set file "[string range $chan 1 end].txt"
  13.         set write [open $file a]
  14.         if { [string range $arg 0 [expr [string first " " $arg]-1]] == "" || [lrange $arg 1 end] == "" } {
  15.                 close $write
  16.                 return 0
  17.         }
  18.         puts $write "[string range $arg 0 [expr [string first " " $arg]-1]]#[lrange $arg 1 end]"
  19.         close $write
  20.         puthelp "NOTICE $nick : le trigger ( [lindex $arg 0]) est ajouté sur le chan de $chan."
  21.         set tlog [open $triggerlog a]
  22.         puts $tlog "Logger:$nick ajoute le trigger sur $chan. ($arg)"
  23.         close $tlog
  24.         putlog "Logger:$nick ajoute le trigger sur $chan. ($arg)"
  25. }
  26.  
  27.  
  28. ####This procedure will be in charge of removing triggers for the chan where the command was written.
  29. proc triggers:rem { nick chan trigger } {
  30.         set triggerlog "triggerlog.txt"
  31.         set file [string trimleft $chan #].txt
  32.         set tempfile [string trimleft $chan #].bak
  33.         set readfirst [open $file r]
  34.         set linenumb 0
  35.         set count 0
  36.         puthelp "NOTICE $nick :début de l'effacement du triggers."
  37.         while { ![eof $readfirst] } {
  38.                 gets $readfirst line
  39.                 set helpwanted [string range $line 0 [expr [string first # $line]-1]]
  40.                 if { $trigger != $helpwanted } {
  41.                         if { $linenumb==0 } {
  42.                                 set writetemp [open $tempfile w]
  43.                                 puts $writetemp $line
  44.                                 close $writetemp
  45.                                 incr linenumb
  46.                         } else {
  47.                                 set writetemp [open $tempfile a]
  48.                                 puts $writetemp $line
  49.                                 close $writetemp
  50.                                 incr linenumb
  51.                         }
  52.                 } else {
  53.                         incr count
  54.                         set tlog [open $triggerlog a]
  55.                         puts $tlog "Logger:$nick effacement du trigger sur $chan. ($helpwanted [string range $line [expr [string first # $line]+1] end])"
  56.                         close $tlog
  57.                         putlog "Logger:$nick effacement du trigger sur $chan. ($helpwanted [string range $line [expr [string first # $line]+1] end])"
  58.                         puthelp "NOTICE $nick :($count):!addtrigger $helpwanted [string range $line [expr [string first # $line]+1] end]"
  59.                 }
  60.         }
  61.         close $readfirst
  62.         set readfirst2 [open $tempfile r]
  63.         set linenumb2 0
  64.         while { ![eof $readfirst2] } {
  65.                 gets $readfirst2 line
  66.                 if { [string first # $line] != -1 } {
  67.                         if { $linenumb2==0 } {
  68.                                 set writetemp [open $file w]
  69.                                 puts $writetemp $line
  70.                                 close $writetemp
  71.                                 incr linenumb2
  72.                         } else {
  73.                                 set writetemp [open $file a]
  74.                                 puts $writetemp $line
  75.                                 close $writetemp
  76.                         }
  77.                 }
  78.         }
  79.         if { $linenumb2==0 } {
  80.                 set writetemp [open $file w]
  81.                 close $writetemp
  82.         }      
  83.         close $readfirst2
  84.         puthelp "NOTICE $nick :fin de l'effacement du triggers."
  85. }
  86.  
  87.  
  88.  
  89. ####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.
  90. proc triggers:list { nick chan } {
  91.         set read [open [string trimleft $chan #].txt r]
  92.         set text ""
  93.         while { ![eof $read] } {
  94.                 gets $read line
  95.                 set text "$text [lindex [split $line #] 0]"
  96.         }
  97.         close $read
  98.         set finish [string range $text 1 [expr [string length $text]-2]]
  99.         set long [split $finish]
  100.         if { [llength $long] > 30 } {
  101.                 for { set c 0} { $c<[llength $long] } { incr c 30 } {
  102.                         if { $c==0 } {
  103.                                 puthelp "NOTICE $nick : Triggers: 4[lrange $long $c [expr $c+29]]"
  104.                         } else {
  105.                                 puthelp "NOTICE $nick : 4[lrange $long $c [expr $c+29]]"
  106.                         }
  107.                 }
  108.         } else {
  109.                 puthelp "NOTICE $nick :Triggers: 4$finish"
  110.         }
  111. }
  112.  
  113. ####Procedure that shows in the chan the text or the action associated with the trigger written in the channel
  114. proc triggers:pubm:trigger { nick uhost handle chan arg } {
  115.         global globalProtect nickProtect triggerchar
  116.         set way ""
  117.         set notice 0
  118.         set ok 0
  119.         set trigger "[string tolower [string range [lindex $arg 0] 1 end]]"
  120.         if { [isop $nick $chan] || [ishalfop $nick $chan] } {
  121.                 if { $trigger=="listtrigger" } {
  122.                         [triggers:list $nick $chan]
  123.                         return 0
  124.                 } elseif { $trigger=="addtrigger" } {
  125.                         triggers:add $nick $chan [join [lrange [split $arg] 1 end]]
  126.                         return 0
  127.                 } elseif { $trigger=="remtrigger" } {
  128.                         triggers:rem $nick $chan [join [lrange [split $arg] 1 end]]
  129.                         return 0
  130.                 }
  131.         } elseif { [isvoice $nick $chan] } {
  132.                 #Voices avoid protection.
  133.         } else {
  134.                 if { [info exists nickProtect($uhost)] == 1 } {
  135.                         putlog "Nick Trigger flood($uhost,$nickProtect($uhost))"
  136.                         if { $nickProtect($uhost) == 2 } {
  137.                                 return 0
  138.                         }
  139.                         incr nickProtect($uhost)
  140.                 } else {
  141.                         set nickProtect($uhost) 1
  142.                         utimer 5 "unset nickProtect($uhost)"
  143.                 }
  144.                 if { [info exists globalProtect] == 1 } {
  145.                         if { $globalProtect == 4 } {
  146.                                 putlog "Global Trigger flood($uhost,$globalProtect)"
  147.                                 return 0
  148.                         }
  149.                         incr globalProtect
  150.                 } else {
  151.                         set globalProtect 1
  152.                         utimer 10 "unset globalProtect"
  153.                 }
  154.         }
  155.         #ways the resulting help text should be sent
  156.         if { [llength $arg] < 2 } {
  157.                 if { [isop $nick $chan] || [ishalfop $nick $chan] ||[isvoice $nick $chan] } {
  158.                         set way "PRIVMSG $chan :\001ACTION"
  159.                         set notice 0
  160.                 } else {
  161.                         set way "NOTICE $nick :$nick:"
  162.                         set notice 0
  163.                 }
  164.         } else {
  165.                 if { [onchan [lindex $arg 1] $chan] && ( [isop $nick $chan] || [ishalfop $nick $chan] || [isvoice $nick $chan] ) } {
  166.                         if { [lindex $arg 2]=="c" } {
  167.                                 set way "PRIVMSG $chan :\001ACTION [lindex $arg 1]"
  168.                                 set notice 3
  169.                         } elseif { [lindex $arg 2]=="p" } {
  170.                                 set way "PRIVMSG [lindex $arg 1] :"
  171.                                 set notice 2
  172.                         } else {
  173.                                 set way "NOTICE [lindex $arg 1] :$nick:"
  174.                                 set notice 1
  175.                         }
  176.                 } else {
  177.                         return 0
  178.                 }
  179.         }
  180.         #now it searches the txt file for the trigger  wrotten in the channel and if it finds something associated with that trigger,
  181.         #it sends it back to the server in the way it was define above.
  182.         if { $way!="" && [file exists [string trimleft $chan #].txt] } {
  183.                 set read [open [string trimleft $chan #].txt r]
  184.                 while  { ![eof $read] } {
  185.                         gets $read line
  186.                         set helpwanted [string range $line 0 [expr [string first # $line]-1]]
  187.                         if { [string tolower [lindex $helpwanted 0]]==[string tolower [string trimleft [lindex $arg 0] $triggerchar]] } {
  188.                                 set ok 1
  189.                                 puthelp "$way [string range $line [expr [string first # $line]+1] end]"
  190.                         }
  191.                 }
  192.                 set final [not $notice $ok $nick $arg]
  193.                 close $read
  194.         }
  195. }
  196.  
  197. proc not { notice ok nick arg } {
  198.         if { $notice==1 && $ok==1 } {
  199.                 puthelp "NOTICE $nick : :) [lindex $arg 1]"
  200.         } elseif { $notice==2 && $ok==1 } {
  201.                 puthelp "NOTICE $nick : :) [lindex $arg 0] [lindex $arg 1]"
  202.         }
  203. }
  204.  
  205. putlog "Triggers.tcl Script loaded."
Add Comment
Please, Sign In to add comment