#################################
### NoTriggers.tcl            ###
### Version 2.1               ###
### By Wcc                    ###
### wcc@techmonkeys.org       ###
### http://dawg.oc255.net:81/ ###
### EFnet #|DAWG|Tcl          ###
#################################

############################################################################
### Copyright © 2000 - 2002 |DAWG| Scripting Group. All rights reserved. ###
############################################################################

#########################################################################
## This script warns users if they type a list trigger in the channel. ##
## It kicks on the second offense, and bans on the third.              ##
#########################################################################

##############
## COMMANDS ##
#############################################
## DCC ## .chanset <channel> +/-notriggers ##
######### Enables or disables trigger      ##
######### protection for a channel.        ##
#############################################

##########################################################
## Just load the script, edit the settings, and rehash. ##
##########################################################

#############################################################
# Set the time in minutes before a ban expires here. If set #
# to 0, the ban will not be removed.                        #
#############################################################

set notriggers_setting(exp) "0"

########################################################
# Set the warning message sent to the channel here.    #
# %nick is substituted with the offending user's nick. #
########################################################

set notriggers_setting(msg) "%nick, please do not use triggers in this channel."

##################################################
# Set the first kick message text here. %nick is #
# substituted with the offending user's nick.    #
##################################################

set notriggers_setting(kmsg) "Please do not use triggers in this channel. The next time you use triggers, you will be banned."

###################################################
# Set the second kick message text here. %nick is #
# substituted with the offending user's nick.     #
###################################################

set notriggers_setting(kmsg2) "Please do not use triggers in this channel."

#############################
# Set the ban type here:    #
# 1 - *!*@host.domain	    #
# 2 - *!user@host.domain    #
# 3 - nick!*@host.domain    #
# 4 - nick!user@host.domain #
# 5 - *!?user@*.host.domain #
#############################

set notriggers_setting(bantype) "1"

####################
# Code begins here #
####################

if {![string match 1.6.* $version]} { putlog "\002NOTRIGGERS:\002 \002WARNING:\002 This script is intended to run on eggdrop 1.6.x or later." }
if {[info tclversion] < 8.2} { putlog "\002NOTRIGGERS:\002 \002WARNING:\002 This script is intended to run on Tcl Version 8.2 or later." }

setudef flag notriggers

bind pubm - * notriggers_parse

proc notriggers_maskban {nick uhost} {
	global notriggers_setting
	switch -- $notriggers_setting(bantype) {
		1 { set ban "*!*@[lindex [split $uhost @] 1]" }
		2 { set ban "*!$uhost" }
		3 { set ban "$nick!*@[lindex [split $uhost @] 1]" }
		4 { set ban "$nick!$uhost" }
		5 { set ban [maskhost $uhost] }
		default { set ban "*!*@[lindex [split $uhost @] 1]" }
	}
	return $ban
}
proc notriggers_parse {nick uhost hand chan text} {
	global notriggers_trigarray notriggers_setting
	if {![botisop $chan] || [isop $nick $chan] || ![regexp {^!list$|^@find |^@locator } $text] || [lsearch -exact [channel info $chan] +notriggers] == -1} { return 0 }
	set banmask [notriggers_maskban $nick $uhost]
	set name [string tolower $chan]![lindex [split $uhost @] 1]
	if {![info exists notriggers_trigarray($name)]} { set notriggers_trigarray($name) 0 }
	incr notriggers_trigarray($name)
	regsub -all -- %nick $notriggers_setting(msg) $nick msg
	switch -- $notriggers_trigarray($name) {
		1 { putserv "PRIVMSG $chan :$msg" }
		2 {
			putserv "KICK $chan $nick :$msg"
			putserv "MODE $chan +b $banmask"
			utimer 10 [list putserv {MODE $chan -b $banmask}]
		}
		default {
			putserv "MODE $chan +b $banmask"
			puthelp "KICK $chan $nick :$msg"
			if {$notriggers_setting(exp) != 0} { timer $notriggers_setting(exp) [list putserv {MODE $chan -b $banmask}] }
		}
	}
}
putlog "\002NOTRIGGERS:\002 NoTriggers.tcl Version 2.1 by Wcc is loaded."
