rendered paste body#!/usr/bin/tclsh
set dobry "wine dobry.exe"
set msg "chat.msg"
set tmp "/tmp/dobry"
set botname "Dobry"
set mind "dobry.mdd"
set learning 1
proc WriteToMind {ai line} {
global mind botname name learning
if {!$learning} return
set fs [open $mind a]
if {$ai} {
set _ai "<ai>"
} else {
set _ai "$name"
}
puts -nonewline $fs "$name [clock seconds] $_ai [Strip $line]\r\n"
close $fs
}
proc GetOutput {} {
global dobry msg tmp
catch {eval exec $dobry} error
set fs [open $msg r]
set da [read $fs]
close $fs
file delete $msg
return $da
}
proc Strip {l} {
return [string map [list "\r" "" "\n" ""] $l]
}
proc CreateFile {name line} {
global msg
set fs [open $msg w]
puts -nonewline $fs "${name}\r\n${line}\r\n"
close $fs
}
proc Prompt {} {
global name
puts -nonewline "<${name}> "
flush stdout
gets stdin input
WriteToMind 0 $input
return $input
}
proc Start {} {
global name botname
puts -nonewline "Your name: "
flush stdout
gets stdin name
while {1} {
set in [Prompt]
CreateFile $name $in
set out [GetOutput]
WriteToMind 1 $out
puts "<${botname}> [Strip $out]"
}
}
Start