Example #1
0
class YobotServerService(YobotServiceBase):
    def _initvars(self):
        YobotServiceBase._initvars(self)
        #should eventually be something that lets us hook up with libpurple
        self.prpl_server = PurpleQueue()
        #clients[cid] = <YobotServer>
        self.clients = {}
        self.requests = {} # requests[reqid] -> client_object
        self.accounts = AccountManager()
        self.logger = MessageLogger()
        self._purple_initvars()
        
    def __init__(self):
        self._initvars()
        def logTimer():
            self.logger.commit()
            reactor.callLater(45, logTimer)
        reactor.callLater(45, logTimer)
    """
    Common data available to all instances and services.
    What this actually means is that the IPC connection to libpurple as
    well as the individual clients connected to our server will be able to
    use a single pool of data defined here
    """
    
    def logHelper(self, obj):
        msg = obj.msg
        who, txt = (msg.who, msg.txt)
        txt = txt if txt else ""
        who = who if who else msg.name
        
        msgtype = None
        if msg.commflags &  yobotproto.YOBOT_MSG_TYPE_CHAT:
            msgtype = CONV_TYPE_CHAT
        elif msg.commflags & yobotproto.YOBOT_MSG_TYPE_IM:
            msgtype = CONV_TYPE_IM
        if not msgtype:
            return #system message, don't need to log it...
        
        #get account info:
        #FIXME: hack.. might want to see what purple does with its usersplit thingy
        acct, _ = self.accounts.byId(msg.acctid)
        if acct.improto == yobotproto.YOBOT_JABBER:
            name = msg.name.split("/", 1)[0]
        else:
            name = msg.name
        
        try:
            self.logger.logMsg(msgtype, acct.user, yobotops.imprototostr(acct.improto),
                               name, msg.txt, who, msg.time)
        except msglogger.IntegrityError, e:
            log_err(e)
Example #2
0
 def _initvars(self):
     YobotServiceBase._initvars(self)
     #should eventually be something that lets us hook up with libpurple
     self.prpl_server = PurpleQueue()
     #clients[cid] = <YobotServer>
     self.clients = {}
     self.requests = {} # requests[reqid] -> client_object
     self.accounts = AccountManager()
     self.logger = MessageLogger()
     self._purple_initvars()