Code: Select all
#### ++++ Author: MadaliN <madalinmen28@yahoo.com>
### ++++ TCL Name: Trigger
## ++++
# Commands:
# !trigger activate (local or global owner)
# !triger deactivate (local or global owner)
# !trigger url www.chanrank.com (any user)
# !triger -list (local or global owner)
# !triger -del url (local or global owner)
#
####
# +++ This script can have the same commands saved on two different channels with different information (this means every channel has its own database)
####
# +++ Created: 1/26/2013
####
bind PUBM - * trigger:main
setudef flag trigger
proc trigger:main {nick uhost hand chan arg} {
global trigger
if {[string index $arg 0] in {! . `}} {
### +++ Checking for triggers
foreach c [channels] {
if {[channel get $chan trigger]} {
foreach n [array names trigger $c,*] {
if {[string range $arg 1 end] == [lindex [split $n ","] 1]} {
putserv "PRIVMSG $chan :$trigger($n)"
}
}
}
}
set temp(cmd) [string range $arg 1 end]
set temp(cmd) [lindex [split $temp(cmd)] 0]
set arg [join [lrange [split $arg] 1 end]]
} elseif {[isbotnick [lindex [split $arg] 0]]} {
set temp(cmd) [lindex [split $arg] 1]
set arg [join [lrange [split $arg] 2 end]]
} else { return 0 }
if {[info commands command:$temp(cmd)] != ""} { command:$temp(cmd) $nick $uhost $hand $chan $arg }
}
proc command:trigger {nick uhost hand chan arg} {
global trigger
switch -exact -- [lindex [split $arg] 0] {
activate {
if {[matchattr $hand n] || [matchattr $hand |N $chan]} {
channel set $chan +trigger
putserv "PRIVMSG $chan :\002$nick\002 - TRIGGER script \00312activated\003 succesfully"
}
}
deactivate {
if {[matchattr $hand n] || [matchattr $hand |N $chan]} {
channel set $chan -trigger
putserv "PRIVMSG $chan :\002$nick\002 - TRIGGER script \00312deactivated\003 succesfully"
}
}
list -
-list {
if {[matchattr $hand n] || [matchattr $hand |N $chan]} {
set l ""
foreach a [array names trigger $chan,*] {
lappend l "\00303[lindex [split $a ","] 1]\003"
}
if {$l == ""} {
putserv "PRIVMSG $chan :\002$nick\002 - There are no trigger commands for this channel"
return
} else {
putserv "PRIVMSG $chan :\002$nick\002 - Trigger command list: [join $l "\002,\002 "]"
}
}
}
del -
-del {
if {[matchattr $hand n] || [matchattr $hand |N $chan]} {
if {![info exists trigger($chan,[lindex [split $arg] 1])]} {
putserv "PRIVMSG $chan :\002$nick\002 - There is no command \00312[lindex [split $arg] 1]\003 in my database"
} else {
unset -nocomplain trigger($chan,[lindex [split $arg] 1])
trigger:save
putserv "PRIVMSG $chan :\002$nick\002 - Command \00312[lindex [split $arg] 1]\003 erased succesfully"
}
}
}
default {
if {[matchattr $hand n] || [matchattr $hand |N $chan]} {
if {![info exists trigger($chan,[lindex [split $arg] 0])]} {
set trigger($chan,[lindex [split $arg] 0]) "[join [lrange $arg 1 end]]"
trigger:save
putserv "PRIVMSG $chan :\002$nick\002 - You succesfully added trigger \00312[lindex [split $arg] 0]"
} else {
putserv "PRIVMSG $chan :\002$nick\002 - Command \00312[lindex [split $arg] 0]\003 already exists"
}
}
}
}
}
proc trigger:save {} {
global trigger
set ofile [open trigger w]
puts $ofile "array set trigger [list [array get trigger]]"
close $ofile
}
putlog "+++ Succesfully loaded: \00312Trigger TCL Script"