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."
Thks for help! :D