Mercurial > hg > egg-tcls
annotate wordkick.tcl @ 436:3c816fdc302f
weather: Implement the "great circle distance" algorithm for calculating
distances between two latitude/longitude coordinate pairs, which should be
more accurate than simply using Euclidean distance.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 09 Jan 2017 05:45:40 +0200 |
parents | 825cac46b1cb |
children |
rev | line source |
---|---|
0 | 1 ########################################################################## |
2 # | |
114
593874678e45
Clarify authorship by doing sed "s/ccr\/TNSP/Matti 'ccr' Hamalainen/g".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
3 # WordKick v1.60 by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
0 | 4 # |
5 # TO-DO: | |
6 # - document this pile of shit. | |
7 # | |
8 ########################################################################## | |
9 # Configure these as you like | |
10 | |
11 ## Kickword mask/message file | |
12 # (FORMAT: See the example file!) | |
13 set wc_badword_file "data.wordkick" | |
14 | |
15 | |
16 ## Stupid call-out kick | |
17 # 1 = kick everyone who only say someone's nick on one public msg | |
18 # 0 = no kick | |
19 set wc_callout_kick 1 | |
20 | |
21 # Kickmessage for call-out kick | |
22 set wc_callout_msg "Pälli." | |
23 | |
24 | |
25 ## Use "happy messages"? | |
26 # 0 = No | |
27 # 1 = Yes (you'll need the happymessage-file, see below) | |
28 set wc_happy_msg_use 0 | |
29 | |
30 | |
31 ## "Random happy-joy-joy-messages file" | |
32 # (FORMAT: One message per line) | |
33 set wc_happy_msg_file "data.happymsg" | |
34 | |
35 | |
36 ## Gentle mode: | |
37 # 0 = Kick with kickmessage, say happymsg just before kicking | |
38 # 1 = Don't kick, just say happymsg. | |
39 set wc_gentlemode 0 | |
40 | |
41 | |
42 ## Irritation treshold mode: | |
43 # 0 = Normal, immendiate kick on detected kickword. | |
44 # 1 = Irritation tresholded kick. See README. | |
45 set wc_irritationmode 0 | |
46 | |
47 | |
48 ## Irritation treshold value | |
49 # Number of how many kickwords to ignore before starting to kick | |
50 set wc_irritationtreshold 4 | |
51 | |
52 | |
53 # Preferred message type ("PRIVMSG" and "NOTICE") | |
54 set wc_preferredmsg "PRIVMSG" | |
55 | |
56 | |
57 ########################################################################## | |
58 # No need to look below this line | |
59 ########################################################################## | |
60 set wc_message "WKick v1.60 by ccr/TNSP" | |
61 set wc_name "WKick" | |
62 | |
63 | |
64 ### | |
65 ### Read the bad-word file | |
66 ### | |
67 catch {unset wc_bad_mask_list} | |
68 catch {unset wc_kick_msg_list} | |
69 set wc_badword_max 0 | |
70 set fd [open $wc_badword_file r] | |
71 while {![eof $fd]} { | |
72 gets $fd foo | |
73 if {[string first # $foo] && ([lindex $foo 0] != "")} { | |
74 set foo [split $foo "$"] | |
75 lappend wc_bad_mask_list [lindex $foo 0] | |
76 lappend wc_kick_msg_list [lrange $foo 1 end] | |
77 incr wc_badword_max | |
78 } | |
79 } | |
80 close $fd | |
81 | |
82 | |
83 ### | |
84 ### Read the happy-message file | |
85 ### | |
86 set wc_happy_msg_max 0 | |
87 catch {unset wc_happy_msg_list} | |
88 set fd [open $wc_happy_msg_file r] | |
89 while {![eof $fd]} { | |
90 gets $fd foo | |
91 lappend wc_happy_msg_list $foo | |
92 incr wc_happy_msg_max | |
93 } | |
94 close $fd | |
95 | |
96 | |
97 ### | |
98 ### Initialize the script | |
99 ### | |
100 bind time - "* % % % %" wc_timer | |
101 bind pubm - %* wc_check | |
102 bind ctcp - ACTION wc_check | |
103 | |
104 putlog "$wc_message" | |
105 putlog "(maskfile: $wc_badword_file, $wc_badword_max // happymsg: $wc_happy_msg_file, $wc_happy_msg_max)" | |
106 | |
107 if {$wc_irritationmode} { | |
424
825cac46b1cb
Cosmetic / stray trailing whitespace cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
108 putlog "(irritation mode, treshold: $wc_irritationtreshold)" |
0 | 109 } else { |
110 putlog "(normal instant wordkick)" | |
111 } | |
112 | |
113 if {$wc_gentlemode} { | |
114 putlog "(gentlemode, no kicking)" | |
115 } | |
116 | |
117 if {$wc_callout_kick} { | |
118 putlog "(call-out idiotism kick mode ON)" | |
119 } | |
120 | |
121 catch {unset wc_irritation} | |
122 set wc_irritation 0 | |
123 | |
124 ### | |
125 ### Change the irritation | |
126 ### | |
127 proc wc_timer {umin uhour uday umonth uyear} { | |
128 global wc_irritation | |
129 if {$wc_irritation > 0} { | |
130 decr wc_irritation | |
131 } | |
132 } | |
133 | |
134 | |
135 ### | |
136 ### Match the messages with bad-word list | |
137 ### | |
138 proc wc_check {nick uhost hand chan itext} { | |
139 global wc_bad_mask_list wc_kick_msg_list botnick wc_preferredmsg | |
140 global wc_happy_msg_list wc_happy_msg_max wc_name wc_gentlemode | |
141 global wc_irritation wc_irritationmode wc_irritationtreshold | |
142 global wc_callout_kick wc_callout_msg | |
143 | |
144 # Convert to lower case | |
145 set itext [string tolower $itext] | |
146 | |
147 # Check for idiots | |
148 if {$wc_callout_kick} { | |
149 | |
150 set ilist [split $itext " "] | |
151 set isec [lindex $ilist 1] | |
152 | |
153 if {$isec == "" || $isec == "{}"} { | |
154 set iword [lindex $ilist 0] | |
155 | |
156 foreach inick [chanlist $chan] { | |
157 if {[string match [string tolower "*$inick*"] $iword]} { | |
158 putlog "$wc_name: $nick@$chan was idiot." | |
159 putserv "KICK $chan $nick :$wc_callout_msg" | |
160 } | |
161 } | |
162 } | |
163 } | |
164 | |
165 | |
166 # Go through the sentence | |
167 set kickit 0 | |
168 set x 0 | |
169 foreach foo $wc_bad_mask_list { | |
170 set foo2 [split $foo "|"] | |
171 | |
172 foreach i $foo2 { | |
173 if {[string match $i $itext]} { | |
174 putlog "$wc_name: $nick@$chan said a bad thing: $i" | |
175 | |
176 # Say happymsg | |
177 if {[rand 100] > 60} { | |
178 putserv "$wc_preferredmsg $chan :$nick, [lindex $wc_happy_msg_list [rand $wc_happy_msg_max]]" | |
179 } | |
180 | |
181 # Check for irritation mode | |
182 if {$wc_irritationmode != 0} { | |
183 if {$wc_irritation >= $wc_irritationtreshold} { | |
184 set kickit 1 | |
185 } else { | |
186 incr wc_irritation | |
187 } | |
188 } else { | |
189 set kickit 1 | |
190 } | |
191 | |
192 # Check for gentle-mode | |
193 if {($wc_gentlemode != 0) || [matchattr $hand n]} { return 0 } | |
194 | |
195 # Kick the lamer | |
196 if {$kickit != 0} { | |
197 putserv "KICK $chan $nick :[lindex $wc_kick_msg_list $x]" | |
198 return 0 | |
199 } | |
200 | |
201 } | |
202 } | |
203 | |
204 incr x | |
205 } | |
206 } | |
207 |