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)
def logRetriever(self, obj, proto): "A backlog request handler" #lookup account name.. acct, _ = self.accounts.byId(obj.cmd.acctid) other_user, count = obj.cmd.data.split(str(yobotproto.YOBOT_TEXT_DELIM)) count = int(count) for msg in self.logger.getMsgs(acct.name, yobotops.imprototostr(acct.improto), other_user, count=count): msg.yprotoflags |= yobotproto.YOBOT_BACKLOG msg.acctid = obj.cmd.acctid proto.sendSegment(msg)
def accept(self): #validate input.. #load the variables first.. w = self.widgets name, password = w.username.text(), w.password.text() improto = yobotops.imprototostr(w.improto.itemData(w.improto.currentIndex()).toPyObject()) log_debug("improto is", improto) use_proxy = w.use_proxy.isChecked() proxy_username, proxy_password, proxy_address, proxy_port = ( w.proxy_username.text(), w.proxy_password.text(), w.proxy_address.text(), w.proxy_port.text()) proxy_type = w.proxy_type.currentText() autoconnect = w.autoconnect.isChecked() err = False while not err: if not name or not password: err = "username and password required" break if use_proxy: if not proxy_address or not proxy_port: err = "proxy requested but no port:address specified" break if (proxy_password and not proxy_username) or ( proxy_username and not proxy_password): err = "username and password must be specified together" break break if err: QErrorMessage(self).showMessage(err) return a = { "name":str(name), "password":str(password), "improto":str(improto), "autoconnect":bool(autoconnect), "use_proxy":bool(use_proxy), "proxy_params": { "proxy_type":str(proxy_type), "proxy_address":str(proxy_address), "proxy_port":str(proxy_port), "proxy_username":str(proxy_username), "proxy_password":str(proxy_password), } } QDialog.accept(self) self.values = a
def relayOfflines(self, obj, proto): acct, _ = self.accounts.byId(obj.cmd.acctid) if not acct: log_err("account is none") return if not acct.lastClientDisconnected: log_info("not relaying offlines while other clients are still connected") return for msg in self.logger.getMsgs(acct.name, yobotops.imprototostr(acct.improto), timerange = (acct.lastClientDisconnected, time.time()), count=0): msg.acctid = obj.cmd.acctid msg.yprotoflags |= (yobotproto.YOBOT_BACKLOG|yobotproto.YOBOT_OFFLINE_MSG) proto.sendSegment(msg) print msg self.logger.dump() log_warn("done") log_info(acct.lastClientDisconnected) acct.lastClientDisconnected = 0
def __init__(self, mkaccti=None, user=None, passw=None, id=None, improto=None, proxy_host = None, proxy_port = None, proxy_username = None, proxy_password = None, proxy_type = None): self._initvars() if mkaccti is not None: self._improto = mkaccti.yomkacct.improto self._user = mkaccti.user self._passw = mkaccti._pass self._id = mkaccti.yomkacct.id #no need for anything here to parse proxy information.. else: self._improto = improto self._user = user self._passw = passw self._id = id self._proxy_host = proxy_host self._proxy_username = proxy_username self._proxy_password = proxy_password self._proxy_port = proxy_port self._proxy_type = proxy_type if not yobotops.imprototostr(self._improto): raise IMUnsupportedProtocol(self._improto)
def __str__(self): return "Account: name=%s protocol=%s" % (self.user,yobotops.imprototostr(self.improto))
a["recent_contacts"] = RingBuffer(25, a["recent_contacts"][:]) if a.get("recent_chats", []): a["recent_chats"] = RingBuffer(25, a["recent_chats"][:]) def get_account(self, acctobj, autoadd=False): """Return a config entry with the improto and name of this account object""" #first try the cache.. try: ret = self.account_lookup_cache[acctobj] #log_err(ret) return ret except KeyError, e: pass #log_debug("account not in cache yet..", self.account_lookup_cache, e) for a in self.accounts: if a["name"] == acctobj.name and a["improto"] == yobotops.imprototostr(acctobj.improto): self.account_lookup_cache[acctobj] = a #log_debug("added account %s to cache, calling again", a) return self.get_account(acctobj, autoadd) if autoadd: d = {"name":acctobj.name, "improto":yobotops.imprototostr(acctobj.improto), "password":"", "autoconnect": False } self.accounts.append(d) self.account_lookup_cache[acctobj] = d return self.get_account(acctobj, autoadd=False) else: return {}
try: import cPickle as pickle plain, htmlescaped = pickle.load(open("/tmp/.yobot_smileys_cached.pickle", "r")) print "imported from pickle" except Exception, e: print e gensmileys() try: pickle.dump((plain, htmlescaped), open("/tmp/.yobot_smileys_cached.pickle", "w")) except Exception, e: print e #gensmileys() if __name__ == "__main__": sys.exit() for k, v in plain.resourcetable.items(): smiley, proto = k print "%-15s %-15s -> %s" % (smiley, yobotops.imprototostr(proto), v) for k, v in plain.allsmileys.items(): print yobotops.imprototostr(k) items = "\t" counter = 0 for i in v: i += " " items += i counter += len(i) if counter >= 70: items += "\n\t" counter = 0 print items