For any bugs or questions please post here
Code: Select all
#### ++++ Author: MadaliN <madalinmen28@yahoo.com>
### +++ Website: www.Ascenture.ro
## +++ TCL Name: Trigger
# +++ Version: 2.0
## ++++
# Commands:
# !trigger activate (local or global owner)
# !trigger deactivate (local or global owner)
# !trigger url www.ascenture.ro (any user)
# !trigger -list (local or global owner)
# !trigger -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: 5/19/2013
####
bind PUBM - * trigger:main
## ++ Set here what triggers you want the script to work with
set ascenture(trigger) {! . ` ?}
## ++ Set here the flag (local) for the activate/deactivate script (n = owner/m = master/o = operator)
set ascenture(flag-ad) "n"
## ++ Set here the flag (local) to use add/delete/list commands (n = owner/m = master/o = operator)
set ascenture(flag-adl) "n"
## ++ Set here the flag (local) to use the command like '!cmd NICKNAME' (n = owner/m = master/o = operator)
set ascenture(flag-cm) "n"
setudef flag trigger
proc trigger:main {nick uhost hand chan arg} {
global trigger ascenture
if {[string index $arg 0] in $ascenture(trigger)} {
### +++ Checking for triggers
if {[channel get $chan trigger]} {
foreach n [array names trigger $chan,*] {
set newvar [string map [list [string index $arg 0] ""] [lindex [split $arg] 0]]
if {[string match -nocase $newvar [lindex [split $n ","] 1]]} {
if {[llength [lindex [split $arg] 1]] && [matchattr $hand $ascenture(flag-cm)] || [matchattr $hand |$ascenture(flag-cm) $chan]} {
foreach n [split $trigger($n) "|"] { if {[llength $n]} { putserv "PRIVMSG $chan :[lindex [split $arg] 1]: \002$newvar\002 - $n" } }
} else {
set nr 0
foreach n [split $trigger($n) "|"] {
if {[llength $n]} {
incr nr
if {$nr == 1} {
putserv "PRIVMSG $chan :$nick: \002$newvar\002 - $n"
} else {
putserv "PRIVMSG $chan :$nick: $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 triggercmd:$temp(cmd)] != ""} { triggercmd:$temp(cmd) $nick $uhost $hand $chan $arg }
}
proc triggercmd:trigger {nick uhost hand chan arg} {
global trigger ascenture
switch -exact -- [lindex [split $arg] 0] {
activate {
if {[matchattr $hand $ascenture(flag-ad)] || [matchattr $hand |$ascenture(flag-ad) $chan]} {
channel set $chan +trigger
putserv "PRIVMSG $chan :\002$nick\002 - TRIGGER script \00312activated\003 succesfully"
}
}
deactivate {
if {[matchattr $hand $ascenture(flag-ad)] || [matchattr $hand |$ascenture(flag-ad) $chan]} {
channel set $chan -trigger
putserv "PRIVMSG $chan :\002$nick\002 - TRIGGER script \00312deactivated\003 succesfully"
}
}
list -
-list {
if {[matchattr $hand $ascenture(flag-adl)] || [matchattr $hand |$ascenture(flag-adl) $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 $ascenture(flag-adl)] || [matchattr $hand |$ascenture(flag-adl) $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 $ascenture(flag-adl)] || [matchattr $hand |$ascenture(flag-adl) $chan]} {
if {[lindex [split $arg] 1] == ""} { putserv "PRIVMSG $chan :\002$nick\002 - You did not provide ARGS for \00304[lindex [split $arg] 0]\003 command"; return }
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
}
catch {source trigger}
putlog "+++ Succesfully loaded: \00312Trigger TCL Script"