Example #1
0
def get_message(sock, settings, state):

    """
    Read a message from the IRC connection, simulaneously making sure
    to keep the connection alive and handling the IRC statey business.
    Returns the message, perhaps with convenience information attached.

    """

    raw_message = network.read(sock)

    if raw_message:
        message = from_raw(raw_message)
        response = manage(message, settings, state)
        if response:
            send_message(sock, response)
        elif message.command == 'PRIVMSG':
            return message

        return None

    if settings.channel != state.joined:
        if state.joined:
            send_message(sock, Message.part(state.joined))
        send_message(sock, Message.join(settings.channel))
        return None