How to use the karmabot.core.register.facet_registry function in karmabot

To help you get started, we’ve selected a few karmabot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chromakode / karmabot / karmabot / core / facets / irc.py View on Github external
# Copyright the Karmabot authors and contributors.
# All rights reserved.  See AUTHORS.
#
# This file is part of 'karmabot' and is distributed under the BSD license.
# See LICENSE for more details.
from karmabot.core.client import thing, listen
from karmabot.core.commands.sets import CommandSet
from karmabot.core.thing import ThingFacet
from karmabot.core.register import facet_registry, presenter_registry


@facet_registry.register
class IRCChannelFacet(ThingFacet):
    name = "ircchannel"
    commands = thing.add_child(CommandSet(name))

    @classmethod
    def does_attach(cls, thing):
        return thing.name.startswith("#")

    @commands.add(u"join {thing}", help_str=u"join the channel {thing}")
    def join(self, thing, context):
        context.bot.join_with_key(thing.name.encode("utf-8"))

    @commands.add(u"leave {thing}", help_str=u"leave the channel {thing}")
    def leave(self, thing, context):
        channel = thing.name.encode("utf-8")
        context.reply("Bye!", where=channel)
github chromakode / karmabot / karmabot / core / subject.py View on Github external
def __init__(self, key, name):
        self.key = key
        self.name = name
        self.data = {"name": name,
                     "+facets": [],
                     "-facets": []}
        self.facets = {}
        facet_registry.attach(self, set(self.data["-facets"]))
github chromakode / karmabot / karmabot / core / subject.py View on Github external
def add_facet(self, facet):
        if str(facet) in self.facets:
            return
        if isinstance(facet, str):
            facet = facet_registry[facet](self)
        self.facets[str(facet)] = facet