diff wordkick.tcl @ 0:1c4e2814cd41

Initial import.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Sep 2010 13:12:49 +0300
parents
children 593874678e45
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wordkick.tcl	Tue Sep 21 13:12:49 2010 +0300
@@ -0,0 +1,207 @@
+##########################################################################
+#
+# WordKick v1.60 by ccr/TNSP <ccr@tnsp.org>
+#
+# TO-DO:
+# - document this pile of shit.
+#
+##########################################################################
+# Configure these as you like
+
+## Kickword mask/message file
+# (FORMAT: See the example file!)
+set wc_badword_file "data.wordkick"
+
+
+## Stupid call-out kick
+# 1 = kick everyone who only say someone's nick on one public msg
+# 0 = no kick
+set wc_callout_kick 1
+
+# Kickmessage for call-out kick
+set wc_callout_msg "Pälli."
+
+
+## Use "happy messages"?
+# 0 = No
+# 1 = Yes (you'll need the happymessage-file, see below)
+set wc_happy_msg_use 0
+
+
+## "Random happy-joy-joy-messages file"
+# (FORMAT: One message per line)
+set wc_happy_msg_file "data.happymsg"
+
+
+## Gentle mode:
+# 0 = Kick with kickmessage, say happymsg just before kicking
+# 1 = Don't kick, just say happymsg.
+set wc_gentlemode 0
+
+
+## Irritation treshold mode:
+# 0 = Normal, immendiate kick on detected kickword.
+# 1 = Irritation tresholded kick. See README.
+set wc_irritationmode 0
+
+
+## Irritation treshold value
+# Number of how many kickwords to ignore before starting to kick
+set wc_irritationtreshold 4
+
+
+# Preferred message type ("PRIVMSG" and "NOTICE")
+set wc_preferredmsg "PRIVMSG"
+
+
+##########################################################################
+# No need to look below this line
+##########################################################################
+set wc_message "WKick v1.60 by ccr/TNSP"
+set wc_name "WKick"
+
+
+###
+### Read the bad-word file
+###
+catch {unset wc_bad_mask_list}
+catch {unset wc_kick_msg_list}
+set wc_badword_max 0
+set fd [open $wc_badword_file r]
+   while {![eof $fd]} {
+          gets $fd foo
+          if {[string first # $foo] && ([lindex $foo 0] != "")} {
+              set foo [split $foo "$"]
+              lappend wc_bad_mask_list [lindex $foo 0]
+              lappend wc_kick_msg_list [lrange $foo 1 end]
+              incr wc_badword_max
+              }
+         }
+close $fd
+
+
+###
+### Read the happy-message file
+###
+set wc_happy_msg_max 0
+catch {unset wc_happy_msg_list}
+set fd [open $wc_happy_msg_file r]
+   while {![eof $fd]} {
+          gets $fd foo
+              lappend wc_happy_msg_list $foo
+	      incr wc_happy_msg_max
+         }
+close $fd
+
+
+###
+### Initialize the script
+###
+bind time - "* % % % %" wc_timer
+bind pubm - %* wc_check
+bind ctcp - ACTION wc_check
+
+putlog "$wc_message"
+putlog "(maskfile: $wc_badword_file, $wc_badword_max // happymsg: $wc_happy_msg_file, $wc_happy_msg_max)"
+
+if {$wc_irritationmode} {
+putlog "(irritation mode, treshold: $wc_irritationtreshold)" 
+} else {
+putlog "(normal instant wordkick)"
+}
+
+if {$wc_gentlemode} {
+putlog "(gentlemode, no kicking)"
+}
+
+if {$wc_callout_kick} {
+putlog "(call-out idiotism kick mode ON)"
+}
+
+catch {unset wc_irritation}
+set wc_irritation 0
+
+###
+### Change the irritation
+###
+proc wc_timer {umin uhour uday umonth uyear} {
+global wc_irritation
+if {$wc_irritation > 0} {
+	decr wc_irritation
+	}
+}
+
+
+###
+### Match the messages with bad-word list
+###
+proc wc_check {nick uhost hand chan itext} {
+global wc_bad_mask_list wc_kick_msg_list botnick wc_preferredmsg
+global wc_happy_msg_list wc_happy_msg_max wc_name wc_gentlemode
+global wc_irritation wc_irritationmode wc_irritationtreshold
+global wc_callout_kick wc_callout_msg
+
+# Convert to lower case
+ set itext [string tolower $itext]
+
+# Check for idiots
+if {$wc_callout_kick} {
+
+	set ilist [split $itext " "]
+	set isec [lindex $ilist 1]
+
+	if {$isec == "" || $isec == "{}"} {
+	set iword [lindex $ilist 0]
+
+	foreach inick [chanlist $chan] {
+		if {[string match [string tolower "*$inick*"] $iword]} {
+			putlog "$wc_name: $nick@$chan was idiot."
+			putserv "KICK $chan $nick :$wc_callout_msg"
+			}
+		}
+	}
+}
+
+
+# Go through the sentence
+ set kickit 0
+ set x 0
+ foreach foo $wc_bad_mask_list {
+	set foo2 [split $foo "|"]
+
+	foreach i $foo2 {
+	if {[string match $i $itext]} {
+		putlog "$wc_name: $nick@$chan said a bad thing: $i"
+
+# Say happymsg
+		if {[rand 100] > 60} {
+			putserv "$wc_preferredmsg $chan :$nick, [lindex $wc_happy_msg_list [rand $wc_happy_msg_max]]"
+			}
+
+# Check for irritation mode
+		if {$wc_irritationmode != 0} {
+			if {$wc_irritation >= $wc_irritationtreshold} {
+				set kickit 1
+				} else {
+				incr wc_irritation
+				}
+			} else {
+			set kickit 1
+			}
+
+# Check for gentle-mode
+		if {($wc_gentlemode != 0) || [matchattr $hand n]} { return 0 }
+
+# Kick the lamer
+		if {$kickit != 0} {
+			putserv "KICK $chan $nick :[lindex $wc_kick_msg_list $x]"
+			return 0
+			}
+
+		}
+	}
+
+ incr x
+ }
+}
+