Beispiel #1
0
 def handle(self, message):
     if message.startswith("load module "):
         ai_str = message[len("load module "):]
         try:
             ai_cls = aihandler.get_oneonone(ai_str)
         except aihandler.NoSuchAIError, e:
             self.ident.send(unicode(e))
         else:
             self.ident.set_AI(ai_cls(self.ident))
             self.ident.send(u"Success.")
         return
Beispiel #2
0
 def handle(self, message):
     if message.startswith("load module "):
         ai_str = message[12:]
         try:
             ai_class = aihandler.get_oneonone(ai_str)
         except aihandler.NoSuchAIError, e:
             self.ident.send(u"Failed to load module %s: %s" % (ai_str, e))
         else:
             new_ai = ai_class(self.ident)
             self.ident.set_AI(new_ai)
             self.ident.send(u"Great success!")
         return
Beispiel #3
0
    def run(self):
        """Take over the stdin and do nifty stuff... etc.

        This method is called as a seperate thread from the main script so it
        must be thread-safe.

        """
        c.stdout_block(USAGE)
        self.idnty.set_AI(aihandler.get_oneonone(self.def_AI)(self.idnty))
        try:
            while not self.halt:
                # The AI can change at run-time.
                ai = self.idnty.get_AI()
                ai.handle(c.stdin(u"<%s> " % self.idnty))
        except EOFError:
            c.stdout_block(u"\n")
Beispiel #4
0
 def handle_msg_chat(self, message):
     text = message.get_body()
     if text is None:
         # If there is no body do nothing at all (don't even call other
         # handlers). These messages are usually "... is typing"
         # notifications.
         return True
     sender = message.get_from()
     if sender in self._parties:
         peer = self._parties[sender]
     else:
         # This is the first message from this peer.
         peer = parties.Individual(sender, self.stream)
         def_AI = _conf.misc["default_ai"]
         peer.set_AI(aihandler.get_oneonone(def_AI)(peer))
         self._parties[sender] = peer
     _logger.debug(u"pm <- %s: %s", peer, text)
     peer.get_AI().handle(text)
     return True
Beispiel #5
0
    def _general_reply(self, message):
        """Tries to come up with a reply to this message without plugins.

        If no reply is found None is returned. Otherwise a unicode object is
        returned.

        """
        if __debug__:
            if not isinstance(message, unicode):
                raise TypeError, "Message must be a unicode object."
        message = message.strip()

        if message.startswith("load module "):
            ai_str = message[len("load module "):]
            try:
                self.party.set_AI(aihandler.get_oneonone(ai_str)(self.party))
            except aihandler.NoSuchAIError, e:
                return unicode(e)
            else:
                self._flush_plugins()
                return u"Success!"
Beispiel #6
0
 def _get_AI_class(self, name):
     return aihandler.get_oneonone(name)
Beispiel #7
0
    import threading as _threading
except ImportError:
    import dummy_threading as _threading
import time

import gobject
import pymsn

import aihandler
import config
from frontends import BaseConnection
from frontends.console.parties import Individual

_conf = config.get_conf_copy()
_def_ai_mom = aihandler.get_manyonmany(_conf.misc["default_ai"])
_def_ai_ooo = aihandler.get_oneonone(_conf.misc["default_ai"])
_logger = logging.getLogger("anna." + __name__)

def _log_call(func):
    """Decorator that logs a message before calling given function."""
    import itertools as i
    def n(*args, **kwargs):
        _logger.debug("%r(%s)", func, ", ".join(i.chain((repr(e) for e in
                args), ("%s=%r" % e for e in kwargs.iteritems()))))
        return func(*args, **kwargs)
    return n

def _log_meths(cls):
    """Create child-class that logs all calls to public methods."""
    class X(cls):
        pass