download alice120.tcl
Language: Tcl
LOC: 520
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
##
#
# alice.tcl v1.2.0 - by strikelight ([sL] @ EFNet) (September 16, 2002)
#
# - Read the README.TXT for script details, help, and contact info.
#
##

#### CONFIGURATION ####

## File to save alice cookies to ##
set alice_cookiesfile "$nick.cookies"

## Every night, expire cookies that have not been accessed in how many days? ##
set alice_cookiesexpire 5

## Let your bot respond to private messages? (0 = No, 1 = Yes) ##
set alice_respondpriv 1

## Let your bot respond to comments in channel when bot's name is mentioned? ##
# (0 = No, 1 = Yes) [ For eggdrop versions less than 1.5.x
# ( 1.5.x+ users should use .chanset #channel +alice ) ]
set alice_respondchan 1

## Require bot's nick to be in all lines of a public conversation in order
# for it to respond, after initial contact? (ie. <someone> alice: hello there)
# (if alice_respondchan is set to 1, or channel is set to +alice, else ignore this)
# (0 = No, 1 = Yes)
set alice_respondrequirenick 1

## Respond with user's nick? (ie. <alice> user: Hi, how are you?)
# (if alice_respondchan is set to 1, or channel is set to +alice, else ignore this)
# (0 = No, 1 = Yes)
set alice_respondwithnick 1

## Channels to listen on (if alice_respondchan is set to 1, else ignore this) ##
# (Separate multiple channels by space, use * to indicate all channels)
# [ For eggdrop versions less than 1.5.x only , 1.5.x+ users should
#   use .chanset #channel +alice ]
# eg. set alice_channels "#channel1 #channel2 #etc"  .. or :
set alice_channels "*"

## Also if alice_respondchan is set to 1 or channel is set to +alice,
# (otherwise ignore this), how long a silence should the bot wait for
# user's text in a channel after the first contact is made before
# giving up on their conversation? (in minutes)
set alice_timeoutchat 5

## Log conversations?
# 0 = No
# 1 = Yes
set alice_logging 0

## If logging on, what directory should the logs be stored in?
# (Note1: If directory doesn't exist, you must create it)
# (Note2: Ignore this if you don't want to log)
set alice_log_path "logs/"

## Which server should I use for the alice engine?
# 0 = www.alicebot.org (Alice)
# 1 = www.agentruby.com (Ruby)
# 2 = a program E server (Phillip)
# 3 = jaczone.com (Cyber-Ivar)
# 4 = neodave.civ.pl (Hippie)
# 5 = your own program-D alice server
# 6 = Actual Hippie Program-C
set alice_engine -1

# If using your own alice server (program-D), enter the url here:
set alice_url "http://yourserver.here.com:2001/"

# If using your own actual Hippie Program-C, set path here:
#set alice_hippie_path "/home/user/eggdrop/C/command_alice"

# If using your own actual Hippie Program-C, set path to ini file here:
#set alice_hippie_inipath "/home/user/eggdrop/C/data/alice.ini"

# If using your own actual Hippie Program-C, set path to log info here:
#set alice_hippie_logpath "/home/user/eggdrop/C/log/"

#### END OF CONFIGURATION (STOP EDITTING HERE!!) ####

if {[info exists egghttp(version)]} {
  regsub -all "\\." $egghttp(version) "" egghttpnumvers 
}
if {($alice_engine < 6) && (![info exists egghttp(version)] || ($egghttpnumvers < 103))} {
  putlog "alice.tcl : Could not load alice.tcl, egghttp.tcl 1.0.3 or greater is required."
  putlog "alice.tcl : You may download it from http://www.TCLScript.com"
  catch {unset alice_url}
  catch {unset alice_timeoutchat}
  catch {unset alice_channels}
  catch {unset alice_respondchan}
  catch {unset alice_respondrequirenick}
  catch {unset alice_respondwithnick}
  catch {unset alice_respondpriv}
  catch {unset alice_cookiesexpire}
  catch {unset alice_cookiesfile}
  catch {unset alice_engine}
  catch {unset alice_logging}
  catch {unset alice_hippie_path}
  catch {unset alice_hippie_inipath}
  catch {unset alice_hippie_logpath}
} elseif {($alice_engine == 6) && (![info exists bgexec(version)])} {
  putlog "alice.tcl : Could not load alice.tcl, bgexec.tcl is required."
  putlog "alice.tcl : You may download it from http://www.TCLScript.com"
  catch {unset alice_url}
  catch {unset alice_timeoutchat}
  catch {unset alice_channels}
  catch {unset alice_respondchan}
  catch {unset alice_respondrequirenick}
  catch {unset alice_respondwithnick}
  catch {unset alice_respondpriv}
  catch {unset alice_cookiesexpire}
  catch {unset alice_cookiesfile}
  catch {unset alice_engine}
  catch {unset alice_logging}
  catch {unset alice_hippie_path}
  catch {unset alice_hippie_inipath}
  catch {unset alice_hippie_logpath}
} elseif {$alice_engine == -1} {
  putlog "alice.tcl : You have not fully configured your Alice.tcl script."
  putlog "alice.tcl : Please edit the configuration, and then restart."
  putlog "alice.tcl : alice.tcl has NOT been loaded."
} else {
  set alice_version "1.2.0"
  set alice_chanflag [catch {setudef flag alice}]
  switch $alice_engine {
    0 {
      set alice_url "http://alice.sunlitsurf.com:2009/a.l.i.c.e./"
      set alice_input "text"
      set alice_cookie_method 0
      set alice_query_method 0
    }
    1 {
      set alice_url "http://www.agentruby.com:2001/"
      set alice_input "text"
      set alice_cookie_method 0
      set alice_query_method 0
    }
    2 {
      set alice_url "http://217.6.247.139/alicebot/src/talk.php"
      set alice_input "input"
      set alice_cookie_method 0
      set alice_query_method 0
    }
    3 {
      set alice_url "http://213.67.11.109/"
      set alice_input "text"
      set alice_cookie_method 0
      set alice_query_method 0
    }
    4 {
      set alice_url "http://neodave.civ.pl/hippie/hippie.cgi"
      set alice_input "text"
      set alice_cookie_method 1
      set alice_query_method 1
    }
    5 {
      set alice_url $alice_url
      set alice_input "text"
      set alice_cookie_method 0
      set alice_query_method 0
    }
    6 {
      set alice_url ""
    }
    default {
      set alice_url "http://alice.sunlitsurf.com:2009/a.l.i.c.e./"
      set alice_input "text"
      set alice_cookie_method 0
      set alice_query_method 0
    }
  }

# MISC PROCS

## strip_html : remove text that begins with <, ends with >, and everything in between
  proc strip_html {text} {
    regsub -all ">" $text \x81 text
    regsub -all "<\[^\x81\]*\x81" $text {} text
    regsub -all "&nbsp;" $text " " text
    regsub -all "&amp;" $text {\&} text
    regsub -all "&quot;" $text "\'" text
    regsub -all "&copy;" $text "(c)" text
    regsub -all "&#" $text "#" text
    regsub -all "&lt;" $text "<" text
    regsub -all "&gt;" $text ">" text
    regsub -all "%20" $text " " text
    return $text
  }

## lstring_remove : remove all elements from a list that contain the matching remove pattern
  proc lstring_remove {list remove} {
    set newlist ""
    foreach item $list {
      if {![string match "*[string tolower $remove]*" [string tolower $item]]} {
        lappend newlist $item
      }
    }
    return $newlist
  }

## nearestindex : return the string index where char occurs in text, nearest to
#                 a specified index
  proc nearestindex {text index {char " "}} {
    set tchar [string index $text $index]
    while {($tchar != $char) && ($index >= 0)} {
      incr index -1
      set tchar [string index $text $index]
    }
    return $index
  }

## istoldquiet : check to see if the text says for the bot to be quiet
  proc istoldquiet {text} {
    set exprs {shush {be *quiet} bye cya ttyl {talk* later} {i* leav} {got* go} {shut *up} shutup {leave me *alone} {go away} quiet shh}
    foreach item $exprs {
      if {[string match "*$item*" [string tolower $text]]} { return 1 }
    }
    return 0
  }

# Alice Formatting Procs

## alice:corrections : replace any occurances of the alice name with the bot's name instead
#                      also fix misc. html codes to plain text
  proc alice:corrections {text} {
    global nick
    regsub -all -- "alice" $text "$nick" text
    regsub -all -- "Alice" $text "$nick" text
    regsub -all -- "ALICE" $text "$nick" text
    regsub -all -- "A.L.I.C.E." $text "$nick" text
    regsub -all -- "A.L.I.C.E" $text "$nick" text
    regsub -all -- "a.l.i.c.e." $text "$nick" text
    regsub -all -- "a.l.i.c.e" $text "$nick" text
    regsub -all -- "ruby" $text "$nick" text
    regsub -all -- "Ruby" $text "$nick" text
    regsub -all -- "sofia" $text "$nick" text
    regsub -all -- "Sofia" $text "$nick" text
    regsub -all -- "testbot" $text "$nick" text
    regsub -all -- "TestBot" $text "$nick" text
    regsub -all -- "ivar" $text "$nick" text
    regsub -all -- "Ivar" $text "$nick" text
    regsub -all -- "[format %c 9]" $text "" text
    regsub -all -- "parent.noAnswer=1;" $text "" text
    regsub -all -- "charNoAnswer \\(\\);" $text "" text
    regsub -all -- "charSpeak\\(\"" $text "" text
    regsub -all -- "\"\\);" $text "" text
    return $text
  }

## alice:fixquery : replace all spaces with "%20" or "+" depending on query_method
# first line of this proc by Wcc (thanks mate) (27/6/02)
  proc alice:fixquery {text} {
    regsub -all -- {\002|\037|\026|\017|\003([0-9][0-9]?(,[0-9][0-9]?)?)?|||([0-9][0-9]?(,[0-9][0-9]?)?)?|} $text "" text
    global alice_query_method
    if {$alice_query_method == 0} {
      regsub -all -- " " $text "%20" text
    } elseif {$alice_query_method == 1} {
      regsub -all -- " " $text "+" text
    }
    return $text
  }

# Alice Logging Procs

## alice:logdata : save data to logfile
  proc alice:logdata {where who what} {
    global alice_logging alice_log_path
    if {!$alice_logging} { return 0 }
    set file "${where}.alice.log"
    regsub -all -nocase \\| $file _ file
    if {[catch {set outfile [open "${alice_log_path}${file}" a+]}]} {
      return 0
    }
    set dtime [clock format [clock seconds] -format "\[(%m.%d.%y) %H:%M\]"]
    puts $outfile "$dtime <$who> $what"
    close $outfile
    return 1
  }

# Alice Cookie Procs

## alice:getcookies : return the saved cookie for a person
#                     (cookies are used so that alice remembers the person)
  proc alice:getcookies {who} {
    global alice_cookies
    set who [string tolower $who]
    if {![info exists alice_cookies($who,data)]} {
      return ""
    }
    return $alice_cookies($who,data)
  }

## alice:setcookies : store a cookie for a person
  proc alice:setcookies {who cookies} {
    global alice_cookies
    set who [string tolower $who]
    set ocookies [alice:getcookies $who]
    if {($ocookies != "") && ([llength [split $cookies]] == 2)} {
      set ncookies ""
      foreach ck $ocookies {
        if {[string match "*jsessionid*" $ck]} {
          if {[string index $ck [expr [string length $ck] - 1]] != ";"} {
            append ck ";"
          }
          append ncookies "$ck "
        }
      }
      append ncookies $cookies
      set cookies $ncookies
    } elseif {($ocookies != "") && ([llength [split $cookies]] == 1)} {
      set ncookies ""
      foreach ck $ocookies {
        if {[string match "*alicebot_*" $ck]} {
          if {[string index $ck [expr [string length $ck] - 1]] != ";"} {
            append ck ";"
          }
          append ncookies "$ck "
        }
      }
      append ncookies $cookies
      set cookies $ncookies
    }
    set alice_cookies($who,data) "$cookies"
    set alice_cookies($who,time) "[clock seconds]"
    return 1
  }

## alice:savecookies : save cookies to file
  proc alice:savecookies {} {
    global alice_cookiesfile alice_cookies
    set outfile [open "$alice_cookiesfile" w]
    puts $outfile [list array set alice_cookies [array get alice_cookies]]
    close $outfile
    return 1
  }

## alice:loadcookies : load cookies from file
  proc alice:loadcookies {} {
    global alice_cookiesfile alice_cookies
    catch {unset alice_cookies}
    source $alice_cookiesfile
  }

## alice:expirecookies : remove old cookies
  proc alice:expirecookies {} {
    global alice_cookies alice_cookiesexpire
    set seconds [expr $alice_cookiesexpire * 24 * 60 * 60]
    foreach cookie [array names alice_cookies *,time] {
      if {[expr [clock seconds] - $alice_cookies($cookie)] >= $seconds} {
        set who [lindex [split $cookie ","] 0]
        catch {unset alice_cookies($who,time)}
        catch {unset alice_cookies($who,data)}
      }
    }
  }

## alice:time_cookie : call the expire cookies procedure
  bind time - "16 * * * *" alice:time_cookie
  proc alice:time_cookie {mi ho da mo yr} {
    putloglev o * "ALICE: Expiring old alice cookies ..."
    alice:expirecookies
    putloglev o * "ALICE: Saving alice cookie data ..."
    alice:savecookies
  }

# Alice Connection Procs

## alice:query : send user's text to the alice engine on the web to wait for a reply
  proc alice:query {who where text} {
    global alice_url alice_input alice_cookie_method alice_engine
    global alice_hippie_path alice_hippie_inipath alice_hippie_logpath
    if {$alice_engine == 6} {
      if {[catch {bgexec "$alice_hippie_path -i $alice_hippie_inipath -u ${alice_hippie_logpath}${who} \"$text\"" [list alice:execresponse $who $where]} err]} {
        putlog "alice.tcl : Error executing hippie command program. ($err) Did you install it?"
      }
      return -1
    }
    set text [alice:fixquery $text]
    set cookies [alice:getcookies $who]
    if {$cookies != ""} {
      if {$alice_cookie_method == 0} {
        set sock [egghttp:geturl $alice_url [list alice:response $who $where] -query $alice_input=$text -headers "Cookie: $cookies"]
      } elseif {$alice_cookie_method == 1} {
        set sock [egghttp:geturl $alice_url [list alice:response $who $where] -query $alice_input=$text&$cookies]
      }
      alice:setcookies $who "$cookies"
    } else {
      if {$alice_cookie_method == 0} {
        set sock [egghttp:geturl $alice_url [list alice:response $who $where] -query $alice_input=$text]
      } elseif {$alice_cookie_method == 1} {
        if {$alice_engine == 4} {
          set cookies "&virtual=none"
        }
        set sock [egghttp:geturl $alice_url [list alice:response $who $where] -query $alice_input=${text}${cookies}]
      }
    }
    return $sock
  }

## alice:response : parse alice's response and show the user
  proc alice:response {who where sock} {
    global alice_engine alice_respondwithnick botnick
    set headers [egghttp:headers $sock]
    set data [egghttp:data $sock]
    set response ""
    if {([egghttp:errormsg $sock] != "Ok") || ($data == "")} {
      catch {alice:timeoutchat $who $where}
      egghttp:cleanup $sock
      return
    }
    egghttp:cleanup $sock
    set cookies ""
    foreach line [split $headers "\n"] {
      if {[string match "*Set-Cookie:*" $line]} {
        set what [lindex [split $line " "] 1]
        if {$alice_engine != 4} {
          if {[string match "*Expires*" $what]} {
            set what [string range $what 0 [expr [string first "Expires" $what] - 2]]
          }
          if {[string match "*Path*" $what]} {
            set what [string range $what 0 [expr [string first "Path" $what] - 2]]
          }
        }
        if {($alice_engine == 4) && ([string match "*VIR=*" $what])} {
          set what [string range $what [expr [string first "VIR=" $what] + 4] [expr [string first $what ";"] - 1]]
          set what "virtual=$what"
        }          
        if {$what != ""} {
          append cookies "; $what"
        }
      }
    }
    set cookies [string range $cookies 2 end]
    if {$cookies != ""} {
      alice:setcookies $who "$cookies"
    }
    set a 0
    foreach line [split $data "\n"] {
      # programE specific instructions
      if {$alice_engine == 2} {
        if {[string match "*#FFFFFF*" $line]} {
          incr a
        }
        if {($a >= 1) && ([string match "*#ffff66*" $line])} {
          set apos [expr [string last "#ffff66" $line] + 9]
          set response [string range $line $apos [string length $line]]
        } elseif {($a >= 1)} {
          append response [string trim $line]
        }
        if {($a >= 1) && ([string match "*</tr>*" $line])} {
          break
        }
        continue
      }
      # hippie cgi specific instructions
      if {$alice_engine == 4} {
        if {[string match "*Hippie said*" $line]} {
          incr a
          set line [string range $line [expr [string first "said:" $line] + 5] end]
        }
        if {($a >= 1) && (![string match "*\"http://neodave*" $line])} {
          append response [string trim $line]
        }
        if {[string match "*\"http://neodave*" $line]} {
          break
        }
        continue
      }
      if {($a >= 1) && ![string match "*</p>*" $line]} {
        append response [string trim $line]
      }
      if {($a >= 1) && ([string match "*</p>*" $line] || [string match "*check_return()*" $line] || [string match "*</form>*" $line] || [string match "*jaczone.com*" $line])} {
        break
      }
      if {[string match "*response-line*" $line] || [string match "*\"botresponse\"*" $line] || ([string match "*offline for maint*" $line] && ($alice_engine != 3)) \
       || [string match "*</td></td></tr><tr><td align=center>*" $line] || [string match "*Perhaps that*" $line]} {
        incr a
      }
    }
    if {$response != ""} {
      set response [strip_html $response]
      set response [alice:corrections $response]
      set response [string trimleft $response "\}"]
      set response [string trim $response]
      if {[string length $response] >= 256} {
        while {($response != "") && ([string length $response] >= 256)} {
          set tmp [nearestindex "$response" 256]
          if {$tmp != -1} {
            set text [string range $response 0 [expr $tmp - 1]]
            set response [string range $response [expr $tmp + 1] end]
          } else {
            set text [string range $response 0 256]
            set response [string range $response 257 end]
          }
          if {[validchan $where] && $alice_respondwithnick} {
            set text "$who: $text"
          }
          alice:logdata "$where" "$botnick" "$text"
          puthelp "PRIVMSG $where :$text"
        }
      }
      if {$response != ""} {
        if {[validchan $where] && $alice_respondwithnick} {
          set response "$who: $response"
        }
        alice:logdata "$where" "$botnick" "$response"
        puthelp "PRIVMSG $where :$response"
      }
    }
  }

## alice:execresponse : parse alice's response and show the user
  proc alice:execresponse {who where data} {
    global alice_engine alice_respondwithnick botnick
    set response ""
    foreach line [split $data "\n"] {
      append response [string trim $line]
    }
    if {$response != ""} {
      set response [strip_html $response]
      set response [alice:corrections $response]
      set response [string trimleft $response "\}"]
      set response [string trim $response]
      if {[string length $response] >= 256} {
        while {($response != "") && ([string length $response] >= 256)} {
          set tmp [nearestindex "$response" 256]
          if {$tmp != -1} {
            set text [string range $response 0 [expr $tmp - 1]]
            set response [string range $response [expr $tmp + 1] end]
          } else {
            set text [string range $response 0 256]
            set response [string range $response 257 end]
          }
          if {[validchan $where] && $alice_respondwithnick} {
            set text "$who: $text"
          }
          alice:logdata "$where" "$botnick" "$text"
          puthelp "PRIVMSG $where :$text"
        }
      }
      if {$response != ""} {
        if {[validchan $where] && $alice_respondwithnick} {
          set response "$who: $response"
        }
        alice:logdata "$where" "$botnick" "$response"
        puthelp "PRIVMSG $where :$response"
      }
    }
  }

  proc alice:timeoutchat {who where} {
    global alice_chat
    catch {unset alice_chat($who,$where)}
  }

# Alice Chat Binding Procs

  if {$alice_respondpriv} {
    bind msgm - * alice:msg_query
    proc alice:msg_query {nick uhost hand text} {
      global botnick
      if {([string tolower $nick] == [string tolower $botnick]) || ([matchattr $hand b])} {
        return
      }
      # let's not bother looking at passwords and stuff ... -sL (6/13/02)
      if {[regexp pass|op|invite|ident|addhost [string tolower [lindex [split $text] 0]]]} {
        set text ""
        return 0
      }
      set where "[string tolower $nick]"
      if {($hand != "") && ($hand != "*")} {
        set who "[string tolower $hand]"
      } else {
        set who "[string tolower $nick]"
      }
      alice:logdata $where $who "$text"
      alice:query $who $where "$text"
      return 0
    }
  }
  
  if {($alice_respondchan) || (!$alice_chanflag)} {

    proc alice:isrespondchan {chan} {
      global alice_chanflag alice_channels
      if {!$alice_chanflag} {
        if {[lsearch -exact [channel info $chan] +alice] != -1} {
          return 1
        } else {
          return 0
        }
      } else {
        if {($alice_channels == "*") || ([lsearch [split [string tolower $alice_channels]] $chan] != -1)} {
          return 1
        } else {
          return 0
        }
      }
    }

    bind pubm - * alice:pub_query
    proc alice:pub_query {nick uhost hand chan text} {
      global botnick alice_channels alice_timeoutchat alice_chat alice_respondrequirenick
      if {([string tolower $nick] == [string tolower $botnick]) || ([matchattr $hand b])} {
        return
      }
      set chan [string tolower $chan]
      if {![alice:isrespondchan $chan]} {
        return
      }
      set where "$chan"
      if {($hand != "") && ($hand != "*")} {
        set who "[string tolower $hand]"
      } else {
        set who "[string tolower $nick]"
      }
      if {(![string match "*[string tolower $botnick]*" [string tolower $text]]) && (![info exists alice_chat($who,$chan)])} {
        return
      }
      if {(![string match "*[string tolower $botnick]*" [string tolower $text]] && $alice_respondrequirenick)} {
        return
      }
      if {![info exists alice_chat($who,$chan)]} {
        set alice_chat($who,$chan) [utimer [expr $alice_timeoutchat * 60] "alice:timeoutchat $who $chan"]
      } else {
        catch {killutimer $alice_chat($who,$chan)}
        set alice_chat($who,$chan) [utimer [expr $alice_timeoutchat * 60] "alice:timeoutchat $who $chan"]
      }
      if {[istoldquiet $text]} {
        alice:timeoutchat $who $where
      }
      set text [join [lstring_remove [split $text] $botnick]]
      alice:logdata $where $who "$text"
      alice:query $who $where "$text"
    }
  }

## create cookies file if it doesn't exist
  if {![file exists $alice_cookiesfile]} {
    set outfile [open $alice_cookiesfile w]
    close $outfile
    catch {unset outfile}
  }

## load cookies file
  alice:loadcookies
  putlog "alice.tcl $alice_version by strikelight is now loaded."
}

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