Пример #1
0
    def _highlight(self, message, sender):
        """This is for when highlighted in a groupchat.

        @param message: The received message (without highlight-prefix).
        @type message: C{unicode}
        @param sender: The group member that sent the message.
        @type sender: L{frontends.BaseGroupMember}

        """
        if __debug__:
            if not isinstance(message, unicode):
                raise TypeError, "Message must be unicode."
            if not isinstance(sender, frontends.BaseGroupMember):
                raise TypeError, "Sender must be a GroupMember."
        reply = None

        res = self._rex_nickchange.match(message)
        if res is not None:
            self.room.set_mynick(res.group(1))
            reply = u"k."
        elif re.match(u"((please )?leave)|(exit)$", message, re.I) is not None:
            self.room.send(u"... :'(")
            self.room.leave()
            return
        elif message.startswith("load module "):
            ai_name = message[len("load module "):]
            try:
                self.room.set_AI(aihandler.get_manyonmany(ai_name)(self.room))
            except aihandler.NoSuchAIError, e:
                reply = unicode(e)
            else:
                self._flush_plugins()
                reply = u"success!"
Пример #2
0
Файл: echo.py Проект: maffe/anna
 def handle(self, message, sender):
     if sender.nick.lower() == self.room.get_mynick().lower():
         _logger.warning("Interpreting messages from myself.")
         return
     if message.startswith("load module "):
         ai_str = message[len("load module "):]
         try:
             ai_cls = aihandler.get_manyonmany(ai_str)
         except aihandler.NoSuchAIError, e:
             self.room.send(unicode(e))
         else:
             self.room.set_AI(ai_cls(self.room))
             self.room.send(u"Success.")
         return
Пример #3
0
 def handle(self, message, sender):
     if message == "fishbot, part":
         self.room.leave()
         return
     elif message == "fishbot, uptime":
         diff = stats.uptimeSecs()
         self.room.send(u'Uptime: %d seconds. gnarf!' % diff)
         return
     elif message.startswith("load module "):
         ai_str = message[12:]
         try:
             ai_class = aihandler.get_manyonmany(ai_str)
         except aihandler.NoSuchAIError, e:
             self.room.send(u"Failed to load module %s: %s" % (ai_str, e))
         else:
             new_ai = ai_class(self.room)
             self.room.set_AI(new_ai)
             self.room.send(u"Great success!")
         return
Пример #4
0
 def _get_AI_class(self, name):
     return aihandler.get_manyonmany(name)
Пример #5
0
try:
    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):