download bwscript20.tcl
Language: Tcl
LOC: 720
Project Info
xbot4 - The version of X-Bot to supercede ... 2003(xbot4)
Server: Google
Type: svn
...\bin\Debug\xTclLib\scripts\
   _BotnetStats1.9.desc
   _cutetopics100.desc
   _dict109.desc
   _entity92.desc
   _hangman101.desc
   _infobottcl.desc
   _jesusbot1.0.desc
   _jIRCserv-0.02n.desc
   _Lusers.desc
   _mp3list100.desc
   _MsgLog1.1.desc
   _mysqlseen1.1.desc
   _newtopics.desc
   _no.spam.desc
   _quizgod.desc
   _serials100.desc
   _skool101.desc
   _Split4.1.desc
   _thehelper100.desc
   _topicmaster1.1.desc
   _trivia.desc
   _UltramodeNews10.desc
   _UndernetCS.desc
   _userquotes100.desc
   _Veed_0.2.desc
   _WebBanList1.1.desc
   _words100.desc
   _zipcodes100.desc
   abuse100.desc
   abuse100.tcl
   action.fix.desc
   action.fix.tcl
   activech100.desc
   activech100.tcl
   adbseen192.desc
   Adbseen192.tcl
   addban10-mbti.desc
   addban10-mbti.tcl
   added140.desc
   Added140.tcl
   addicted100.desc
   addicted100.tcl
   advert105.desc
   advert105.tcl
   alice120.desc
   alice120.tcl
   alltools.desc
   alltools.tcl
   antiidle-narf-0.3.desc
   antiidle-narf-0.3.tcl
   auth103.desc
   auth103.tcl
   autolimit102.desc
   autolimit102.tcl
   autooper.desc
   autooper.tcl
   av.pubmsg.desc
   av.pubmsg.tcl
   bancheck.desc
   bancheck.tcl
   BanCount1.1.desc
   BanCount1.1.tcl
   BanTools1.2.desc
   BanTools1.2.tcl
   bitchxirix.desc
   bitchxirix.tcl
   bot-solutions.3.0.desc
   bot-solutions.3.0.tcl
   botping.desc
   botping.tcl
   bwscript20.desc
   bwscript20.tcl
   chancheck100.desc
   chancheck100.tcl
   ChanMax1.2.desc
   ChanMax1.2.tcl
   ChanPeak1.3.desc
   ChanPeak1.3.tcl
   chanrelay.desc
   chanrelay.tcl
   ClanAvail1.4.desc
   ClanAvail1.4.tcl
   ClanBase1.1.desc
   ClanBase1.1.tcl
   cmd_resolve.desc
   cmd_resolve.tcl
   compat.desc
   compat.tcl
   CopyVoice1.3.desc
   CopyVoice1.3.tcl
   cracks100.desc
   cracks100.tcl
   DALnetNews1.1.desc
   DALnetNews1.1.tcl
   date1.3.desc
   date1.3.tcl
   DateToDay1.0.desc
   DateToDay1.0.tcl
   daystill102.desc
   daystill102.tcl
   dccwatch104.desc
   dccwatch104.tcl
   Decide1.2.desc
   Decide1.2.tcl
   decide100.desc
   decide100.tcl
   define.desc
   define.tcl
   delhost1.01.desc
   delhost1.01.tcl
   delivery101.desc
   delivery101.tcl
   Dictionary1.1.desc
   Dictionary1.1.tcl
   DieAuth2.1.desc
   DieAuth2.1.tcl
   Dns2.5.desc
   Dns2.5.tcl
   DomainWhois1.2.desc
   DomainWhois1.2.tcl
   EFnetNews1.1.desc
   EFnetNews1.1.tcl
   egg-fu.1.7.desc
   egg-fu.1.7.tcl
   eggpad.desc
   eggpad.tcl
   englishonly102.desc
   englishonly102.tcl
   filerelay0.4.desc
   filerelay0.4.tcl
   fluxlearn1.5a.desc
   fluxlearn1.5a.tcl
   flyby101.desc
   flyby101.tcl
   gamble100.desc
   gamble100.tcl
   gamestar1.4.desc
   gamestar1.4.tcl
   GBan1.4.desc
   GBan1.4.tcl
   getops-2.6.desc
   getops-2.6.tcl
   getops.desc
   getops.tcl
   greeter101.desc
   greeter101.tcl
   guard101.desc
   guard101.tcl
   heise1.4.desc
   heise1.4.tcl
   HostSpy1.8.desc
   HostSpy1.8.tcl
   HostTools1.5.desc
   HostTools1.5.tcl
   HTMLOpVote2.0.desc
   HTMLOpVote2.0.tcl
   ident.desc
   ident.tcl
   ieXbeta1.1.desc
   ieXbeta1.1.tcl
   ilc100.desc
   ilc100.tcl
   infoegg-v1-3.desc
   infoegg-v1-3.tcl
   insult101.desc
   insult101.tcl
   inv.desc
   inv.tcl
   irco-fuckem.desc
   irco-fuckem.tcl
   irco-muh.desc
   irco-muh.tcl
   irco-psybnc.desc
   irco-psybnc.tcl
   irco-scanport.desc
   irco-scanport.tcl
   irco-soundkick.desc
   irco-soundkick.tcl
   irco-wingateban.desc
   irco-wingateban.tcl
   kick100.desc
   kick100.tcl
   kickad100.desc
   kickad100.tcl
   KillLog2.5.desc
   KillLog2.5.tcl
   klined.desc
   klined.tcl
   lamer.desc
   lamer.tcl
   lanparty.desc
   lanparty.tcl
   limit-v1.1.desc
   limit-v1.1.tcl
   limitchan.desc
   limitchan.tcl
   LinkedBots1.2.desc
   LinkedBots1.2.tcl
   maxvisitors101.desc
   maxvisitors101.tcl
   mc.banchan.desc
   mc.banchan.tcl
   mc.spamcheck.desc
   mc.spamcheck.tcl
   megadeth100.desc
   megadeth100.tcl
   mIRCShitlist1.2.desc
   mIRCShitlist1.2.tcl
   moi.desc
   moi.tcl
   netlink107.desc
   netlink107.tcl
   NetStats1.2.desc
   NetStats1.2.tcl
   news.desc
   news.tcl
   news2html.desc
   news2html.tcl
   NoAccess1.1.desc
   NoAccess1.1.tcl
   noads108.desc
   noads108.tcl
   noawayactions1.03.desc
   noawayactions1.03.tcl
   NoColors1.2.desc
   NoColors1.2.tcl
   nocomics100.desc
   nocomics100.tcl
   NoFservs1.5.desc
   NoFservs1.5.tcl
   nosense2.desc
   nosense2.tcl
   notes2.desc
   notes2.tcl
   NoTriggers2.3.desc
   NoTriggers2.3.tcl
   oannouce100.desc
   oannouce100.tcl
   ok1.3.desc
   ok1.3.tcl
   opbegger103.desc
   opbegger103.tcl
   opkillsnn.desc
   opkillsnn.tcl
   OpNotice1.9.desc
   OpNotice1.9.tcl
   pa-trgt3_68.desc
   pa-trgt3_68.tcl
   passgen.desc
   passgen.tcl
   pcgames.desc
   pcgames.tcl
   pickakick102.desc
   pickakick102.tcl
   PortCheck2.2.desc
   PortCheck2.2.tcl
   postal101.desc
   postal101.tcl
   Pub.desc
   Pub.tcl
   pwf.desc
   pwf.tcl
   ques5.desc
   ques5.tcl
   ran.desc
   ran.tcl
   RandRead1.1.desc
   RandRead1.1.tcl
   randtopic2.04.desc
   randtopic2.04.tcl
   recruiters100.desc
   recruiters100.tcl
   released102.desc
   released102.tcl
   SearchPage.desc
   SearchPage.tcl
   sentinel.desc
   sentinel.tcl
   Services2.0.desc
   Services2.0.tcl
   sharereactor1.0.desc
   sharereactor1.0.tcl
   ShellTime1.6.desc
   ShellTime1.6.tcl
   ShellUptime1.0.desc
   ShellUptime1.0.tcl
   shortnews.desc
   shortnews.tcl
   showchans104.desc
   showchans104.tcl
   sound_dos-0.02a.desc
   sound_dos-0.02a.tcl
   Spod.desc
   Spod.tcl
   spymsg.desc
   spymsg.tcl
   StockQuote.desc
   StockQuote.tcl
   striptease104.desc
   striptease104.tcl
   SubChan2.0.desc
   SubChan2.0.tcl
   superbitch0.45.desc
   superbitch0.45.tcl
   sync1.2.desc
   sync1.2.tcl
   tan101.desc
   tan101.tcl
   tempc100.desc
   tempc100.tcl
   textsearch0.2.desc
   textsearch0.2.tcl
   TimeIdent1.0.desc
   TimeIdent1.0.tcl
   TimeMessage1.0.desc
   TimeMessage1.0.tcl
   TimeRehash1.0.desc
   TimeRehash1.0.tcl
   tool-lyrics.desc
   tool-lyrics.tcl
   top10.desc
   top10.tcl
   topiclock2.04.desc
   topiclock2.04.tcl
   topiclogger1.01.desc
   topiclogger1.01.tcl
   ucsx0.2.desc
   ucsx0.2.tcl
   uptime1.08.desc
   uptime1.08.tcl
   UrlGet1.4.desc
   UrlGet1.4.tcl
   userinfo.desc
   userinfo.tcl
   VerboseMail1.1.desc
   VerboseMail1.1.tcl
   Voice1.1.desc
   Voice1.1.tcl
   voiceallbut102.desc
   voiceallbut102.tcl
   voicebitch0.1.desc
   voicebitch0.1.tcl
   VoiceFservs1.3.desc
   VoiceFservs1.3.tcl
   vote1.14.desc
   vote1.14.tcl
   warn100.desc
   warn100.tcl
   weather3.3.1.desc
   weather3.3.1.tcl
   WebSiteStatus1.0.desc
   WebSiteStatus1.0.tcl
   Whatis1.5.desc
   Whatis1.5.tcl
   Whom1.0.desc
   Whom1.0.tcl
   winfuture.desc
   winfuture.tcl
   winident1.2.desc
   winident1.2.tcl
   worldtime.desc
   worldtime.tcl
   x-commands0.1.desc
   x-commands0.1.tcl
   zdnet1.1.desc
   zdnet1.1.tcl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
#	Advanced bad word script v2.0
#
#	Authors: SprudL <sprudl@advalvas.be>, Demian <demian@pandora.be>
#	Initially For Eggdrop 1.6.3 & TCL 8.3
#	Tested with most subsequent versions (up to 1.6.12)
#
############################################################
#
#	HISTORY:
#			5/2001 v0.9: Initial release by Sprudl and Demian
#			9/2002 v2.0: Update by Demian
#
#				Consisting of:	* Exempts are added now (.badword addexempt and delexempt).
#						* Bantime can be 0 (only a kick).
#						* .badword search is added.
#						* .badword view is added.
#
############################################################


####CONFIGURATION

# Lists loaded at startup
set bw_initLists "general.abw"

# Channel where script is active
set bw_chans {#donna}

# Kick chanops?
set bw_kickOpped 0

# For consulting BW lists & stats
set bw_lowAccessFlags "o|omn"	 

# For editing BW database
set bw_highAccessFlags "Bmn"

# Path to BW files	
set bw_dbPath "scripts/bwdb/"

# End of configuration section 
###########################################################

# Binds for checking badwords
bind pubm - * badwcheck
bind join - * badjcheck
bind nick - * badncheck
bind CTCP - ACTION badacheck  

# Binds for commands
bind dcc - badword bw_dcccommand
bind msg - badword bw_msgcommand

proc badwcheck {nick host handle chan text} {
	parseText $nick $host $chan $text "w"
}

proc badacheck {nick uhost hand chan keyword text} {
	parseText $nick $uhost $chan $text "w"
}

proc badjcheck {nick host handle chan} {
	parseText $nick $host $chan $nick "n"
}

proc badncheck {nick host handle chan newnick} {
	parseText $nick $host $chan $newnick "n"
}

proc parseText {nick uhost chan text src} {
# Checks text for badwords
	global bw_kickOpped bw_badwords botnick bw_chans botnick
	if {[string match $src "n"]} { set nick $text }
	if {!$bw_kickOpped && [isop $nick $chan]} { return 0 }
	if {[lsearch -exact $bw_chans $chan] < 0} { return 0 }
	if {[isbotnick $nick] || ![botisop $chan]} { return 0 }
	
	set words [split [stripControlCodes $text]]
	array set bwfound {} 

	foreach word $words {
		putloglev 4 * "ABW: Word: $word"
		foreach bword $bw_badwords {
			global $bword
			if {![string compare [set ${bword}(type)] "b"] || ![string compare [set ${bword}(type)] $src]} {
				if {[string match [string tolower [set ${bword}(pattern)]] [string tolower $word]]} {
					foreach exempt [set ${bword}(exempts)] {
						if {[string match [string tolower $exempt] [string tolower $word]]} { 
					 		return 0 
						}
					}		 
					putloglev 5 * "ABW: match found -->  Pattern: [set ${bword}(pattern)] -- Word: $word"
					array set bwfound [array get ${bword}]
				}
			}
		}
	}

	if {[array size bwfound]} {
		set bantime $bwfound(bantime)
		if { $bantime > 0 } {
			if {[string match $src "n"]} {
				newchanban $chan $bwfound(pattern)!*@*.* $botnick "$bwfound(reason) (NICKBAN)" $bantime
			} else {
				set banmask "*!$uhost"
				newchanban $chan $banmask $botnick $bwfound(reason) $bantime
			}
		}
		putkick $chan $nick $bwfound(reason)
	}
	return 0
}

proc bw_dcccommand {handle idx text} {
# Takes care of commands via DCC
	set outputList [bw_parseCommand $handle $text]
	foreach elem $outputList {
		putdcc $idx "$elem"
	}
	return 1
}

proc bw_msgcommand {nick host handle text} {
# Takes care of commands via msg
	global bw_chans
	set password [lindex $text 0]
	set arguments [lrange $text 1 end]
	if {[passwdok $handle $password]} {
		set outputList [bw_parseCommand $handle $arguments]
		foreach elem $outputList {
			puthelp "PRIVMSG $nick :$elem"
		}
	} else {
		puthelp "PRIVMSG $nick :Password Error."
	}
	return 0
}

proc bw_parseCommand {handle text} {
# Parses commands and calls appropriate command handler
# Returns results or error code to calling wrapper function
	set command [string tolower [lindex $text 0]]
	set arguments [split [lrange $text 1 end]]
	# Needs some re-thinking
#putcmdlog "#$handle# $command $arguments"
	if {[highAccess $handle]} {
		switch -exact $command {	
			add { return [bw_addWord $arguments] }
			delete { return [bw_deleteWord $arguments] }
			modify { return [bw_modifyWord $arguments] }
			load { return [bw_loadList $arguments] }
			save { return [bw_saveList $arguments] }
			unload { return [bw_unloadList $arguments] }
			unloadall { return [bw_unloadAllLists] }
			clear { return [bw_clearList $arguments] }
			loaded { return [bw_listLoadedFiles] }
			addexempt { return [bw_addExempt $arguments] }
			delexempt { return [bw_deleteExempt $arguments] }
		}
	} 
	if {[lowAccess $handle]} {
		switch -exact $command {
			patterns { return [bw_showPatterns $arguments] }
			view { return [bw_viewWord $arguments] } 
			stats { return [bw_showStats $arguments] }
			search { return [bw_search $arguments] } 
			help { return [bw_help $arguments $handle]
			}
		}
	}
}

proc bw_addWord {arguments} {
# Add 1 pattern to BW list
# Syntax .badword add pattern type minutes reason file
	global bw_delimiter bw_lists bw_badwords bw_dbPath bw_types 
	set arglength [llength $arguments]
	set pattern [lindex $arguments 0]
	set type [lindex $arguments 1]
	set minutes [lindex $arguments 2]
	set reason [lrange $arguments 3 [expr ($arglength-2)]]
	set file [lindex $arguments end]

	set outputList {}

	if {[llength $arguments] < 5 } { return {"Not enough parameters"}} 
	if {[string first $type $bw_types] < 0} { return [lappend outputList "Unknown type $type"] }
	if {![string is integer $minutes]} { return {"Bantime has to be an integer"}}
	if { $minutes < 0 } { return {"Bantime has to be positive.."} }
	set temp [checkFile ${bw_dbPath}$file] 
	if { $temp != 1 } { return [lappend outputList $temp] } 

	# add badword to current memory, if list loaded
	set badword "${pattern}${bw_delimiter}${type}${bw_delimiter}${minutes}${bw_delimiter}${reason}${bw_delimiter}"
	foreach list $bw_lists {
		if {[string match [string tolower $list] [string tolower $file]]} {
			set bw_badwords [concat $bw_badwords [createBWArrays [list $badword] $file]]
			
		}
	}	
	# write badword to file
	appendFile "$bw_dbPath$file" [list $badword]	
	return {"Badword added."}
}

proc bw_addExempt {arguments} {
# Add 1 exempt to a bad word
# Syntax .badword addexempt exempt word file
 	global bw_delimiter bw_lists bw_badwords bw_dbPath bw_types
	set arglength [llength $arguments]
	set exempt [lindex $arguments 0]
	set exempts {}
	set pattern [lindex $arguments 1] 
	set file [lindex $arguments end]
	set outputList {}

        if {[llength $arguments] < 3 } { return {"Not enough parameters"}}
	if {[llength $arguments] > 3 } { return {"Too many parameters"}}
        set temp [checkFile ${bw_dbPath}$file]
        if { $temp != 1 } { return [lappend outputList $temp] }

	# add exempt in file
	set fileContentList [readFile ${bw_dbPath}$file]
	set patternlist {}
	set patternIndex -1 
	foreach elem $fileContentList {
		set elemPattern [lindex [split $elem $bw_delimiter] 0]
		set patternlist [lappend patternlist $elemPattern]
		if {[string match $pattern $elemPattern]} {
			set patternIndex [lsearch $patternlist $pattern]
		}
	}
	

	if {$patternIndex >= 0} {
		set type [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 1]
		set minutes [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 2]
		set reason [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 3]
		set exempts [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 4]
		
		set exempts [lappend exempts $exempt]
		set badword "${pattern}${bw_delimiter}${type}${bw_delimiter}${minutes}${bw_delimiter}${reason}${bw_delimiter}${exempts}"
		set fileContentList [lreplace $fileContentList $patternIndex $patternIndex $badword]
		writeFile "$bw_dbPath$file" $fileContentList
	} else {
		return {"Bad word not in list."}
	}
	
	# add exempt in memory, if necessary.
	foreach list $bw_lists {
		if [string match [string tolower $file] [string tolower $list]] {
			set patternlist ""
			foreach elemnt $bw_badwords {
				global $elemnt
				set patternlist [lappend patternlist [set ${elemnt}(pattern)]]
			}

			set badwordLoc [lsearch -exact $patternlist $pattern]
			if {$badwordLoc >= 0} {
				set bword [lindex $bw_badwords $badwordLoc]
				if {[string match [set ${bword}(file)] $file]} {
					set ${bword}(exempts) $exempts
				}
			}
		}
	}
	return {"Exempt added."}
}

proc bw_deleteExempt {arguments} {
        global bw_delimiter bw_lists bw_badwords bw_dbPath bw_types
        set arglength [llength $arguments]
        set exempt [lindex $arguments 0]
        set exempts {}
        set pattern [lindex $arguments 1]
        set file [lindex $arguments end]
        set outputList {}

        if {[llength $arguments] < 3 } { return {"Not enough parameters"}}
        if {[llength $arguments] > 3 } { return {"Too many parameters"}}  
        set temp [checkFile ${bw_dbPath}$file]
        if { $temp != 1 } { return [lappend outputList $temp] }

        # add exempt in file
        set fileContentList [readFile ${bw_dbPath}$file]
        set patternlist {}
        set patternIndex -1
        foreach elem $fileContentList {
                set elemPattern [lindex [split $elem $bw_delimiter] 0]
                set patternlist [lappend patternlist $elemPattern]
                if {[string match $pattern $elemPattern]} {
                        set patternIndex [lsearch $patternlist $pattern]
                }
        }


        if {$patternIndex >= 0} {
                set type [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 1]
                set minutes [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 2]
                set reason [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 3]
                set exempts [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 4]
		set exemptFound [lsearch $exempts $exempt]
		if {$exemptFound<0} {
			return {"Exempt not found."}
		} 
		set exempts [lreplace $exempts $exemptFound $exemptFound]
                set badword "${pattern}${bw_delimiter}${type}${bw_delimiter}${minutes}${bw_delimiter}${reason}${bw_delimiter}${exempts}"
                set fileContentList [lreplace $fileContentList $patternIndex $patternIndex $badword]
                writeFile "$bw_dbPath$file" $fileContentList
        } else {
                return {"Bad word not in list."}
        }

        # delete exempt in memory, if necessary.
        foreach list $bw_lists {
                if [string match [string tolower $file] [string tolower $list]] {
                        set patternlist ""
                        foreach elemnt $bw_badwords {
                                global $elemnt
                                set patternlist [lappend patternlist [set ${elemnt}(pattern)]]
                        }

                        set badwordLoc [lsearch -exact $patternlist $pattern]
                        if {$badwordLoc >= 0} {
                                set bword [lindex $bw_badwords $badwordLoc]
                                if {[string match [set ${bword}(file)] $file]} {
                                        set ${bword}(exempts) $exempts
                                }
                        }
                }
        }
	return {"Exempt removed."}
}
proc bw_viewWord {arguments} {
# View information about a bad word. File does not have to be loaded.
# Syntax .badword view pattern file
	global bw_dbPath bw_delimiter bw_badwords
	
	set pattern [lindex $arguments 0]
	set file [lindex $arguments 1]
	set outputList {}
	## Search in memory
	if {[string match $file ""]} {
		foreach element $bw_badwords {
			global $element
			if {[string match [set ${element}(pattern)] $pattern]} {
				set type [set ${element}(type)]	 	
				set minutes [set ${element}(bantime)]
				set reason [set ${element}(reason)]
				set exempts [set ${element}(exempts)]
				set bwfile [set ${element}(file)]
                		set outputList [lappend outputList "Badword Information for: $pattern"]
                		set outputList [lappend outputList "  Type: $type"]
                		set outputList [lappend outputList "  Bantime: $minutes minutes"]
                		set outputList [lappend outputList "  Kickreason: $reason"]
				set outputList [lappend outputList "  Exempts: $exempts"]
				set outputList [lappend outputList "  File: $bwfile"]
				return $outputList
			}
		}
		return {"Pattern not found in current memory."}
	} else {
	## Search in file
        	set fileContentList [readFile ${bw_dbPath}$file]
        	set patternIndex -1
        	foreach elem $fileContentList {
                	set elemPattern [lindex [split $elem $bw_delimiter] 0]
                	set patternlist [lappend patternlist $elemPattern]
                	if {[string match $pattern $elemPattern]} {
                        	set patternIndex [lsearch $patternlist $pattern]
                	}
       		 }

        	if {$patternIndex >= 0} {
                	set type [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 1]
                	set minutes [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 2]
                	set reason [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 3]
                	set exempts [lindex [split [lindex $fileContentList $patternIndex] $bw_delimiter] 4]
		
			set outputList [lappend outputList "Badword Information for: $pattern"]
			set outputList [lappend outputList "  Type: $type"]
			set outputList [lappend outputList "  Bantime: $minutes minutes"]
			set outputList [lappend outputList "  Kickreason: $reason"]
			set outputList [lappend outputList "  Exempts: $exempts"]

			return $outputList
		} else { return {"Badword not found in that list."}}
	}
}

proc bw_deleteWord {arguments} {
# Delete word from BW list.  File does not have to be loaded!
# Syntax .badword delete pattern file
	global bw_dbPath bw_lists bw_badwords bw_delimiter bw_types
	set pattern [lindex $arguments 0]
	set file [lindex $arguments 1]
	set outputList {}
	
	if {[llength $arguments] < 2 } { return {"Not enough arguments"} }
	if {[llength $arguments] > 2 } { return {"Too many arguments"} }
	set temp [checkFile ${bw_dbPath}$file]  
	if { $temp != 1 } { return [lappend outputList $temp]}

	set fileContentList [readFile ${bw_dbPath}$file]
	set patternlist {}
	foreach elem $fileContentList {
		set elemPattern [lindex [split $elem $bw_delimiter] 0]
		lappend patternlist $elemPattern
	}
	
	# delete word from file
	set patternIndex [lsearch -exact $patternlist $pattern]
	if {$patternIndex >= 0} {
		set fileContentList [lreplace $fileContentList $patternIndex $patternIndex]
		writeFile "$bw_dbPath$file" $fileContentList
	} else {	
		return {"Bad word not in list."}
	}
	
	# delete word from list in memory, if necessary
	foreach list $bw_lists {
		if [string match [string tolower $file] [string tolower $list]] {
			set patternlist {} 
			foreach element $bw_badwords {
				global $element		
				set patternlist [lappend patternlist [set ${element}(pattern)]]
			}
			set badwordLoc [lsearch -exact $patternlist $pattern]
			if {$badwordLoc >= 0} {
				set badword [lindex $bw_badwords $badwordLoc]
				if {[string match [set ${badword}(file)] $file]} {
					set bw_badwords [lreplace $bw_badwords $badwordLoc $badwordLoc]
					unset ${badword}
				} else {
					return {"Word in another list"}
				}
			} else {
				return {"Word not found ?!! Impossible."}
			}
		}
	}
	return {"Bad word removed."}
}

proc bw_modifyWord {arguments} {
# Modify word from BW list.  File does not have to be loaded!
# Syntax .badword modify pattern file newpattern newtype newminutes newreason
	global bw_dbPath bw_lists bw_badwords bw_delimiter bw_types
	set pattern [string tolower [lindex $arguments 0]]
	set file [lindex $arguments 1]
	set newpattern [lindex $arguments 2]
	set newtype [lindex $arguments 3]
	set newminutes [lindex $arguments 4]
	set newreason [lrange $arguments 5 end]
	set outputList {}

	if {[llength $arguments] < 6 } { return {"Not enough parameters"} } 
	if {[string first $newtype $bw_types] < 0} { return [lappend outputList "Unknown type $newtype"] }
	if {![string is integer $newminutes]} { return {"Bantime has to be an integer"} }
	if { $newminutes < 0 } { return {"Bantime has to be positive.."} }
	set temp [checkFile ${bw_dbPath}$file]
	if {$temp != 1} { return [lappend outputList $temp] }

	set newBadword "${newpattern}${bw_delimiter}${newtype}${bw_delimiter}${newminutes}${bw_delimiter}${newreason}"
	set fileContentList [readFile ${bw_dbPath}$file]
	set patternlist {}
	foreach elem $fileContentList {
		set elemPattern [lindex [split $elem $bw_delimiter] 0]
		set patternlist [lappend patternlist $elemPattern]
	}

	# modify word from file
	set patternIndex [lsearch -exact $patternlist $pattern]
	if {$patternIndex >= 0} {
		set fileContentList [lreplace $fileContentList $patternIndex $patternIndex $newBadword]
		writeFile "$bw_dbPath$file" $fileContentList
	} else {
		return {"Bad word not in list."}
	}

	# delete word from list in memory, if necessary
	foreach list $bw_lists {
		if [string match [string tolower $file] [string tolower $list]] {
			set patternlist ""
			foreach element $bw_badwords {
				global $element
				set patternlist [lappend patternlist [set ${element}(pattern)]]
			}
			set badwordLoc [lsearch -exact $patternlist $pattern]
			if {$badwordLoc >= 0} {
				set badword [lindex $bw_badwords $badwordLoc]
				if {[string match [set ${badword}(file)] $file]} {
					set ${badword}(pattern) $newpattern
					set ${badword}(type) $newtype
					set ${badword}(minutes) $newminutes
					set ${badword}(reason) $newreason
				} else {
					return {"Word in another list."}
				}                                       
			} else {
				return {"Word not found ?!! Impossible."}
			}
		}
	}
	return {"Bad word modified."}
}

proc bw_search {arguments} {
	global bw_badwords
	set pattern [lindex $arguments 0]
	if {[llength $arguments] < 1} { return {"Not enough parameters."} }
	if {[llength $arguments] > 1 } { return {"Too many arguments"} }

	set patternList {}
	set outputList {}

	foreach element $bw_badwords {
		global $element
		if {[string match [string tolower $pattern] [string tolower [set ${element}(pattern)]]]} {
			set patternList [lappend patternList [set ${element}(pattern)]]
		}
	}

	if {![llength $patternList]} {
		return {"No matches found."}
	} else {
		set outputList [lappend outputList "The following patterns were found:"]
		set outputList [lappend outputList $patternList]
		return $outputList
	}
}

proc bw_loadList {arguments} {
# Load file with patterns
# Syntax: .badword load filename
	set outputList {}
	if {[llength $arguments] < 1 } { return {"Not enough arguments"} } 
	if {[llength $arguments] > 1 } { return {"Too many arguments"} } 
	return [lappend outputList [expandWordList $arguments]] 
}

proc bw_saveList {arguments} {
# Save current list to file
# Syntax: .badword save filename [new]
	global bw_dbPath bw_badwords bw_lists bw_delimiter
	set outputList {}

	if {[llength $arguments]<1} { return {"Not enough arguments"} }
	if {[llength $arguments] > 2 } { return {"Too many arguments"} } 
	set file [lindex $arguments 0]
	set fqFile "$bw_dbPath$file"
	set new 0
	if {[string compare [string tolower [lindex arguments 1]] "new"] || [lsearch -exact $bw_lists $file]<0} {
		set new 1
	}
	set tempList {}
	foreach bword $bw_badwords {
		global $bword
		set str "[set ${bword}(pattern)]$bw_delimiter[set ${bword}(type)]$bw_delimiter[set ${bword}(bantime)]$bw_delimiter[set ${bword}(reason)]"
		lappend tempList $str
	}
	if {$new} {
		writeFile $fqFile $tempList
	} else {
		appendFile $fqFile $tempList
	}
	return [lappend outputList "List saved to $file"]
}

proc bw_unloadList {arguments} {
# Unload list from memory
# Syntax: .badword unload filename
	set outputList {}
	if {[llength $arguments] < 1} { return {"Not enough parameters."} }
	if {[llength $arguments] > 1} { return {"Too many parameters."}}
	set file $arguments
	global bw_badwords bw_lists

	set i [lsearch -exact $bw_lists $file]
	if {$i<0} {
		return {"File not loaded"}
	}
	set bw_lists [lreplace $bw_lists $i $i]
	foreach bword $bw_badwords {
		global $bword
		set i [lsearch -exact $bw_badwords $bword]
		if {![string compare $file [set ${bword}(file)]]} {
			set bw_badwords [lreplace $bw_badwords $i $i]
			unset ${bword}
		}
	}
	return [lappend outputList "Patterns from $file unloaded"]
}

proc bw_unloadAllLists {} {
# Clear patterns from memory
	global bw_badwords bw_lists
	set outputList {}
	
	if {[llength $bw_lists]<1} { return {"No lists loaded"} }
	
	foreach bword $bw_badwords {
		global $bword
		unset ${bword}
	}
	set bw_badwords {}
	set bw_lists {}
	return {"All patterns cleared"}
}

proc bw_listLoadedFiles {} {
# Returns list of BW files in $bw_dbPath
	global bw_lists
	set outputList {}

	if {[llength $bw_lists]<1} { 
		return {"No lists loaded"} 
	} else {
		return [lappend outputList "Files loaded: $bw_lists"]
	}
}

proc bw_showPatterns {args} {
# Returns formatted list of patterns
        global bw_badwords
        set patternList ""
        set outputList ""

        if {[llength $bw_badwords]<1} {
                return {"No patterns loaded"}
        } else {
                foreach badword $bw_badwords {
                        global $badword
                        set patternList [lappend patternList [set ${badword}(pattern)]]
                }
        for { set i 0 } { $i < [llength $patternList] } { incr i 15 } {
                lappend outputList [lrange $patternList $i [expr ($i + 14)]]
        }
        return $outputList
        }
}

proc bw_help {arguments handle} {
        set outputList ""
        if {[llength $arguments]>1} { return [lappend outputList "Not enough parameters"] }

        if [highAccess $handle] {
                switch -exact $arguments {
                        add {
                                lappend outputList "SYNTAX: badword add <pattern> <type> <minutes> <reason> <file>"
                                lappend outputList "USE: Adding a badword to a list (which doesn't have to be loaded)"
                                lappend outputList "<type> must be w/n/b (word/nick/both)"
                                lappend outputList "<file> must be an existing file."
				lappend outputList "Bantime = 0 means the bot will not ban, only kick."
                                return $outputList
                        }
                        delete {
                                lappend outputList "SYNTAX: badword delete <pattern> <file>"
                                lappend outputList "USE: Deleting a badword from a list (which doesn't have to be loaded)"
                                return $outputList
                        }
                        modify {
                                lappend outputList "SYNTAX: badword modify <pattern> <file> <newpattern> <newtype> <newminutes> <new reason>"
                                lappend outputList "USE: Modifying a bad word in a list (which doesn't have to be loaded)"
                                lappend outputList "<newtype> must be w/n/b (word/nick/both)"                        
				lappend outputList "Bantime = 0 means the bot will not ban, only kick."
				return $outputList
			}
                        load {
                                lappend outputList "SYNTAX: badword load <file>"
                                lappend outputList "USE: Adding a badword-list to the currently loaded badwords."
                                return $outputList
                        }
                        unload {
                                lappend outputList "SYNTAX: badword unload <file>"
                                lappend outputList "USE: Removing a badword-list from the currently loaded badwords."
                                return $outputList
                        }
                        unloadall {
                                lappend outputList "SYNTAX: badword unloadall"
                                lappend outputList "USE: Removing all loaded lists from the currently loaded badwords (empties it)"
                                return $outputList
                        }
                        loaded {
                                lappend outputList "SYNTAX: badword loaded"
                                lappend outputList "USE: Showing the currently loaded listnames."
                                return $outputList
                        }
                        save {
                                lappend outputList "SYNTAX: badword save <file> \[new\]"
                                lappend outputList "USE: Saving the currently loaded badwords to <file>"
                                lappend outputList "\[new\] must be added when you want the badwords written to a new file,"
				lappend outputList "or to overwrite a currently existing file."
				lappend outputList "When it is omitted the bad words will be added to <file> if it exists,"
				lappend outputList "or written to a new file, if it doesn't."
                                return $outputList
                                }
                        addexempt {
                                lappend outputList "SYNTAX: badword addexempt <exempt> <pattern> <file>"
                                lappend outputList "USE: Adding an exempt to <pattern> in <file>."
                                return $outputList
                		}
                        delexempt {
                                lappend outputList "SYNTAX: badword delexempt <exempt> <pattern> <file>"
                                lappend outputList "USE: Removing an exempt from <pattern> in <file>." 
                                return $outputList
				}
                }
        }
        if [lowAccess $handle] {
                switch -exact $arguments {
                        "" {
                                lappend outputList "Available commands:"
                                if [highAccess $handle] {
                                        lappend outputList "add - delete - modify - load - unload - unloadall - loaded - save"
					lappend outputList "addexempt - delexempt"
                                }
                                lappend outputList "patterns - view - search"
                                lappend outputList "Use 'badword help command' for help on each of these."
                                return $outputList
                        }
                        patterns {
                                lappend outputList "SYNTAX: badword patterns"
                                lappend outputList "USE: Shows a list of all currently loaded badwords."
                                return $outputList
                        }
			view {
				lappend outputList "SYNTAX: badword view <pattern> (<file>)"
				lappend outputList "USE: Shows information about <pattern> in <file>."
				lappend outputList "<file> is optional, if omitted the search is done in the currently loaded memory."
				return $outputList
			}
                        search {
                                lappend outputList "SYNTAX: badword search <pattern>"
                                lappend outputList "USE: Searches if <pattern> is currently a loaded badword."
				lappend outputList "<pattern> can contain wildcards."
                                return $outputList
                        }
                }	
        }
        return [lappend outputList "No help available on that."]
}
proc bw_showStats {args} {
# Return stats
	return "bw_showstats"
}

proc lowAccess {handle} {
	global bw_chans bw_highAccessFlags bw_lowAccessFlags
	set found 0
	foreach chan $bw_chans {
		if {[matchattr $handle $bw_highAccessFlags $chan] || [matchattr $handle $bw_lowAccessFlags $chan]} {
			set found 1
		}
	}
	return $found
}

proc highAccess {handle} {
	global bw_chans bw_highAccessFlags
	set found 0
	foreach chan $bw_chans {
		if {[matchattr $handle $bw_highAccessFlags $chan]} {
			set found 1
		}
	}
	return $found
}

proc expandWordList {file} {
# Load extra file 
	global bw_badwords bw_lists bw_dbPath
	set fqFile "$bw_dbPath$file"

	if {[lsearch -exact $bw_lists $file]>-1} { return "File already loaded" }
	set temp [checkFile $fqFile]
	if { $temp != 1 } { return $temp }

	# list with arraynames
	set bw_wordlist [readFile "$fqFile"]
	set tempList [createBWArrays $bw_wordlist $file]
	set bw_badwords [concat $bw_badwords $tempList]
	lappend bw_lists $file
	return "Loaded file $file"
}

proc createBWArrays {unmodlist file} {
# Creates the arrays, returns a list of array names
	global bw_badwords bw_delimiter

	# list to be returned
	set arrayNamesList ""
	# Set first number for new patterns
	set crrntNr 0
	if {[llength $bw_badwords]} {
		set crrntNr [expr [lindex [split [lindex $bw_badwords end] ","] 1] + 1]
	}
	foreach rawUnmod $unmodlist {
		set badwordunmod [split $rawUnmod $bw_delimiter]
		global badword,${crrntNr}
		set badword,${crrntNr}(pattern) [lindex $badwordunmod 0]
		set badword,${crrntNr}(type) [lindex $badwordunmod 1]
		set badword,${crrntNr}(bantime) [lindex $badwordunmod 2]
		set badword,${crrntNr}(reason) [lindex $badwordunmod 3]
		set badword,${crrntNr}(exempts) [lindex $badwordunmod 4]
		set badword,${crrntNr}(file) $file
		# add it to the list
		set arrayNamesList [lappend arrayNamesList badword,$crrntNr]
		incr crrntNr
	}
	return $arrayNamesList
}

proc readFile {filename} {
# Read file to list, each line is a list element (strings)
	set lines {}
	set FH [open $filename r]
	set g [gets $FH]
	while {![eof $FH]} {
		lappend lines $g
		set g [gets $FH]
	}
	close $FH
	return $lines
}

proc writeFile {filename inputList} {
# Write list to file, each element on a seperate line
# Overwrites the original file
	set FH [open $filename w]
	foreach elem $inputList {
		puts $FH $elem
	}
	close $FH
}

proc appendFile {filename inputList} {       
# Append lines to a file, each list element on a seperate line
	set FH [open $filename a+]        
	foreach elem $inputList {
		puts $FH $elem
	}
	close $FH
}

proc checkFile {filename} {
# Checks if file is accessible
	if {![file exists $filename]} { return "File does not exist." }
	if {![file readable $filename]} { return "File unreadable." }
	if {![file isfile $filename]} { return "File is not a normal file." }
	return 1
}

proc stripControlCodes {str} {
# Remove all control codes from a string
# Color: \003; Underline: \037; Bold: \002; Reverse: \026; Plain: \017 
	set res $str
	regsub -all -- {\003(\d){0,2}(,){0,1}(\d){0,2}} $res {} res
	regsub -all -- {\037} $res {} res
	regsub -all -- {\002} $res {} res
	regsub -all -- {\026} $res {} res
	regsub -all -- {\017} $res {} res
	return $res
}

proc checkChans {} {
	global bw_chans
	set errorChans {}
	foreach chan $bw_chans {
		if {[lsearch [channels] $chan] <0} {
			set bw_chans [lreplace $bw_chans [lsearch $bw_chans $chan] [lsearch $bw_chans $chan]]
			set errorChans [lappend errorChans $chan]
		}
	}
	if {[llength $errorChans]} {
		putlog "ABW: These ABW-channels were removed because I don't monitor them: $errorChans"
	}
}
		
#################################################################
# Field delimiter in BW files
set bw_delimiter "|" 	

# Flags used for type-check (for Inputcontrol)
set bw_types "wnb"

# Initialisation
set bw_badwords {}
set bw_lists {}
foreach list $bw_initLists {
	expandWordList $list
}
unset bw_initLists
#the delay is to give the bot the chance to join the monitor-channels.
utimer 10 checkChans
putlog "Advanced bad word script v2.0 (By Demian and Sprudl) loaded."

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us