This file is indexed.

/usr/share/amsn/plugins/jake/jake.tcl is in amsn-data 0.98.9-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
namespace eval ::jake {

    global mydir
    global starttime
    global birthday

    proc jakeStart { dir } {
	global mydir
	set mydir $dir

	#Global vars used for the "info" command.
        global starttime
        global birthday

        #Little hack. The "clock" was totally rewriten in 8.5
        if {[info tclversion] == 8.4} {
            set birthday [regexp {(\d+)/(\d+)/(\d+)/(\d+)/(\d+)} 05/02/2009/12/00 -> d m Y H M ; clock scan $Y-$m-${d}T$H:$M]
        } else {
            set birthday [clock scan 05/02/2009/12/00 -format %d/%m/%Y/%H/%M]
        }
        set starttime [clock seconds] 

	#Register the plugin
	::plugins::RegisterPlugin jake
	::plugins::RegisterEvent jake chat_msg_received answer
        ::plugins::RegisterEvent jake chat_msg_received statesetLastWord
	::plugins::RegisterEvent jake ChangeMyState online
        ::plugins::RegisterEvent jake ChangeState statesetLastSeen

	#Set and load the language for the plugin
	set langdir [file join $mydir "lang"]       
	set lang [::config::getGlobalKey language]    
	load_lang en $langdir                       
	load_lang $lang $langdir                    

	#Create the aray used in the conf
	array set ::jake::config {
	    botname {jake}                                             
	    helptxt {I'm jake, an AI bot.}  
	    nresultsgoogle {3}                
            nresultsmegaupload {3}
            nresultssongs {3}
            nresultsyoutube {3}
	}

	set ::jake::configlist [list \
	    [list str "[trans guiname]" botname] \
	    [list str "[trans guihelptext]" helptxt] \
	    [list str "[trans guinresultsgoogle]" nresultsgoogle] \
            [list str "[trans guinresultsmegaupload]" nresultsmegaupload] \
            [list str "[trans guinresultssongs]" nresultssongs] \
            [list str "[trans guinresultsyoutube]" nresultsyoutube] \
	]

	#Source needed tcl files
        source [file join $mydir "http.tcl"]
	source [file join $mydir "help.tcl"]
	source [file join $mydir "music.tcl"]
        source [file join $mydir "stack.tcl"]
        source [file join $mydir "learn.tcl"]
        source [file join $mydir "state.tcl"]
        source [file join $mydir "forget.tcl"]
	source [file join $mydir "google.tcl"]
	source [file join $mydir "youtube.tcl"]
        source [file join $mydir "cmdline.tcl"]
        source [file join $mydir "htmlparse.tcl"]
        source [file join $mydir "translate.tcl"]
        source [file join $mydir "megaupload.tcl"]
        source [file join $mydir "fuzzystringmatch.tcl"]

        #make sure that needed files exist
        if {![file exists [file join $::HOME "jake" "dictionary.dic"]]} {
            set fl [open [file join $::HOME "jake" "dictionary.dic"] "a+"]
            close $fl
        }
        if {![file exists [file join $::HOME "jake" "off.conf"]]} {
            set fl [open [file join $::HOME "jake" "off.conf"] "a+"]
            close $fl
        }
    }

    proc rand {m {n 0}} {
	    expr {int(($m-$n)*rand()+$n)}
    }

    proc getPage {url} {
	    package require http
	    ::http::config -useragent "Monkey cmdline tool (OpenBSD; en)"
	    if {[catch {set token [::http::geturl $url]} msg]} {
	      return "Error: $msg"
	    } else {
	      set data [::http::data $token]
	    }
	    ::http::cleanup $token
	    return $data
    }

    proc answer {event epvar} {
	    
	    global mydir
            global starttime
            global birthday

	    upvar 2 $epvar args
	    upvar 2 $args(msg) msg                           
	    upvar 2 $args(chatid) chatid                      
	    upvar 2 $args(user) user                         
	    set me [::abook::getPersonal login]               
	    set window [::ChatWindow::For $chatid]            
	    set botname $::jake::config(botname)
	    set language [::config::getGlobalKey language]

	    if { $msg == "![trans cmdon]" } {   
		    if { [isuseroff $chatid] == 1 } {
			    set in [open [file join $::HOME "jake" "off.conf"] r]
			    set out [open [file join $::HOME "jake" "off.conf.tmp"] w]
			    while { [gets $in line] >= 0 } {
				    if { [string match $chatid $line] == 0 } {
					    puts $out $line
				    }
			    }
			    close $in
			    close $out
			    file delete -force [file join $::HOME "jake" "off.conf"]
			    file rename -force [file join $::HOME "jake" "off.conf.tmp"] [file join $::HOME "jake" "off.conf"]
		    }
		    plugins_log jake "Plugin Jake activado!"
		    ::amsn::MessageSend $window 0 "$botname: [trans msgon]"
	    } elseif { $msg == "![trans cmdoff]" } {
		    set in [open [file join $::HOME "jake" "off.conf"] a+]
		    if { ![isuseroff $chatid] } {
			    puts $in $chatid
		    }
		    close $in
		    plugins_log jake "Plugin Jake desactivado"
		    ::amsn::MessageSend $window 0 "$botname: [trans msgoff]"
	    } elseif { [string first "![trans cmdstate]" $msg] == 0 } {
                    set commandLength [expr [string length [trans cmdstate]] + 2]
                    set strWithoutCommand [string range $msg $commandLength end]

                    #get what options did the user wrote.
                    set arguments [stateparseArgs $strWithoutCommand]

                    #if everything is ok, keep on, else say that something went wrong
                    if { [string compare [lindex $arguments 1] "ok"] == 0 } {
                        if { [string compare [lindex $arguments 0] ""] == 0 } {
                            set results [stategetState $starttime $birthday $chatid]
                        } else {
                            set results [stategetLastSeen [lindex $arguments 0]]
                            if { [string compare $results "notonlinebutneverseen"] == 0 } {
                                set results "[trans txtstatenotonlinebutneverseen]"
                            } elseif { [string compare $results "online"] == 0 } {
                                set results "[trans txtstateonline]"
                            }
                        }
                    } else {
                        set results "[trans txtcmderr]\n\
                                    [trans txtcommand]: ![trans cmdstate]\n\
                                    [trans txtprm]: [trans prmstate]\n\
                                    [trans txtdsc]: [trans dscstate]\n\
                                    [trans txtexl]: [trans exlstate]"
                    }

                    #show results
                    ::amsn::MessageSend $window 0 "$botname: $results"
	    } elseif { [string first "![trans cmdhelp]" $msg] == 0 } {
		    set commandLength [expr [string length [trans cmdhelp]] + 2]
		    set strWithoutCommand [string range $msg $commandLength end]

		    #get what options did the user wrote.
		    set arguments [helpparseArgs $strWithoutCommand]

		    #if everything is ok, keep on, else say that something went wrong
		    if { [string compare [lindex $arguments 1] "ok"] == 0 } {
			if { [string compare [lindex $arguments 0] ""] == 0 } {
			    set results [helpgeneralHelp]
			} else {
			    set results [helpcommandHelp [lindex $arguments 0]]
			}
		    } else {
			set results "[trans txtcmderr]\n\
				    [trans txtcommand]: ![trans cmdhelp]\n\
				    [trans txtprm]: [trans prmhelp]\n\
				    [trans txtdsc]: [trans dschelp]\n\
				    [trans txtexl]: [trans exlhelp]"
		    }

		    #show results
		    ::amsn::MessageSend $window 0 "$botname: $results"
	    } elseif { [string first "![trans cmdhour]" $msg] == 0 } {
		    set commandLength [expr [string length [trans cmdhour]] + 1]
		    if { $commandLength == [string length $msg] } {
			set results "[clock format [clock seconds] -format {%H:%M:%S}]"
		    } else {
			set results "[trans txtcmderr]\n\
				    [trans txtcommand]: ![trans cmdhour]\n\
				    [trans txtprm]: [trans prmhour]\n\
				    [trans txtdsc]: [trans dschour]\n\
				    [trans txtexl]: [trans exlhour]"
		    }
		    ::amsn::MessageSend $window 0 "$botname: $results"
	    } elseif { [string first "![trans cmddate]" $msg] == 0 } {
		    set commandLength [expr [string length [trans cmddate]] + 1]
		    if { $commandLength == [string length $msg] } {
			set results "[clock format [clock seconds] -format {%d/%m/%Y}]"
		    } else {
			set results "[trans txtcmderr]\n\
				    [trans txtcommand]: ![trans cmddate]\n\
				    [trans txtprm]: [trans prmdate]\n\
				    [trans txtdsc]: [trans dscdate]\n\
				    [trans txtexl]: [trans exldate]"
		    }
		    ::amsn::MessageSend $window 0 "$botname: $results"
	    } elseif { [string first "![trans cmdgoogle] " $msg] == 0 } {
		    set commandLength [expr [string length [trans cmdgoogle]] + 2]
		    set strWithoutCommand [string range $msg $commandLength end]

		    #get what options did the user wrote.
		    set arguments [googleparseArgs $strWithoutCommand]

		    #if everything is ok, keep on, else say that something went wrong
		    if { [string compare [lindex $arguments 2] "ok"] == 0 } {
			set results [googlesearchText [lindex $arguments 0] [lindex $arguments 1] $language]
		    } else {
			set results "[trans txtcmderr]\n\
				    [trans txtcommand]: ![trans cmdgoogle]\n\
				    [trans txtprm]: [trans prmgoogle $::jake::config(nresultsgoogle)]\n\
				    [trans txtdsc]: [trans dscgoogle]\n\
				    [trans txtexl]: [trans exlgoogle]"
		    }

		    #convert to plain text
		    set results [::htmlparse::mapEscapes $results]
		    if {[string compare $results "noresults"] == 0 } {
                        set results "$botname: [trans txtnoresults] [trans txtchangesearchwords]"
                    }
		    #print results
		    ::amsn::MessageSend $window 0 $results
	    } elseif { [string first "![trans cmdmegaupload] " $msg] == 0 } {
		    set commandLength [expr [string length [trans cmdmegaupload]] + 2]
		    set strWithoutCommand [string range $msg $commandLength end] 

                    #get what options did the user wrote.
                    set arguments [megauploadparseArgs $strWithoutCommand]

                    #if everything is ok, keep on, else say that something went wrong
                    if { [string compare [lindex $arguments 2] "ok"] == 0 } {
                        set results [megauploadsearch [lindex $arguments 0] [lindex $arguments 1]]
                    } else {
                        set results "[trans txtcmderr]\n\
                                    [trans txtcommand]: ![trans cmdmegaupload]\n\
                                    [trans txtprm]: [trans prmmegaupload $::jake::config(nresultsmegaupload)]\n\
                                    [trans txtdsc]: [trans dscmegaupload]\n\
                                    [trans txtexl]: [trans exlmegaupload]"
                    }

                    #convert to plain text
                    set results [::htmlparse::mapEscapes $results]
                    
                    #print results
                    ::amsn::MessageSend $window 0 $results
	    } elseif { [string first "![trans cmdyoutube] " $msg] == 0 } {   
		    #leave only the text after the command
		    set commandLength [expr [string length [trans cmdyoutube]] + 2]
		    set strWithoutCommand [string range $msg $commandLength end]

		    #get what options did the user wrote.
		    set arguments [youtubeparseArgs $strWithoutCommand]

		    #if everything is ok, keep on, else say that something went wrong
		    if { [string compare [lindex $arguments 2] "ok"] == 0 } {
			set results [youtubesearchVideos [lindex $arguments 0] [lindex $arguments 1]]
		    } else {
			set results "[trans txtcmderr]\n\
				    [trans txtcommand]: ![trans cmdyoutube]\n\
				    [trans txtprm]: [trans prmyoutube $::jake::config(nresultsyoutube)]\n\
				    [trans txtdsc]: [trans dscyoutube]\n\
				    [trans txtexl]: [trans exlyoutube]"
		    }
		    
		    #convert to plain text
		    set results [::htmlparse::mapEscapes $results]

		    #print results
		    ::amsn::MessageSend $window 0 $results
	    } elseif { [string first "![trans cmddefine] " $msg] == 0 } {  
		    set commandLength [expr [string length [trans cmddefine]] + 2]
		    set strWithoutCommand [string range $msg $commandLength end]

		    #get what options did the user wrote.
		    set arguments [googleparseArgs $strWithoutCommand]

		    #if everything is ok, keep on, else say that something went wrong
		    if { [string compare [lindex $arguments 2] "ok"] == 0 } {
			set results [googledefineText [lindex $arguments 0] [lindex $arguments 1] $language]
		    } else {
			set results "[trans txtcmderr]\n\
				    [trans txtcommand]: ![trans cmddefine]\n\
				    [trans txtprm]: [trans prmdefine]\n\
				    [trans txtdsc]: [trans dscdefine]\n\
				    [trans txtexl]: [trans exldefine]"
		    }

		    #convert to plain text
		    set results [::htmlparse::mapEscapes $results]
                    if {[string compare $results "noresults"] == 0 } {
                        set results "$botname: [trans txtnoresults] [trans txtchangesearchwords]"
                    }
		    #print results
		    ::amsn::MessageSend $window 0 $results
	    } elseif { [string first "![trans cmdlearn] " $msg] == 0 } {   
		    if { [array exists dictionary] == 0 } {
			    source [file join $::HOME "jake" "dictionary.dic"]
		    }
		    set commandLength [expr [string length [trans cmdlearn]] + 2]
		    set strWithoutCommand [string range $msg $commandLength end]      

                    #get what options did the user wrote.
                    set arguments [learnparseArgs $strWithoutCommand]

                    #if everything is ok, keep on, else say that something went wrong
                    if { [string compare [lindex $arguments 1] "ok"] == 0 } {
                        if { [learnaddToDictionary [lindex $arguments 0]] == 1 } {
                            set results "$botname: [trans txtregadd] [expr [array size dictionary] + 1] [trans txtregs]"
                        } else {
                            set results "$botname: [trans txterradd]"
                        }
                    } else {
                        set results "[trans txtcmderr]\n\
                                    [trans txtcommand]: ![trans cmdlearn]\n\
                                    [trans txtprm]: [trans prmlearn]\n\
                                    [trans txtdsc]: [trans dsclearn]\n\
                                    [trans txtexl]: [trans exllearn]"
                    }

                    #print results
                    ::amsn::MessageSend $window 0 $results
	    } elseif { [string first "![trans cmdforget] " $msg] == 0 } {  

		    set commandLength [expr [string length [trans cmdforget]] + 2]
		    set strWithoutCommand [string range $msg $commandLength end]  

                    #get what options did the user wrote.
                    set arguments [forgetparseArgs $strWithoutCommand]

		    if { [string compare [lindex $arguments 1] "ok"] == 0 } {
                        set results [forgetremoveFromDictionary [lindex $arguments 0]]
			set results "$botname: [trans txtregdel] $results [trans txtregs]"
                    } else {
                        set results "[trans txtcmderr]\n\
                                    [trans txtcommand]: ![trans cmdforget]\n\
                                    [trans txtprm]: [trans prmforget]\n\
                                    [trans txtdsc]: [trans dscforget]\n\
                                    [trans txtexl]: [trans exlforget]"
                    }
                    ::amsn::MessageSend $window 0 $results
	    } elseif { [string first "![trans cmdexpr] " $msg] == 0 } {
		    set commandLength [expr [string length [trans cmdexpr]] + 2]
		    set msg [string range $msg $commandLength end]
		    ::amsn::MessageSend $window 0 "$botname: [expr [string map {/ *1./} $msg]]"
	    } elseif { [string first "![trans cmdsong] " $msg] == 0 } {
		    #leave only the text after the command
		    set commandLength [expr [string length [trans cmdsong]] + 2]
		    set strWithoutCommand [string range $msg $commandLength end]

		    #get what options did the user wrote.
		    set arguments [musicparseArgs $strWithoutCommand]

		    #if everything is ok, keep on, else say that something went wrong
		    if { [string compare [lindex $arguments 2] "ok"] == 0 } {
			set results [musicsearchGoear [lindex $arguments 0] [lindex $arguments 1]]
			if { [musicCheckCoincidence $results [lindex $arguments 0]] == 1 } {
			    #convert to plain text
                            set results [::htmlparse::mapEscapes $results]
			    ::amsn::MessageSend $window 0 $results
			    return
			}
			set results [musicsearchElcamajan [lindex $arguments 0] [lindex $arguments 1]]
			if { [musicCheckCoincidence $results [lindex $arguments 0]] == 1 } {
			    #convert to plain text
			    set results [::htmlparse::mapEscapes $results]
			    ::amsn::MessageSend $window 0 $results
			    return
			}
			set results [musicsearchDilandau [lindex $arguments 0] [lindex $arguments 1]]
			if { [musicCheckCoincidence $results [lindex $arguments 0]] == 1 } {
			    #convert to plain text
			    set results [::htmlparse::mapEscapes $results]
			    ::amsn::MessageSend $window 0 $results
			    return
			}
			set results "$botname: [trans txtnoresults] [trans txtchangesearchwords]"
		    } else {
			set results "[trans txtcmderr]\n\
				    [trans txtcommand]: ![trans cmdsong]\n\
				    [trans txtprm]: [trans prmsong $::jake::config(nresultssongs)]\n\
				    [trans txtdsc]: [trans dscsong]\n\
				    [trans txtexl]: [trans exlsong]"
		    }

		    #print results
		    ::amsn::MessageSend $window 0 $results
	    } elseif { [string first "![trans cmdtranslate] " $msg] == 0 } {
		    set commandLength [expr [string length [trans cmdtranslate]] + 2]
		    set str [string range $msg $commandLength end]
		    set lngstartpos [string first " " $str]
		    set lng [string range $str 0 [expr $lngstartpos - 1]]
		    set txt [string range $str [expr $lngstartpos + 1] end]
		    set output [translateWithGoogle $lng $txt]
		    ::amsn::MessageSend $window 0 $output
	    } elseif { [string first "!envia " $msg] == 0 } {
		    #test
		    ::amsn::MessageSend $window 0 "Procesos separados lanzados!"
		    update
		    set url "http://www.google.com"
		    set text [getPage $url]
		    after 5000 [list ::amsn::MessageSend $window 0 $text]
	    } elseif { $user != $me && [isuseroff $chatid] == 0} {
		    if { [array exists dictionary] == 0 } {
			    source [file join $::HOME "jake" "dictionary.dic"]
		    }
		    set i 1
		    set j 0.6
		    foreach index [array names dictionary] {
			    if { [expr ([stringSimilarity $msg $index]) > $j] } {
				    #set j [expr ([stringSimilarity $msg $index])]
				    set respuesta($i) $dictionary($index)
				    incr i
			    }
		    }
		    if { $i > 1 } {
			    ::amsn::MessageSend $window 0 "$botname: $respuesta([rand [array size respuesta] 1])"
		    } else {
			    if { [rand 9 1] == 1 } {
				    ::amsn::MessageSend $window 0 "$botname: $::jake::config(helptxt)"
			    }
		    }
	    }
    }

    proc online {event epvar} {
	    upvar 2 $epvar args
	    set status $args(idx)
	    plugins_log "jake" "[trans txtchangestate] $status"
	    if { $status == "AWY" } {
		    plugins_log "jake" "Plugin Jake [trans txtlogactivated]"
		    set ::jake::config(mystate) 1
	    }
	    if { $status == "NLN" } {
		    plugins_log "jake" "Plugin Jake [trans txtlogdesactivated]"
		    set ::jake::config(mystate) 0
	    }
    }

}