Amount of Warnings before action option

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Amount of Warnings before action option

Post by ComputerTech »

So i was wondering how to make it a user can choose how many warnings until kicking

Code: Select all

#Badwords
set swearwords {
"*[censored]*"
"*wank*"
"*pussy*"
"*[censored]*"
}

#Time until reset warnings

set brd "30"


###########Code############
setudef flag ctswear

bind pubm - * ctswear:pub
bind ctcp - ACTION ctswear:act

proc ctswear:pub {nick host hand chan text} {
global swearwords brd
if {[channel get $chan ctswear]} {
	foreach badword $swearwords {
	 if {[string match -nocase $badword $text]} {
incr warn +1
if {$warn($host) == "1"} {
putserv "NOTICE $nick :Warning! Do not Swear on $chan, cease immediately or else"
utimer $brd {set warn "0"}
} elseif {$warn($host) == "2"} {
utimer $brd {set warn "1"}
putserv "NOTICE $nick :Warning! Do not swear on $chan, cease immediately or else"
} elseif {$warn($host) == "3"} { 
putserv "kick $nick $chan Kickbanned from $chan : Reason: Use of swear word $badword"
set warn($host) "0"
    }
   }
  }
 }
}
so like

Code: Select all

set warnings "5"
will allow 5 of

Code: Select all

putserv "NOTICE $nick :Warning! Do not swear on $chan, cease immediately or else"
Before doing

Code: Select all

putserv "kick $nick $chan Kickbanned from $chan : Reason: Use of swear word $badword"
Any ideas and help is much appreciated :D
ComputerTech
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Nevermind :lol:

Found a way

Code: Select all

#Badwords
set swearwords {
"*[censored]*"
"*wank*"
"*pussy*"
"*[censored]*"
}

#Time until reset warnings

set brd "30"

#max warning

set maxwarning "5"

###########Code############
setudef flag ctswear

bind pubm - * ctswear:pub

proc ctswear:pub {nick host hand chan text} {
global swearwords brd maxwarning warn
if {[channel get $chan ctswear]} {
	foreach badword $swearwords {
	 if {[string match -nocase $badword $text]} {
incr warn($host) +1
if{![info exists warn]} {return}
if {![$warn($host) == $maxwarning]} {
putserv "NOTICE $nick :Warning! Do not Swear on $chan, cease immediately or else"
utimer $brd {incr warn($host) -1 }
} else {
putserv "kick $nick $chan Kickbanned from $chan : Reason: Use of swear word $badword"
set warn($host) "0"
    }
   }
  }
 }
}
If anyone knows of a better way of doing this, do share
:P


EDIT: Fixed :)
Last edited by ComputerTech on Fri Feb 19, 2021 3:50 pm, edited 2 times in total.
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1247
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

That's the way I would do it.

Just think about two detals:
- set the warn variable global (or use ::warn)
- check if warn($host) exists before increment it (positive or negative)
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Ok cheers CrazyCat, will do that right away :)
ComputerTech
Post Reply