<commit_before>#!/usr/bin/python3
"""Chat engine using CommChannel class."""
import web.web_config as config
from web.channel import CommChannel
from web.message import Message # for assertion

CHAT_SIGNATURE = ['msg']


class ChatEngine(CommChannel):
    """Chat engine implementation."""
    def __init__(self):
        CommChannel.__init__(self)

    ## Overriden members.
    def register(self, server):
        """Register ChatEngine as announce and responder to the server.

        Use announce mode to multi-cast chat message to other parties in room.

        Use respond mode to acknowledge receipt of message and order client to
        self-publish message (??? is this desirable???)

        """
        server.add_responder(self, CHAT_SIGNATURE)
        server.add_announcer(self)        

    def respond(self, incoming_msg):
        """Handle incoming chat message.

        Package chat message into Message with other game members
        as recipients.

        incoming_msg (Message): chat message with source and msg data
        
        """
        assert isinstance(incoming_msg, Message)

        # Extract chat message from Message object
        chat = incoming_msg.data.get('msg', "")

        # Get GUIDs of clients in chat room
        ##contact game router using incoming_msg.source to get
        ## need internal reference to game router, or means of
        ## registering channels to the router a la web server
        ### should return list
        recipients = [incoming_msg.source] #for testing purposes

        # Package into Message and notify the server
        msg_data = {'dest':recipients, 'msg':chat}  #rework Message.py to avoid this jankiness
        msg = Message(msg_data, dest_key='dest')
        self.announce(msg)

        # No error conditions exist for chat, so return None
        return None<commit_msg>Put output into compliance with docs.<commit_after>#!/usr/bin/python3
"""Chat engine using CommChannel class."""
import web.web_config as config
from web.channel import CommChannel
from web.message import Message # for assertion

CHAT_SIGNATURE = ['msg']


class ChatEngine(CommChannel):
    """Chat engine implementation."""
    def __init__(self):
        CommChannel.__init__(self)

    ## Overriden members.
    def register(self, server):
        """Register ChatEngine as announce and responder to the server.

        Use announce mode to multi-cast chat message to other parties in room.

        Use respond mode to acknowledge receipt of message and order client to
        self-publish message (??? is this desirable???)

        """
        server.add_responder(self, CHAT_SIGNATURE)
        server.add_announcer(self)        

    def respond(self, incoming_msg):
        """Handle incoming chat message.

        Package chat message into Message with other game members
        as recipients.

        incoming_msg (Message): chat message with source and msg data
        
        """
        assert isinstance(incoming_msg, Message)

        # Extract chat message from Message object
        chat = incoming_msg.data.get('msg', "")

        # Get GUIDs of clients in chat room
        ##contact game router using incoming_msg.source to get
        ## need internal reference to game router, or means of
        ## registering channels to the router a la web server
        ### should return list
        recipients = [incoming_msg.source] #for testing purposes

        # Package into Message and notify the server
        msg_data = {'source': incoming_msg.source,
                    'dest':recipients,
                    'uNum':999, 'msg':chat}  #rework Message.py to avoid this jankiness
        msg = Message(msg_data, source_key='source', dest_key='dest')
        self.announce(msg)

        # No error conditions exist for chat, so return None
        return None
{'fraction_non_alphanumeric': 0.07796257796257797, 'fraction_numerical': 0.0012993762993762994, 'mean_word_length': 2.6448863636363638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3700232', 'n_tokens_mistral': 982, 'n_tokens_neox': 940, 'n_words': 378}