46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
import logging
|
|
from ast import literal_eval
|
|
|
|
from tfw.components.frontend import MessageSender
|
|
from tfw.components.terminal import TerminalCommandsHandler
|
|
from tfw.main import TFWUplinkConnector
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class CenatorHandler:
|
|
keys = ['history.bash']
|
|
|
|
def handle_event(self, message, server_connector): # pylint: disable=no-self-use
|
|
command = message['value']
|
|
LOG.debug('User executed command: "%s"', command)
|
|
MessageSender(server_connector).send('JOHN CENA', f'You\'ve executed "{command}"')
|
|
|
|
|
|
class TestCommandsHandler(TerminalCommandsHandler):
|
|
# pylint: disable=unused-argument,attribute-defined-outside-init,no-self-use
|
|
def command_sendmessage(self, *args):
|
|
if not args:
|
|
message_template = """'{"key": "", "data": {"command": ""}}'"""
|
|
TFWUplinkConnector().send_message({
|
|
'key': 'shell',
|
|
'data': {
|
|
'command': 'write',
|
|
'value': f'sendmessage {message_template}'
|
|
}
|
|
})
|
|
else:
|
|
TFWUplinkConnector().send_message(literal_eval(args[0]))
|
|
|
|
|
|
def messageFSMStepsHandler(message, server_connector):
|
|
"""
|
|
When the FSM steps this method is invoked.
|
|
Receives a 'data' field from an fsm_update message as kwargs.
|
|
"""
|
|
MessageSender(server_connector).send(
|
|
'FSM info',
|
|
f'FSM has stepped from state "{message["last_event"]["from_state"]}" '
|
|
f'to state "{message["current_state"]}" in response to trigger "{message["last_event"]["trigger"]}"'
|
|
)
|