CactusDev / CactusBot

An open source, community-written service-agnostic chat bot
MIT License
30 stars 5 forks source link

Handler system #44

Closed 2Cubed closed 7 years ago

2Cubed commented 8 years ago

A class for all handlers to inherit from. Uses on_ methods for event handling.

Innectic commented 8 years ago

This was finished on the feature/handlers branch.

2Cubed commented 8 years ago

Currently empty. Need to add content, which will be possible once #43 is complete.

Innectic commented 8 years ago

@2Cubed I thought you said nothing needed to be added as of now?

2Cubed commented 8 years ago

@Innectic Correct, but we shouldn't close the issue until we've actually added the things.

Something we should add, though, is a built-in logger.

import logging

class Handler(object):
    """Abstract handler."""

    def __init__(self):
        self.logger = logging.getLogger(__name__)

class PotatoHandler(object):
    def on_potato(self, potato):
        self.logger.debug("We got a potato! (%s)", potato)
Innectic commented 8 years ago

@2Cubed I'll make that a thing real fast.

Innectic commented 8 years ago

@2Cubed Done in commit: 32d878aed050bdf502b9980f380370d1e620bbd6

2Cubed commented 8 years ago

@Innectic Whoa, nice! Only complaint is this:

    def on_message(self, packet):
        """Handle message events."""
        self.logger.debug(packet)
        self.logger.info(
            ''.join(chunk["text"] for chunk in packet if chunk["type"] == chunk["text"])
        )

IMHO, we should keep the LoggingHandler (#48) and move those logging statements there.

Innectic commented 8 years ago

@2Cubed I don't see any use to keeping the logging handler if Handler contains a logger. Maybe you can prove me wrong?

2Cubed commented 8 years ago

What else might this need? Currently, it's essentially an empty class.

Innectic commented 8 years ago

I'm not sure if anything is needed in there, at the moment.

2Cubed commented 8 years ago

@Innectic Yeah, me neither. I feel like there should be something, but... :thinking:

Innectic commented 8 years ago

@2Cubed I think we could close this.

2Cubed commented 8 years ago

@Innectic Renamed to Handler system, because that's a much better description of what this issue is for.

2Cubed commented 7 years ago

Completed on feature/handlers branch, merged in #81.