mirror of
				https://github.com/avatao-content/test-tutorial-framework
				synced 2025-10-31 15:32:55 +00:00 
			
		
		
		
	Add message sender pipe
This commit is contained in:
		| @@ -24,7 +24,7 @@ class SignMessagePipeIOEventHandler(PipeIOEventHandlerBase): | |||||||
|         super().__init__(None, in_pipe_path, out_pipe_path, permissions) |         super().__init__(None, in_pipe_path, out_pipe_path, permissions) | ||||||
|  |  | ||||||
|     def handle_event(self, message): |     def handle_event(self, message): | ||||||
|         return |         pass | ||||||
|  |  | ||||||
|     def handle_pipe_event(self, message_bytes): |     def handle_pipe_event(self, message_bytes): | ||||||
|         message = loads(message_bytes) |         message = loads(message_bytes) | ||||||
| @@ -46,7 +46,7 @@ class VerifyMessagePipeIOEventHandler(PipeIOEventHandlerBase): | |||||||
|         super().__init__(None, in_pipe_path, out_pipe_path, permissions) |         super().__init__(None, in_pipe_path, out_pipe_path, permissions) | ||||||
|  |  | ||||||
|     def handle_event(self, message): |     def handle_event(self, message): | ||||||
|         return |         pass | ||||||
|  |  | ||||||
|     def handle_pipe_event(self, message_bytes): |     def handle_pipe_event(self, message_bytes): | ||||||
|         message = loads(message_bytes) |         message = loads(message_bytes) | ||||||
| @@ -54,6 +54,43 @@ class VerifyMessagePipeIOEventHandler(PipeIOEventHandlerBase): | |||||||
|         self.pipe_io.send_message(str(validity).lower().encode()) |         self.pipe_io.send_message(str(validity).lower().encode()) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class BotPipeIOEventHandler(PipeIOEventHandlerBase): | ||||||
|  |     """ | ||||||
|  |     Sends bot messages to the frontend. | ||||||
|  |     If you assign @originator, it will be the default message sender. | ||||||
|  |     When you write a line to the pipe, it will be considered as a single | ||||||
|  |     message and gets appended to the queue until an empty line is received, | ||||||
|  |     which triggers forwarding the messages to the TFW server. | ||||||
|  |     """ | ||||||
|  |  | ||||||
|  |     def __init__( | ||||||
|  |             self, in_pipe_path, out_pipe_path, permissions=DEFAULT_PERMISSIONS, | ||||||
|  |             originator='avataobot' | ||||||
|  |     ): | ||||||
|  |         self.queue = [] | ||||||
|  |         self.originator = originator | ||||||
|  |         super().__init__(None, in_pipe_path, out_pipe_path, permissions) | ||||||
|  |  | ||||||
|  |     def handle_event(self, message): | ||||||
|  |         pass | ||||||
|  |  | ||||||
|  |     def handle_pipe_event(self, message_bytes): | ||||||
|  |         if message_bytes == b"": | ||||||
|  |             if self.queue: | ||||||
|  |                 self.server_connector.send({ | ||||||
|  |                     'key': 'queueMessages', | ||||||
|  |                     'data': { | ||||||
|  |                         'messages': self.queue | ||||||
|  |                     } | ||||||
|  |                 }) | ||||||
|  |                 self.queue = [] | ||||||
|  |         else: | ||||||
|  |             self.queue.append({ | ||||||
|  |                 'originator': self.originator, | ||||||
|  |                 'message': message_bytes.decode().replace('\\n', '\n') | ||||||
|  |             }) | ||||||
|  |  | ||||||
|  |  | ||||||
| class DeployPipeIOEventHandler(PipeIOEventHandlerBase): | class DeployPipeIOEventHandler(PipeIOEventHandlerBase): | ||||||
|     """ |     """ | ||||||
|     Manages deployment in the IDE. |     Manages deployment in the IDE. | ||||||
|   | |||||||
| @@ -7,13 +7,14 @@ from tfw.components import PipeIOEventHandler | |||||||
|  |  | ||||||
| from pipe_io_auxlib import ( | from pipe_io_auxlib import ( | ||||||
|         SignMessagePipeIOEventHandler, VerifyMessagePipeIOEventHandler, |         SignMessagePipeIOEventHandler, VerifyMessagePipeIOEventHandler, | ||||||
|  |         BotPipeIOEventHandler, | ||||||
|         DeployPipeIOEventHandler, IdePipeIOEventHandler, |         DeployPipeIOEventHandler, IdePipeIOEventHandler, | ||||||
|         FSMPipeIOEventHandler |         FSMPipeIOEventHandler | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|     ''' |     """ | ||||||
|     Creates general purpose pipes. |     Creates general purpose pipes. | ||||||
|     The first parameter associates the receiving pipe with a key, which is |     The first parameter associates the receiving pipe with a key, which is | ||||||
|     an empty string in this case. It has a special meaning, you can |     an empty string in this case. It has a special meaning, you can | ||||||
| @@ -23,7 +24,7 @@ if __name__ == '__main__': | |||||||
|     You can send/receive JSON messages to/from the TFW server as any user, |     You can send/receive JSON messages to/from the TFW server as any user, | ||||||
|     because we gave read+write permissions, without that parameter, only |     because we gave read+write permissions, without that parameter, only | ||||||
|     the owner has access to the pipes. |     the owner has access to the pipes. | ||||||
|     ''' |     """ | ||||||
|     json_pipe = PipeIOEventHandler( |     json_pipe = PipeIOEventHandler( | ||||||
|         '', |         '', | ||||||
|         '/tmp/tfw_json_send', |         '/tmp/tfw_json_send', | ||||||
| @@ -42,6 +43,11 @@ if __name__ == '__main__': | |||||||
|         '/tmp/tfw_verify_recv' |         '/tmp/tfw_verify_recv' | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |     bot_pipe = BotPipeIOEventHandler( | ||||||
|  |         '/tmp/tfw_bot_send', | ||||||
|  |         '/tmp/tfw_bot_recv' | ||||||
|  |     ) | ||||||
|  |  | ||||||
|     deploy_pipe = DeployPipeIOEventHandler( |     deploy_pipe = DeployPipeIOEventHandler( | ||||||
|         '/tmp/tfw_deploy_send', |         '/tmp/tfw_deploy_send', | ||||||
|         '/tmp/tfw_deploy_recv', |         '/tmp/tfw_deploy_recv', | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user