You've already forked STARK
mirror of
https://github.com/MarkParker5/STARK.git
synced 2025-11-23 21:34:45 +02:00
add Response class, recursive voice assistant algorithm
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
from .Command import Command
|
||||
from .Response import Response
|
||||
import re
|
||||
|
||||
class Callback:
|
||||
def __init__(this, patterns):
|
||||
def __init__(this, patterns, quiet = False, once = True):
|
||||
this.patterns = patterns
|
||||
this.quiet = quiet
|
||||
this.once = once
|
||||
|
||||
def setStart(this, function):
|
||||
this.start = function
|
||||
@@ -14,5 +17,16 @@ class Callback:
|
||||
def answer(this, string):
|
||||
for pattern in this.patterns:
|
||||
if match := re.search(re.compile(Command.compilePattern(pattern)), string):
|
||||
return this.start({**match.groupdict(), 'string':string})
|
||||
return this.start({**match.groupdict(), 'string':string})
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def background(answer = '', voice = ''):
|
||||
def decorator(cmd):
|
||||
def wrapper(text):
|
||||
finish_event = Event()
|
||||
thread = RThread(target=cmd, args=(text, finish_event))
|
||||
thread.start()
|
||||
return Response(voice = voice, text = answer, thread = {'thread': thread, 'finish_event': finish_event} )
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
@@ -252,14 +252,6 @@ class Command(ABC):
|
||||
finish_event = Event()
|
||||
thread = RThread(target=cmd, args=(text, finish_event))
|
||||
thread.start()
|
||||
return {
|
||||
'type': 'background',
|
||||
'text': answer,
|
||||
'voice': voice,
|
||||
'thread': {
|
||||
'thread': thread,
|
||||
'finish_event': finish_event,
|
||||
}
|
||||
}
|
||||
return Response(voice = voice, text = answer, thread = {'thread': thread, 'finish_event': finish_event} )
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
6
Command/Response.py
Normal file
6
Command/Response.py
Normal file
@@ -0,0 +1,6 @@
|
||||
class Response:
|
||||
def __init__(this, voice, text, callback = None, thread = None):
|
||||
this.voice: str = voice
|
||||
this.text: str = text
|
||||
this.callback: Callback = callback
|
||||
this.thread = thread
|
||||
@@ -1,2 +1,3 @@
|
||||
from .Command import *
|
||||
from .Callback import *
|
||||
from .Response import *
|
||||
|
||||
Reference in New Issue
Block a user