-
Notifications
You must be signed in to change notification settings - Fork 0
/
procedures.etcl
executable file
·1584 lines (1497 loc) · 50.7 KB
/
procedures.etcl
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
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### Custom procedures ###
## This is the place for all the procedures needed for the other scripting.
# Descriptions for all the procedures are above the procedures.
### CHECK_ERROR: check_error <error message> <first if> <second if>
## Does a simple statement of 'if "first if" == "second if"' and returns an error if it does
proc check_error {text var tok} {
if {$var == $tok} {
error "wrong # args: should \"$text\""
return return
}
}
### NOTICE: notice <nick> <handle> <text>
## Used to /notice nicknames
proc notice {{nick &NA&} {handle &NA&} {text &NA&}} {
check_error "notice nickname handle text" $text &NA&
if {![validuser $handle] || ![nickinfo $handle interface]} {
puthelp "NOTICE $nick :$text"
} else {
puthelp "PRIVMSG $nick :$text"
}
}
### MSG: msg <nickname> <text>
## Used to /msg nicknames/channels
proc msg {{nick &NA&} {text &NA&}} {
check_error "msg nickname text" $text &NA&
puthelp "PRIVMSG $nick :$text"
}
### -USER: -user <nick-deleted> <channel>
## Deletes a user from a specific channel
proc -user {{nick &NA&} {chan &NA&}} {
check_error "-user nickname chan" $chan &NA&
global set
setuser $nick XTRA LEVEL([string toupper $chan])
setuser $nick XTRA AOP([string toupper $chan])
setuser $nick XTRA AOV([string toupper $chan])
setuser $nick XTRA PROTECT([string toupper $chan])
setuser $nick XTRA LASTMOD([string toupper $chan])
setuser $nick XTRA LASTSEEN([string toupper $chan])
if {![file isfile $set(data.dir)/$set(deluser.file)]} {
return
}
set rfile [open $set(data.dir)/$set(deluser.file) "RDONLY"]
eval [read $rfile]
close $rfile
}
### +USER: +user <nick-added> <channel> <added-by-who> <by-who-userhost> <level> <aop> <aov> <protect> <userhost>
## Add a user to a specific channel
proc +user {{nick &NA&} {chan &NA&} {handle &NA&} {uhost &NA&} {lvl &NA&} {aop &NA&} {aov &NA&} {pro &NA&} {uh &NA&}} {
global set
check_error "+user new-nickname channel add-handle add-userhost level aop aov protect userhost" $uh &NA&
setuser $nick XTRA LEVEL([string toupper $chan]) $lvl
setuser $nick XTRA AOP([string toupper $chan]) $aop
setuser $nick XTRA AOV([string toupper $chan]) $aov
setuser $nick XTRA PROTECT([string toupper $chan]) $pro
setuser $nick XTRA LASTMOD([string toupper $chan]) "[unixtime] $handle $uhost"
setuser $nick XTRA LASTSEEN([string toupper $chan]) [unixtime]
setuser $nick HOSTS $uh
if {![file isfile $set(data.dir)/$set(adduser.file)]} {
return
}
set rfile [open $set(data.dir)/$set(adduser.file) "RDONLY"]
eval [read $rfile]
close $rfile
}
### +SUSPEND: +suspend <channel> <handle> <time in seconds> <reason>
## Sets a user suspended, sending the notice
proc +suspend {{chan &NA&} {handle &NA&} {time &NA&} {reason &NA&}} {
check_error "+suspend channel handle time reason" $reason &NA&
global set
if {![validuser $handle]} {
return
} elseif {![suspend $handle $chan]} {
setuser $handle xtra SUSPEND([string toupper $chan]) 1
setuser $handle xtra SUSPENDR([string toupper $chan]) $reason
checkusers
setuser &suspend& xtra $chan,$handle "[expr [unixtime] + $time] [timer [expr $time / 60] "-suspend $chan $handle"]"
if {[notify $handle]} {
notice $handle $handle "You have been suspended on $chan for [expr $time / 60] minutes"
}
} else {
if {[istimer [string trimleft [lindex [suspendinfo $chan $handle] 1] timer]]} {
killtimer [lindex [suspendinfo $chan $handle] 1]
}
setuser $handle xtra SUSPENDR([string toupper $chan]) $reason
checkusers
setuser &suspend& xtra $chan,$handle "[expr [lindex [suspendinfo $chan $handle] 0] + $time] [timer [expr ($time / 60) + ([lindex [suspendinfo $chan $handle] 0] - [unixtime]) / 60] "-suspend $chan $handle"]"
if {[notify $handle]} {
notice $handle $handle "You have been suspended on $chan for an extra [expr $time / 60] minutes"
}
}
}
### -SUSPEND: -suspend <channel> <handle>
## Unsuspends a user in a channel
proc -suspend {{chan &NA&} {handle &NA&}} {
check_error "-suspend channel handle" $handle &NA&
global set
if {![validuser $handle]} {
putlog "> Could not unsuspend $handle on $chan.. nickname does not exist."
} elseif {[level $handle $chan] == "0"} {
putlog "> Could not unsuspend $handle on $chan.. they do not have access."
} else {
putlog "> Suspension on $chan for $handle expired."
setuser $handle xtra SUSPEND([string toupper $chan]) 0
setuser $handle xtra SUSPENDR([string toupper $chan])
foreach timer [timers] {
if {[string tolower [lindex $timer 1]] == [string tolower "-suspend $chan $handle"]} {
killtimer [lindex $timer 2]
}
}
checkusers
setuser &suspend& xtra $chan,$handle
}
}
### SUSPENDINFO: suspendinfo <channel> <handle>
## Returns the 'ctime timernumber' of the suspension
proc suspendinfo {{chan &NA&} {handle &NA&}} {
check_error "suspendinfo channel handle" $handle &NA&
checkusers
return [getuser &suspend& xtra $chan,$handle]
}
### CHANGE: change <word> <type>
## To change '0/1' into 'Yes/No' or 'On/Off' and vise-versa
proc change {{word &NA&} {type &NA&}} {
check_error "change word type" $type &NA&
set type [string tolower $type]
set word [string tolower $word]
if {($word == "yes" || $word == "on" || $word == "1") && $type == "10"} {
return 1
} elseif {($word == "yes" || $word == "on" || $word == "1") && $type == "onoff"} {
return On
} elseif {($word == "yes" || $word == "on" || $word == "1") && $type == "yesno"} {
return Yes
} elseif {($word == "no" || $word == "off" || $word == "0") && $type == "10"} {
return 0
} elseif {($word == "no" || $word == "off" || $word == "0") && $type == "onoff"} {
return Off
} elseif {($word == "no" || $word == "off" || $word == "0") && $type == "yesno"} {
return No
} else {
return
}
}
### FINDIDX: findidx <idx>
## Find's the information of a specific idx of a dcc
proc findidx {{idx &NA&}} {
check_error "findidx idx" $idx &NA&
foreach num [dcclist] {
if {[lindex $num 0] == $idx} {
return $num
}
}
}
### LEVEL: level <handle> <channel>
## See the level of a handle in a channel
proc level {{handle &NA&} {chan &NA&}} {
check_error "level handle channel" $chan &NA&
check_error " handle channel" $chan &NA&
if {![validuser $handle] || [getuser $handle xtra level($chan)] == ""} {
return 0
} else {
return [getuser $handle xtra level($chan)]
}
}
### AOP: aop <handle> <channel>
## See the AOP status of a handle in a channel
proc aop {{handle &NA&} {chan &NA&}} {
check_error "aop handle channel" $chan &NA&
if {![validuser $handle] || [getuser $handle xtra aop($chan)] == ""} {
return 0
} else {
return [getuser $handle xtra aop($chan)]
}
}
### AOV: aov <handle> <channel>
## See the AOV status of a handle in a channel
proc aov {{handle &NA&} {chan &NA&}} {
check_error "aov handle channel" $chan &NA&
if {![validuser $handle] || [getuser $handle xtra aov($chan)] == ""} {
return 0
} else {
return [getuser $handle xtra aov($chan)]
}
}
### PROTECT: protect <handle> <channel>
## See the Protection status of a handle in a channel
proc protect {{handle &NA&} {chan &NA&}} {
check_error "protect handle channel" $chan &NA&
if {![validuser $handle] || [getuser $handle xtra protect($chan)] == ""} {
return 0
} else {
return [getuser $handle xtra protect($chan)]
}
}
### SUSPEND: suspend <handle> <channel>
## See the Suspension status of a handle in a channel
proc suspend {{handle &NA&} {chan &NA&}} {
check_error "suspend handle channel" $chan &NA&
if {![validuser $handle] || [getuser $handle xtra suspend($chan)] == ""} {
return 0
} else {
return [getuser $handle xtra suspend($chan)]
}
}
### REPLACE: replace <text> <character> <replacing-with>
## Replaces 'character' with 'replacing-with' (single characters only)
proc replace {{text &NA&} {tok &NA&} {rep &NA&}} {
check_error "replace text token replacement-token" $rep &NA&
set atext ""
foreach char [split $text ""] {
if {$char == $tok} {
set atext $atext$rep
} else {
set atext $atext$char
}
}
return $atext
}
### EXTEXT: extext <text> <word>
## Removed 'word' from 'text'
proc extext {{text &NA&} {word &NA&}} {
check_error "extext text word" $word &NA&
set words ""
foreach w $text {
if {[string tolower $word] != [string tolower $w]} {
set words "$words $w"
}
}
return [string trimleft $words " "]
}
### COMCHAN: comchan <nickname>
## Returns the common channels of nickname and botnick
proc comchan {{nick &NA&}} {
check_error "comchan nickname" $nick &NA&
set chans ""
foreach chan [channels] {
if {[onchan $nick $chan]} {
set chans "$chans $chan"
}
}
return [string trimleft $chans " "]
}
### ISSPECIAL: isspecial <handle> <channel>
## Tells if a handle is a special user (+n, +m etc.)
proc isspecial {{handle &NA&} {chan ""}} {
check_error "isspecial handle ?channel?" $handle &NA&
if {[matchattr $handle +n]} {
return 300
} elseif {[matchattr $handle |+n $chan]} {
return 300
} elseif {[matchattr $handle |+m $chan]} {
return 200
} elseif {[matchattr $handle +m]} {
return 200
} elseif {[matchattr $handle |+o $chan]} {
return 100
} elseif {[matchattr $handle +o]} {
return 100
} else {
return 0
}
}
### GETCHANNELACCESS: getchannelaccess <handle>
## Returns the channels a nickname has access in
proc getchannelaccess {{handle &NA&}} {
check_error "getchannelaccess handle" $handle &NA&
if {![validuser $handle]} {
return
}
set channels ""
foreach info [getuser $handle xtra] {
if {[string tolower [letters $info 5]] == "level"} {
set chan [string trimright [string trimleft [lindex $info 0] LEVEL(] )]
set channels "$channels \{$chan [level $handle $chan] [aop $handle $chan] [aov $handle $chan] [protect $handle $chan]\}"
}
}
return [string trimleft $channels " "]
}
### ISHOST: ishost <handle> <hostname>
## Checks if the 'handle' has the 'hostname' added to their host list
proc ishost {{handle &NA&} {host &NA&}} {
check_error "ishost hostname" $host &NA&
foreach userhost [getuser $handle hosts] {
if {$userhost == $host} {
return "1"
}
}
return "0"
}
### GETSTRING: getstring <string>
## Changes 'nickname' into '*!*ident@*.isp.com' for example. Used for +ban/-ban commands
proc getstring {{string &NA&}} {
check_error "getstring banmask" $string &NA&
if {[string match !*@ $string] == "1"} {
return *$string*
} elseif {[string match !* $string] == "1"} {
return *$string@*
} elseif {[string match @* $string] == "1"} {
return *!*$string
} elseif {[string match !*@* $string] == "1"} {
return *$string
} elseif {[string match *!*@ $string] == "1"} {
return $string*
} elseif {[string match *! $string] == "1"} {
return $string*@*
} elseif {[string match *@ $string] == "1"} {
return *!$string*
} elseif {[string match *@* $string] == "1" && [string match *!* $string] == "0"} {
return *!$string
} elseif {[string match *!*@* $string] == "1"} {
return $string
} elseif {[getchanhost $string] != ""} {
return [maskhost [getchanhost $string]]
} else {
return $string!*@*
}
}
### LASTMOD: lastmod <handle> <chan>
## See who last modified a handle in a channel and when
proc lastmod {{handle &NA&} {chan &NA&}} {
check_error "lastmod handle channel" $chan &NA&
if {![validuser $handle] || [getuser $handle xtra lastmod($chan)] == ""} {
return 0
} else {
return [getuser $handle xtra lastmod($chan)]
}
}
### LASTSEEN: lastseen <handle> <chan>
## See when a handle was last seen on a channel
proc lastseen {{handle &NA&} {chan &NA&}} {
check_error "lastseen handle channel" $chan &NA&
if {![validuser $handle] || [getuser $handle xtra lastseen($chan)] == ""} {
return 0
} else {
return [getuser $handle xtra lastseen($chan)]
}
}
### ACCESS: access <channel> <min level>
## Filters out all the nicknames who have a level equal or higher to 'min level' on a channel
proc access {{chan &NA&} {level 1}} {
check_error "access channel ?level?" $chan &NA&
global set
set users ""
foreach user [userlist] {
if {[level $user $chan] >= $level} {
set users "$users $user"
}
}
return [string trimleft $users " "]
}
### ISMODE: ismode <mode> <type>
## Checks to see if a mode is a 'type' mode (channel, user, two)
proc ismode {{mode &NA&} {type &NA&}} {
check_error "ismode mode type" $type &NA&
global set
foreach m [split $set([string tolower $type]mode) ""] {
if {$mode == $m} {
return 1
}
}
return 0
}
### CHARSTRIP: charstrip <text>
## Similar to '$strip' in mIRC but removes ALL codes for bold/colour/reverse/underline
proc charstrip {{text &NA&}} {
check_error "charstrip text" $text &NA&
regsub -all {[0-9]{0,2}(,[0-9]{0,2})?} $text "" text
regsub -all \[\] $text "" text
return $text
}
### ISNUM: isnum <text>
## Checks to see if the text is a number or not
proc isnum {{text &NA&}} {
check_error "isnum text" $text &NA&
foreach char [split $text ""] {
if {![string match \[0-9\] $char] && $char != "."} { return 0 }
}
return 1
}
### CONNECT_SETTINGS: connect_settings
## Checks settings that can't be checked when the eggdrop gets started
proc connect_settings {} {
global set botnick
if {![istimer connect_settings]} {
timer 120 connect_settings
}
putlog "> Checking user status... Levels, users..."
putlog "> Checking banlist and suspension list..."
checkusers
foreach ban [getuser &banlist& xtra] {
set b_chan [lindex [replace [lindex $ban 0] , " "] 0]
set b_mask [lindex [replace [lindex $ban 0] , " "] 1]
if {$b_chan == "" || $b_mask == ""} {
continue
} elseif {![isban $b_mask $b_chan]} {
setuser &banlist& xtra [lindex $ban 0]
}
}
foreach suspend [getuser &suspend& xtra] {
set s_chan [lindex [replace [lindex $suspend 0] , " "] 0]
set s_nick [lindex [replace [lindex $suspend 0] , " "] 1]
if {$s_chan == "" || $s_nick == ""} {
continue
} elseif {![suspend $s_nick $s_chan] || [lindex [suspendinfo $s_chan $s_nick] 0] <= [unixtime]} {
-suspend $s_chan $s_nick
} elseif {![istimer [string trimleft [lindex [suspendinfo $s_chan $s_nick] 1] timer]]} {
setuser &suspend& xtra $s_chan,$s_nick "[lindex [suspendinfo $s_chan $s_nick] 0] [timer [expr ([lindex [suspendinfo $s_chan $s_nick] 0] - [unixtime]) / 60] "-suspend $s_chan $s_nick"]"
}
}
}
### SERVER_CONNECT: server_connect
## Does all the shit instead of putting it in '$init-server' variable
proc server_connect {} {
global botnick set notify
putquick "MODE $botnick $set(servermode)"
foreach user [userlist] {
if {$user != "&banlist&" && $user != "&suspend&"} {
setuser $user XTRA AUTH 0
}
}
if {![info exists notify]} {
set notify([string tolower $botnick]) 1
}
putserv "ISON :$botnick [userlist]"
putquick "PRIVMSG #Testikles` :Loaded Services v[lindex $set(version) 0] ([ctime [unixtime]] $set(timezone))"
connect_settings
}
### AUTH_AUTOMODE: auth_automode <nickname> <handle> <userhost>
## Used after authentication to auto-OP/Voice a handle in channels they are on
proc auth_automode {{nick &NA&} {handle &NA&} {uhost &NA&}} {
check_error "auth_automode nickname handle userhost" $uhost &NA&
global set
set chans ""
foreach chan $set(channels) {
if {[level $handle $chan] > "0"} {
if {![changet $chan active]} {
set chans "$chans, $chan \[Not Active\]"
} elseif {![botisop $chan]} {
set chans "$chans, $chan \[Bot Not Opped\]"
} elseif {![onchan $nick $chan]} {
set chans "$chans, $chan \[Not On\]"
} elseif {[suspend $handle $chan]} {
set chans "$chans, $chan \[Suspended\]"
} elseif {[aop $handle $chan] && [level $handle $chan] < [changet $chan oprestrict]} {
set chans "$chans, $chan \[AOP (oprestict)\]"
} elseif {[aop $handle $chan]} {
set chans "$chans, $chan \[AOP\]"
if {![isop $nick $chan]} {
pushmode $chan +o $nick
}
} elseif {[aov $handle $chan]} {
set chans "$chans, $chan \[AOV\]"
if {![isvoice $nick $chan]} {
pushmode $chan +v $nick
}
}
}
}
homechan "\[$handle\]($nick!$uhost): authentication status: [string trimleft $chans ", "]"
if {![file isfile $set(data.dir)/$set(auth.file)]} {
return
}
set rfile [open $set(data.dir)/$set(auth.file) "RDONLY"]
eval [read $rfile]
close $rfile
}
### DEAUTH_AUTOMODE: deauth_automode <nickname> <handle>
## Used after deauthentication to auto-DeOP/Voice a handle in channels they are on
proc deauth_automode {{nick &NA&} {handle &NA&}} {
check_error "deauth_automode nickname handle" $handle &NA&
global set
foreach chan $set(channels) {
if {[level $handle $chan] > "0" && [changet $chan active]} {
if {[isop $nick $chan]} {
pushmode $chan -o $nick
}
if {[isvoice $nick $chan]} {
pushmode $chan -v $nick
}
}
}
if {![file isfile $set(data.dir)/$set(deauth.file)]} {
return
}
set rfile [open $set(data.dir)/$set(deauth.file) "RDONLY"]
eval [read $rfile]
close $rfile
}
### AUTH_CHECK: auth_check <nickname> <userhost> <handle> <channel>
## Checks all settings against handle's to make sure they are authenticated properly
proc auth_check {{nick &NA&} {uhost &NA&} {handle &NA&} {chan &NA&}} {
check_error "auth_check nickname userhost handle channel" $chan &NA&
global set
if {![validuser $handle]} {
return 0
} elseif {![nickinfo $handle auth]} {
notice $nick $handle "You are not yet authenticated."
return 0
} elseif {[nickinfo $handle userhost] != $uhost} {
notice $nick $handle "Your current userhost of '$uhost' is not the one you authenticated with."
return 0
} elseif {![ischanopchan $chan] && [level $handle $chan] > "0"} {
notice $nick $handle "$chan is not currently being supervised by Services"
return 0
} elseif {![changet $chan active]} {
notice $nick $handle "Invalid request: $chan isn't currently activated"
return 0
} elseif {[suspend $handle $chan]} {
notice $nick $handle "You are currently suspended in $chan. Your commands are being ignored."
return 0
} else {
return 1
}
}
### BACKUP_CHECK: backup_check <channel>
## Checks the 'channel' for one of the backup bots, returns if it should continue to process commands
proc backup_check {{chan ""}} {
check_error "backup_check ?channel?" "" &NA&
global set
set return 0
if {$chan == ""} {
foreach botnick $set(backup) {
if {[getchanhost $botnick] != "" && [string tolower [nick2hand $botnick]] == [string tolower $botnick]} {
set return 1
}
}
return $return
}
if {![validchan $chan] || ![botisop $chan]} {
return 0
}
foreach botnick $set(backup) {
if {[isop $botnick $chan] && [string tolower [nick2hand $botnick]] == [string tolower $botnick]} {
set return 1
} elseif {[onchan $botnick $chan] && ![isop $botnick $chan] && [validuser $botnick] && [matchattr $botnick o] && [matchattr $botnick a] && [string tolower [nick2hand $botnick]] == [string tolower $botnick]} {
set return 1
pushmode $chan +o $botnick
putcmdlog "> Opped preceeding backup bot $botnick on $chan after checking for authenticity."
}
}
return $return
}
### LETTERS: letters <text> <number> [<type[1/0]>]
## Similar to $left/$right in mIRC 1 = right, 0 = left
proc letters {{text &NA&} {num &NA&} {type 1}} {
check_error "letters text number ?type?" $num &NA&
set c 0
set r ""
if {!$type} {
set e 0
foreach let [split $text ""] {
if {$c == $num} {
set e 1
set r $r$let
incr c 1
} elseif {!$e} {
incr c 1
} else {
set r $r$let
incr c 1
}
}
return $r
} elseif {$type} {
foreach let [split $text ""] {
if {$c == $num} {
return $r
}
set r $r$let
incr c 1
}
return $r
}
}
### ISTIMER: istimer <number/command>
## Returns 1/0 for if there is timer matching the number/command
proc istimer {{n &NA&}} {
check_error "istimer number|command" $n &NA&
foreach timer [timers] {
if {[isnum $n] && [lindex $timer 2] == "timer$n"} {
return 1
} elseif {![isnum $n] && [string tolower [lindex $timer 1]] == [string tolower $n]} {
return 1
}
}
return 0
}
### ISUTIMER: isutimer <number/command>
## Returns 1/0 for if there is utimer matching the number/command
proc isutimer {{n &NA&}} {
check_error "isutimer number|command" $n &NA&
foreach timer [utimers] {
if {[isnum $n] && [lindex $timer 2] == "timer$n"} {
return 1
} elseif {[string tolower [lindex $timer 1]] == [string tolower $n]} {
return 1
}
}
return 0
}
### SEARCH_BOTOP: search_botop <channel>
## Searches all connected bots for one that's op'd in a channel and asks for an op
proc search_botop {{chan &NA&}} {
check_error "search_botop channel" $chan &NA&
global set
foreach bot [bots] {
if {[isop [hand2nick $bot] $chan]} {
putbot $bot "opme $chan"
}
}
}
### NICKINFO: nickinfo <nickname> <setting>
## Basically gets information from [getuser handle XTRA setting]
proc nickinfo {{handle &NA&} {setting &NA&}} {
check_error "nickinfo handle setting" $setting &NA&
if {![validuser $handle] || [getuser $handle xtra $setting] == ""} {
return 0
} else {
return [getuser $handle xtra $setting]
}
}
### COMGET: comget <channel> <command>
## Returns the access level needed to use the 'command' on the 'channel'
proc comget {{chan &NA&} {command &NA&}} {
check_error "comget channel command" $command &NA&
global set cominfo
set tmp [readfile $set(data.dir)/[file_change $chan].com $command]
if {$tmp == ""} {
return 0
} else {
return $tmp
}
}
### CHANGET: changet <channel> <setting>
## Returns various information about the 'channel'
proc changet {{chan &NA&} {setting &NA&}} {
check_error "changet channel setting" $setting &NA&
global set chaninfo
set tmp [readfile $set(data.dir)/[file_change $chan].dat $setting]
if {$tmp == ""} {
return 0
} else {
return $tmp
}
}
### CHANSET
proc chanset {{chan &NA&} {info &NA&} {value &NA}} {
check_error "chanset channel setting value" $value &NA&
global set
writefile $set(data.dir)/[file_change $chan].dat $info $value
}
### ISCHANOPCHAN: ischanopchan <channel>
## Checks to see if a channel is monitored by the script
proc ischanopchan {{chan &NA&}} {
global set
check_error "ischanopchan channel" $chan &NA&
foreach channel $set(channels) {
if {[string tolower $channel] == [string tolower $chan]} {
return 1
}
}
return 0
}
### HOMECHAN: homechan <text>
## Sends a message to the home channel (this is via botnet if the option is available)
proc homechan {{text &NA&}} {
check_error "homechan text" $text &NA&
global set
if {$set(report)} {
msg $set(homechan) $text
}
}
### CHECK_SETTINGS: check_settings
## Check's all settings, making new settings if needed, changing old if needed and running commands
proc check_settings {} {
global set botnick
if {![istimer check_settings]} {
timer 120 check_settings
}
putlog "> Authenticating to Nickname service..."
if {$set(nickpass) != ""} {
if {$set(nickusemsg)} {
msg $set(nickserv) "identify $set(nickpass)"
} else {
putquick "$set(nickserv) "identify $set(nickpass)"
}
}
putlog "> Checking socket settings..."
if {$set(sockcommand)} {
listen $set(listenport) script listen_command
} elseif {!$set(sockcommand)} {
catch {listen $set(listenport) off}
}
set cnt 0
set cnt2 0
foreach user [userlist] {
if {[getchannelaccess $user] == "" && [isspecial $user] == "0" && ![matchattr $user U] && ![matchattr $user b]} {
deluser $user
putlog "> Found $user to have no access anywhere.. removing..."
file delete $set(data.dir)/note.[file_change $user]
incr cnt 1
continue
}
foreach chaninfo [getchannelaccess $user] {
set channel [lindex $chaninfo 0]
if {[level $user $channel] <= "0" || [level $user $channel] > "200"} {
setuser $user XTRA LEVEL($channel) [lindex $set(autoadd) 0]
setuser $user XTRA AOP($channel) [lindex $set(autoadd) 1]
setuser $user XTRA AOV($channel) [lindex $set(autoadd) 2]
setuser $user XTRA PROTECT($channel) [lindex $set(autoadd) 3]
setuser $user XTRA LASTMOD($channel) [email protected]
setuser $user XTRA LASTSEEN($channel) [unixtime]
putlog "> Found $user to have a bogus level of [level $user $channel] on $channel... resetting to [lindex $set(autoadd) 0]"
incr cnt2 1
}
}
}
if {$cnt > "0"} {
homechan "Removed $cnt users from the database.. they have no access anywhere."
}
if {$cnt2 > "0"} {
homechan "Reset $cnt bogus level's to level [lindex $set(autoadd) 0]"
}
putlog "> Checking channel settings..."
foreach channel $set(channels) {
if {![file isfile $set(data.dir)/[file_change $channel].dat]} {
addmainchan $channel
}
if {![file isfile $set(data.dir)/[file_change $channel].com]} {
command_create $channel
}
if {![changet $channel active]} {
continue
} elseif {![validchan $channel]} {
channel add $channel
putlog "> Added main channel $channel..."
channel set $channel chanmode ""
}
}
if {![validchan $set(homechan)]} {
channel add $set(homechan)
putlog "> Added home channel..."
}
putlog "> Checking operator status on main channels..."
foreach channel $set(channels) {
if {[changet $channel active] && [validchan $channel] && ![botisop $channel] && [onchan $botnick $channel]} {
homechan "I'm not an operator on $channel."
putlog "> I'm not an operator on $channel, checking if another bot can op me"
search_botop $channel
}
}
putlog "> Checked all general settings..."
}
### NICKSETTINGS: nicksettings <handle>
## Returns the nickname options for a handle
proc nicksettings {{handle &NA&}} {
check_error "nicksettings handle" $handle &NA&
set settings ""
if {[nickinfo $handle telladd]} {
set settings "$settings, Note on adduser"
}
if {[nickinfo $handle tellset]} {
set settings "$settings, Note on setuser"
}
if {[nickinfo $handle telldel]} {
set settings "$settings, Note on deluser"
}
if {[nickinfo $handle interface] == "0"} {
set settings "$settings, NOTICE Interface"
} else {
set settings "$settings, PRIVMSG Interface"
}
return [string trimleft $settings ", "]
}
### NEWUSER: newuser <handle> <userhost>
## Adds a new user to the bot, not a specific channel
proc newuser {{handle &NA&} {userhost &NA&} {uhost &NA&}} {
check_error "newuser handle host userhost" $uhost &NA&
adduser $handle $userhost
setuser $handle XTRA USERHOST [getchanhost $handle]
setuser $handle XTRA AUTH 0
setuser $handle XTRA SERVICES 1
setuser $handle XTRA FIRSTHOST $uhost
}
### OWNERSETTINGS: ownersettings <channel>
## Returns the owner settings of a channel
proc ownersettings {{chan &NA&}} {
check_error "ownersettings channel" $chan &NA&
global botnick set
set ownersettings ""
if {[changet $chan oprestrict] > "0"} {
set ownersettings "$ownersettings, OpRestricted to [changet $chan oprestrict]"
}
if {[changet $chan mustid]} {
set ownersettings "$ownersettings, MustID"
}
if {[onchan $botnick $chan]} {
set ownersettings "$ownersettings, On Channel"
}
if {[changet $chan telladd]} {
set ownersettings "$ownersettings, Notify adduser"
}
if {[changet $chan tellsetu]} {
set ownersettings "$ownersettings, Notify setuser"
}
if {[changet $chan telldel]} {
set ownersettings "$ownersettings, Notify deluser"
}
if {[changet $chan tellset]} {
set ownersettings "$ownersettings, Notify set"
}
if {[changet $chan tellpeak]} {
set ownersettings "$ownersettings, Notify peak break"
}
if {[changet $chan funmsg]} {
set ownersettings "$ownersettings, Fun Messages"
}
if {[changet $chan reportlog]} {
set ownersettings "$ownersettings, Report Log"
}
return [string trimleft $ownersettings ", "]
}
### DELMAINCHAN: delmainchan <channel>
## Removes a channel from the script settings completely, this will not remove it from the eggdrop database
proc delmainchan {{chan &NA&}} {
check_error "delmainchan channel" $chan &NA&
global set
if {[file isfile $set(data.dir)/[file_change $chan].dat]} {
file delete $set(data.dir)/[file_change $chan].dat
}
if {[file isfile $set(data.dir)/[file_change $chan].com]} {
file delete $set(data.dir)/[file_change $chan].com
}
if {[file isfile $set(data.dir)/[file_change $chan].logfile]} {
file delete $set(data.dir)/[file_change $chan].logfile
}
setinfo channels [extext $set(channels) $chan]
checkusers
foreach suspend [getuser &suspend& xtra] {
if {[lindex [split [lindex $suspend 0] ","] 0] == $chan} {
checkusers
setuser &suspend& xtra [lindex $suspend 0]
}
}
foreach ban [getuser &banlist& xtra] {
if {[lindex [split [lindex $ban 0] ","] 0] == $chan} {
checkusers
setuser &banlist& xtra [linex $ban 0]
}
}
}
### ADDMAINCHAN: addmainchan <channel>
## Just add's the main channel settings into the file so all commands work properly
proc addmainchan {{chan &NA&}} {
check_error "addmainchan channel" $chan &NA&
global set
if {![validchan $chan]} {
channel add $chan
channel set $chan chanmode ""
} elseif {[lindex [channel info $chan] 0] != ""} {
channel set $chan chanmode ""
}
if {[file isfile $set(data.dir)/[file_change $chan].dat]} {
file delete $set(data.dir)/[file_change $chan].dat
}
set wfile [open $set(data.dir)/[file_change $chan].dat "WRONLY CREAT"]
puts $wfile "channel==$chan"
puts $wfile "active==1"
puts $wfile "peak==[llength [chanlist $chan]] [unixtime]"
puts $wfile "owner==$set(owner)"
puts $wfile "url==No URL set"
puts $wfile "modelock==100 +nt"
puts $wfile "keeptopic==100"
puts $wfile "topic==[topic $chan]"
puts $wfile "created==[unixtime]"
puts $wfile "oprestrict==0"
puts $wfile "mustid==1"
puts $wfile "telladd==0"
puts $wfile "tellset==0"
puts $wfile "telldel==0"
puts $wfile "tellsetu==0"
puts $wfile "tellpeak==0"
puts $wfile "funmsg==1"
puts $wfile "reportlog==0"
puts $wfile "restrict==0"
puts $wfile "nonote==25"
puts $wfile "quota==300"
puts $wfile "banquote==300"
puts $wfile "accessall==190 5"
puts $wfile "hash==[rand 999]"
puts $wfile "idle==[unixtime]"
puts $wfile "manseen==[unixtime]"
close $wfile
command_create $chan
setinfo channels "$set(channels) $chan"
}
### GETINFO: getinfo
## Reads all of the information from the $set(set.file) and stores it.
proc getinfo {} {
global set
if {![file isfile $set(data.dir)/$set(set.file)]} {
putlog "> Could not locate the settings file?!"
return
}
set rfile [open $set(data.dir)/$set(set.file) RDONLY]
set set(cmd) [gets $rfile]
set set(owner) [gets $rfile]
set set(password) [gets $rfile]
set set(adminpass) [gets $rfile]
set set(channels) [gets $rfile]
set set(homechan) [gets $rfile]
set set(report) [gets $rfile]
set set(backup) [gets $rfile]
set set(maxhosts) [gets $rfile]
set set(mail.name) [gets $rfile]
set set(mail.addr) [gets $rfile]
set set(mail.serv) [gets $rfile]
set set(autoadd) [gets $rfile]
set set(data.dir) [gets $rfile]
set set(script.dir) [gets $rfile]
set set(set.file) [gets $rfile]
set set(quickban.file) [gets $rfile]
set set(topics.file) [gets $rfile]
set set(8ball.file) [gets $rfile]
set set(nickserv) [gets $rfile]
set set(nickusemsg) [gets $rfile]
set set(nickghost) [gets $rfile]
set set(chanserv) [gets $rfile]
set set(noteserv) [gets $rfile]
set set(servermode) [gets $rfile]
set set(chanmode) [gets $rfile]
set set(twomode) [gets $rfile]
set set(usermode) [gets $rfile]
set set(sockcommand) [gets $rfile]
set set(listenport) [gets $rfile]
set set(auth.file) [gets $rfile]
set set(deauth.file) [gets $rfile]
set set(adduser.file) [gets $rfile]
set set(deluser.file) [gets $rfile]
set set(banmask) [gets $rfile]
close $rfile
}
### SETINFO: setinfo <variable> [<value>]
## Stores the information from variable to file (opposite of 'getinfo')
proc setinfo {{var &NA&} {value &NA&}} {
check_error "setinfo variable ?value?" $var &NA&
global set
if {[string tolower $var] != "all"} {
set set([string tolower $var]) $value