Commit 69d4af14 authored by Ralf's avatar Ralf

make communication with eliza work

parent cebf95e4
......@@ -433,7 +433,10 @@ sub command_interface {
print $self->botprompt if $self->prompts_on;
# Print an initial greeting
print "$self->{initial}->[ int &{$self->{myrand}}( scalar @{ $self->{initial} } ) ]\n";
#print "$self->{initial}->[ int &{$self->{myrand}}( scalar @{ $self->{initial} } ) ]\n";
select STDOUT;
$| = 1;
###################################################################
......
from npc import Npc
from util import read_timeout
import random
import subprocess
class Extern (Npc):
class DLevel(Npc.DialogLevel):
def __init__ (self,extern,wdir,binary):
super().__init__(extern)
self.proc = subprocess.Popen([binary], cwd=wdir, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
def analyzeAnswer(self, teller, verb, message):
return ("say", "hello", None)
self.proc.stdin.write(message.encode('utf-8')+b"\n")
self.proc.stdin.flush()
answer = read_timeout(self.proc.stdout, 512, 1.1).strip()
return ("say", "I am speachless." if answer is None else answer.decode('utf-8'), None)
def __del__(self):
self.proc.terminate()
def __init__(self,game,name,char,wdir,binary):
super().__init__(game, Extern.DLevel(self, wdir, binary))
......
import threading, traceback, sys
from datetime import datetime
from select import select
import os
# run a Python command asynchronously
def fire_and_forget(f):
......@@ -34,4 +35,4 @@ def log_file(file, *args, clock=False):
def read_timeout(file, size, time):
r, w, x = select([file], [], [], time)
if not r: return None
return file.read(size)
return os.read(file.fileno(), size) # read MAX size, not block until we get that much
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment