How to use the karmabot.thing.ThingFacet 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 / facets / bot.py View on Github external
from karmabot import client
from karmabot import thing
from karmabot import command

@thing.facet_classes.register
class KarmaBotFacet(thing.ThingFacet):
    name = "karmabot"
    
    @classmethod
    def does_attach(cls, thing):
        return thing.name == "karmabot"
        
    #TODO: add save/reload/quit commands, customizable messages and behavior
        
@thing.presenters.register(set(["karmabot", "name", "karma", "description"]))
def present(thing, context):
    text = u"{name}[v{version}]({karma}): {descriptions} ({things} things)".format(
        name         = thing.describe(context, facets=set(["name"])),
        karma        = thing.facets["karma"].karma,
        descriptions = thing.facets["description"].present(),
        version      = karmabot.VERSION,
        things       = context.bot.things.count
github chromakode / karmabot / karmabot / extensions / reddit.py View on Github external
# This file is part of 'karmabot' and is distributed under the BSD license.
# See LICENSE for more details.
import urllib

try:
    import json
except ImportError:
    import simplejson as json

from karmabot import thing
from karmabot import command
from karmabot.utils import Cache


@thing.facet_classes.register
class RedditorFacet(thing.ThingFacet):
    name = "redditor"
    commands = command.thing.add_child(command.FacetCommandSet(name))

    def __init__(self, thing_):
        thing.ThingFacet.__init__(self, thing_)
        self.get_info = Cache(self._get_info, expire_seconds=10 * 60)

    @classmethod
    def does_attach(cls, thing):
        return False

    @commands.add(u"forget that {thing} is a redditor",
                  help=u"unset {thing}'s reddit username",
                  exclusive=True)
    def unset_redditor(self, thing, context):
        del self.data
github chromakode / karmabot / karmabot / facets / name.py View on Github external
from karmabot import thing
from karmabot import command
from karmabot import ircutils 

@thing.facet_classes.register
class NameFacet(thing.ThingFacet):
    name = "name"    
    commands = command.thing.add_child(command.FacetCommandSet(name))
    
    @classmethod
    def does_attach(cls, thing):
        return True   
    
    @commands.add(u"{thing}\?*", help=u"show information about {thing}")
    def describe(self, thing, context):
        context.reply(thing.describe(context))

@thing.presenters.register(set(["name"]), order=-10)
def present(thing, context):
    return u"{name}".format(name = ircutils.bold(thing.name))
github chromakode / karmabot / karmabot / extensions / twitter.py View on Github external
# This file is part of 'karmabot' and is distributed under the BSD license.
# See LICENSE for more details.
import urllib
from xml.sax.saxutils import unescape as unescape_html

try:
    import json
except ImportError:
    import simplejson as json
    
from karmabot import thing
from karmabot import command
from karmabot.utils import Cache

@thing.facet_classes.register
class TwitterFacet(thing.ThingFacet):
    name = "twitter"
    commands = command.thing.add_child(command.FacetCommandSet(name))
    
    def __init__(self, thing_):
        thing.ThingFacet.__init__(self, thing_)
        self.get_info = Cache(self._get_info, expire_seconds=10*60)
    
    @classmethod
    def does_attach(cls, thing):
        return False
        
    @commands.add(u"forget that {thing} is on twitter",
                  help=u"unset {thing}'s twitter username",
                  exclusive=True)
    def unset_twitterer(self, thing, context):
        del self.data
github chromakode / karmabot / karmabot / extensions / eightball.py View on Github external
"Yes",
		"Yes - definitely",
		"You may rely on it",
		"Reply hazy, try again",
		"Ask again later",
		"Better not tell you now",
		"Cannot predict now",
		"Concentrate and ask again",
		"Don't count on it",
		"My reply is no",
		"My sources say no",
		"Outlook not so good",
		"Very doubtful"]

@thing.facet_classes.register
class EightBallFacet(thing.ThingFacet):
    name = "eightball"    
    commands = command.thing.add_child(command.FacetCommandSet(name))
    
    @classmethod
    def does_attach(cls, thing):
        return thing.name == "eightball"  
    
    @commands.add("shake {thing}", help="shake the magic eightball")
    def shake(self, thing, context):
        context.reply(random.choice(predictions) + ".")
github chromakode / karmabot / karmabot / extensions / github.py View on Github external
# See LICENSE for more details.
import urllib

try:
    import json
except ImportError:
    import simplejson as json

from karmabot.client import thing
from karmabot.thing import facet_classes, presenters, ThingFacet
from karmabot import command
from karmabot.utils import Cache


@facet_classes.register
class GitHubFacet(ThingFacet):
    name = "github"
    commands = command.thing.add_child(command.FacetCommandSet(name))

    def __init__(self, thing_):
        ThingFacet.__init__(self, thing_)
        self.get_info = Cache(self._get_info, expire_seconds=10 * 60)

    @classmethod
    def does_attach(cls, thing):
        return False

    @commands.add(u"forget that {thing} is on github",
                  help=u"unset {thing}'s github username",
                  exclusive=True)
    def unset_github_username(self, thing, context):
        del self.data