mirror of
https://github.com/MarkParker5/STARK.git
synced 2024-11-24 08:12:13 +02:00
add decorator for creating commands
This commit is contained in:
parent
deb828324f
commit
a5c488f1a5
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,3 +12,5 @@ __pycache__
|
||||
/config.py
|
||||
/tts-gc-key.json
|
||||
/logs.txt
|
||||
|
||||
audio/
|
||||
|
@ -225,13 +225,21 @@ class Command(ABC):
|
||||
'params': {'string':string,},
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
@staticmethod #TODO: pass Response instead of answer and voice; create ThreadData struct
|
||||
def background(answer = '', voice = ''): # make background cmd
|
||||
def decorator(cmd): #wrapper of wrapper (decorator of decorator)
|
||||
def decorator(func): #wrapper of wrapper (decorator of decorator)
|
||||
def wrapper(text):
|
||||
finish_event = Event()
|
||||
thread = RThread(target=cmd, args=(text, finish_event))
|
||||
thread = RThread(target=func, args=(text, finish_event))
|
||||
thread.start()
|
||||
return Response(voice = voice, text = answer, thread = {'thread': thread, 'finish_event': finish_event} )
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
@classmethod
|
||||
def new(cls, *args, **kwargs):
|
||||
def creator(func):
|
||||
cmd: Command = cls(*args, **kwargs)
|
||||
cmd.setStart(func)
|
||||
return func
|
||||
return creator
|
||||
|
@ -1,10 +1,8 @@
|
||||
from .SmallTalk import *
|
||||
from ..Command import Response
|
||||
################################################################################
|
||||
|
||||
@SmallTalk.new('Hello', patterns = ['* привет* *',])
|
||||
def method(params):
|
||||
voice = text = 'Привет'
|
||||
return Response(text = text, voice = voice)
|
||||
|
||||
patterns = ['* привет* *',]
|
||||
hello = SmallTalk('Hello', {}, patterns)
|
||||
hello.setStart(method)
|
||||
|
Loading…
Reference in New Issue
Block a user