Exemplo n.º 1
0
Arquivo: plugin.py Projeto: maffe/anna
 def __init__(self, party, args):
     self._party = party
     # Functions to apply to incoming messages subsequently.
     self._msg_parsers = (
             self._handle_annoy,
             self._handle_fetch,
             self._handle_add,
             self._handle_delete,
             )
     # Create the database if it doesn't exist.
     db_uri = config.get_conf_copy().factoids_plugin["db_uri"]
     self._engine = sa.create_engine(db_uri)#, echo=True)
     self._md = sa.MetaData()
     self._table = sa.Table("factoid", self._md, 
             sa.Column("factoid_id", sa.Integer, primary_key=True),
             sa.Column("numreq", sa.Integer, sa.PassiveDefault('0'),
                 nullable=False),
             sa.Column("object", sa.String(512), nullable=False,
                 unique=True),
             sa.Column("definition", sa.String(512), nullable=False),
             )
     self._md.bind = self._engine
     self._md.create_all(self._engine)
     # Seconds between subsequent calls to _annoy()
     self._aintrv = 300
     # Lock must be acquired before manipulating the annoy timer.
     self._annoy_lock = _threading.Lock()
Exemplo n.º 2
0
 def _get_AI_list(self):
     """Get a textual list of available AIs."""
     def_ai = config.get_conf_copy().misc["default_ai"]
     ais = []
     for name in aihandler.get_names():
         if name.lower() == def_ai.lower():
             name = u" ".join((name, "(default)"))
         ais.append(u"- %s\n" % name)
     return CHOOSE_AI % u"".join(ais).strip()
Exemplo n.º 3
0
 def handle(self, message, sender=None):
     """If the message is a valid AI name, load that, otherwise: retry."""
     def_ai = config.get_conf_copy().misc["default_ai"]
     message = message.strip()
     if message == "":
         message = def_ai
     elif message.endswith(" (default)"):
         # If the user thought " (default)" was part of the name, strip.
         message = message[:-len(" (default)")]
     try:
         self.party.set_AI(self._get_AI_class(message)(self.party))
     except aihandler.NoSuchAIError, e:
         self.party.send(u"\n".join((unicode(e), u"Please try again.",
             self._get_AI_list())))
Exemplo n.º 4
0
Arquivo: agenda.py Projeto: maffe/anna
 def __init__(self, party, args):
     if len(args) != 1:
         raise PluginError, u"Usage: load plugin agenda <namespace>"
     self.namespace = args[0].lower()
     db_uri = config.get_conf_copy().agenda_plugin["db_uri"]
     self._engine = sa.create_engine(db_uri)
     self._md = sa.MetaData(self._engine)
     self._table = sa.Table("agenda", self._md, 
             sa.Column("id", sa.Integer, primary_key=True),
             sa.Column("date", sa.DateTime),
             sa.Column("event", sa.Text),
             sa.Column("namespace", sa.String(50))
             )
     self._md.create_all(self._engine)
Exemplo n.º 5
0
Arquivo: plugin.py Projeto: maffe/anna
 def _prepare_db(self):
     # Create the database if it doesn't exist.
     db_uri = config.get_conf_copy().reactions_plugin["db_uri"]
     self._engine = sa.create_engine(db_uri)#, echo=True)
     self._md = sa.MetaData()
     self._table = sa.Table("reaction", self._md, 
             sa.Column("reaction_id", sa.Integer, primary_key=True),
             sa.Column("numreq", sa.Integer, sa.PassiveDefault('0'),
                 nullable=False),
             sa.Column("type", sa.Integer, nullable=False),
             # TODO: The hook is not unique because there can be two. A real
             # constraint should be formulated, though.
             sa.Column("hook", sa.String(512), nullable=False),
             sa.Column("reaction", sa.String(512), nullable=False),
             )
     self._md.bind = self._engine
     self._md.create_all(self._engine)
Exemplo n.º 6
0
def start():
    """Perform all actions needed to make the module ready for use.

    Loads and stores the references to plugin modules and populates the
    _name_map dictionary.

    Note; it is important not to catch any exceptions this function raises
    because it does not release the import lock when failing. Besides, failure
    of this function indicates something is terribly wrong anyway.

    """
    global _start_lock, _refs
    if not _start_lock.acquire(False):
        return False
    name_map = config.get_conf_copy().annai_plugins["names"]
    for name in name_map:
        assert(name not in _refs)
        _refs[name_map[name]] = getattr(__import__("ai.annai.plugins",
            globals(), locals(), fromlist=[name.encode("us-ascii")]), name)
Exemplo n.º 7
0
You can see the list of participants by saying "names".

More information on U{the wiki
<https://0brg.net/anna/wiki/Mucproxy_plugin>}.

"""
try:
    import threading as _threading
except ImportError:
    import dummy_threading as _threading
import time

import config
from ai.annai.plugins import BasePlugin, PluginError

_conf = config.get_conf_copy()
# Always acquire _room_lock before doing ANYTHING with _rooms.
_room_lock = _threading.Lock()
_rooms = {}

class _Plugin(BasePlugin):
    def __init__(self, identity, args):
        if len(args) != 2:
            raise PluginError(u'Illegal syntax, see "about plugin mucproxy".')
        assert(isinstance(args[0], unicode))
        assert(isinstance(args[1], unicode))
        if u":" in args[1]:
            raise PluginError(u"Nickname may not contain colons (:).")
        self._identity = identity
        self._mucname = args[0]
        self._peername = args[1]
Exemplo n.º 8
0
def init():
    """Make this module ready for use."""
    global _conf
    _conf = config.get_conf_copy()
Exemplo n.º 9
0
 def __init__(self):
     _threading.Thread.__init__(self, name="console frontend")
     self.idnty = Individual(getpass.getuser())
     self.def_AI = config.get_conf_copy().misc["default_ai"]