Example #1
0
 def validateProfile(self):
     if not self.profileBox or self.profileBox.currentIndex() == 0:
         handle = unicode(self.chumHandle.text())
         if not PesterProfile.checkLength(handle):
             self.errorMsg.setText("PROFILE HANDLE IS TOO LONG")
             return
         if not PesterProfile.checkValid(handle):
             self.errorMsg.setText("NOT A VALID CHUMTAG")
             return
     self.accept()
Example #2
0
    def __init__(self, user):
        self.profiledir = _datadir+"profiles"

        if type(user) is PesterProfile:
            self.chat = user
            self.userprofile = {"handle":user.handle,
                                "color": str(user.color.name()),
                                "quirks": [],
                                "theme": "pesterchum"}
            self.theme = pesterTheme("pesterchum")
            self.chat.mood = Mood(self.theme["main/defaultmood"])
            self.lastmood = self.chat.mood.value()
            self.quirks = pesterQuirks([])
            self.randoms = False
            initials = self.chat.initials()
            if len(initials) >= 2:
                initials = (initials, "%s%s" % (initials[0].lower(), initials[1]), "%s%s" % (initials[0], initials[1].lower()))
                self.mentions = [r"\b(%s)\b" % ("|".join(initials))]
            else:
                self.mentions = []
            self.autojoins = []
        else:
            fp = open("%s/%s.js" % (self.profiledir, user))
            self.userprofile = json.load(fp)
            fp.close()
            try:
                self.theme = pesterTheme(self.userprofile["theme"])
            except ValueError as e:
                self.theme = pesterTheme("pesterchum")
            self.lastmood = self.userprofile.get('lastmood', self.theme["main/defaultmood"])
            self.chat = PesterProfile(self.userprofile["handle"],
                                      QtGui.QColor(self.userprofile["color"]),
                                      Mood(self.lastmood))
            self.quirks = pesterQuirks(self.userprofile["quirks"])
            if "randoms" not in self.userprofile:
                self.userprofile["randoms"] = False
            self.randoms = self.userprofile["randoms"]
            if "mentions" not in self.userprofile:
                initials = self.chat.initials()
                if len(initials) >= 2:
                    initials = (initials, "%s%s" % (initials[0].lower(), initials[1]), "%s%s" % (initials[0], initials[1].lower()))
                    self.userprofile["mentions"] = [r"\b(%s)\b" % ("|".join(initials))]
                else:
                    self.userprofile["mentions"] = []
            self.mentions = self.userprofile["mentions"]
            if "autojoins" not in self.userprofile:
                self.userprofile["autojoins"] = []
            self.autojoins = self.userprofile["autojoins"]

        try:
            with open(_datadir+"passwd.js") as fp:
                self.passwd = json.load(fp)
        except Exception as e:
            self.passwd = {}
        self.autoidentify = False
        self.nickservpass = ""
        if self.chat.handle in self.passwd:
            self.autoidentify = self.passwd[self.chat.handle]["auto"]
            self.nickservpass = self.passwd[self.chat.handle]["pw"]
Example #3
0
    def timeUpdate(self, handle, cmd):
        window = self.mainwindow
        chum = PesterProfile(handle)
        systemColor = QtGui.QColor(window.theme["memos/systemMsgColor"])
        close = None
        # old TC command?
        try:
            secs = int(cmd)
            time = datetime.fromtimestamp(secs)
            timed = time - datetime.now()
            s = (timed.seconds // 60)*60
            timed = timedelta(timed.days, s)
        except ValueError:
            if cmd == "i":
                timed = timedelta(0)
            else:
                if cmd[len(cmd)-1] == 'c':
                    close = timeProtocol(cmd)
                    timed = None
                else:
                    timed = timeProtocol(cmd)

        if self.times.has_key(handle):
            if close is not None:
                if close in self.times[handle]:
                    self.times[handle].setCurrent(close)
                    grammar = self.times[handle].getGrammar()
                    self.times[handle].removeTime(close)
                    msg = chum.memoclosemsg(systemColor, grammar, window.theme["convo/text/closememo"])
                    self.textArea.append(convertTags(msg))
                    self.mainwindow.chatlog.log(self.channel, msg)
            elif timed not in self.times[handle]:
                self.times[handle].addTime(timed)
            else:
                self.times[handle].setCurrent(timed)
        else:
            if timed is not None:
                ttracker = TimeTracker(timed)
                self.times[handle] = ttracker
Example #4
0
class userProfile(object):
    def __init__(self, user):
        self.profiledir = _datadir+"profiles"

        if type(user) is PesterProfile:
            self.chat = user
            self.userprofile = {"handle":user.handle,
                                "color": str(user.color.name()),
                                "quirks": [],
                                "theme": "pesterchum"}
            self.theme = pesterTheme("pesterchum")
            self.chat.mood = Mood(self.theme["main/defaultmood"])
            self.lastmood = self.chat.mood.value()
            self.quirks = pesterQuirks([])
            self.randoms = False
            initials = self.chat.initials()
            if len(initials) >= 2:
                initials = (initials, "%s%s" % (initials[0].lower(), initials[1]), "%s%s" % (initials[0], initials[1].lower()))
                self.mentions = [r"\b(%s)\b" % ("|".join(initials))]
            else:
                self.mentions = []
            self.autojoins = []
        else:
            fp = open("%s/%s.js" % (self.profiledir, user))
            self.userprofile = json.load(fp)
            fp.close()
            try:
                self.theme = pesterTheme(self.userprofile["theme"])
            except ValueError as e:
                self.theme = pesterTheme("pesterchum")
            self.lastmood = self.userprofile.get('lastmood', self.theme["main/defaultmood"])
            self.chat = PesterProfile(self.userprofile["handle"],
                                      QtGui.QColor(self.userprofile["color"]),
                                      Mood(self.lastmood))
            self.quirks = pesterQuirks(self.userprofile["quirks"])
            if "randoms" not in self.userprofile:
                self.userprofile["randoms"] = False
            self.randoms = self.userprofile["randoms"]
            if "mentions" not in self.userprofile:
                initials = self.chat.initials()
                if len(initials) >= 2:
                    initials = (initials, "%s%s" % (initials[0].lower(), initials[1]), "%s%s" % (initials[0], initials[1].lower()))
                    self.userprofile["mentions"] = [r"\b(%s)\b" % ("|".join(initials))]
                else:
                    self.userprofile["mentions"] = []
            self.mentions = self.userprofile["mentions"]
            if "autojoins" not in self.userprofile:
                self.userprofile["autojoins"] = []
            self.autojoins = self.userprofile["autojoins"]

        try:
            with open(_datadir+"passwd.js") as fp:
                self.passwd = json.load(fp)
        except Exception as e:
            self.passwd = {}
        self.autoidentify = False
        self.nickservpass = ""
        if self.chat.handle in self.passwd:
            self.autoidentify = self.passwd[self.chat.handle]["auto"]
            self.nickservpass = self.passwd[self.chat.handle]["pw"]

    def setMood(self, mood):
        self.chat.mood = mood
    def setTheme(self, theme):
        self.theme = theme
        self.userprofile["theme"] = theme.name
        self.save()
    def setColor(self, color):
        self.chat.color = color
        self.userprofile["color"] = str(color.name())
        self.save()
    def setQuirks(self, quirks):
        self.quirks = quirks
        self.userprofile["quirks"] = self.quirks.plainList()
        self.save()
    def getRandom(self):
        return self.randoms
    def setRandom(self, random):
        self.randoms = random
        self.userprofile["randoms"] = random
        self.save()
    def getMentions(self):
        return self.mentions
    def setMentions(self, mentions):
        try:
            for (i,m) in enumerate(mentions):
                re.compile(m)
        except re.error as e:
            logging.error("#%s Not a valid regular expression: %s" % (i, e))
        else:
            self.mentions = mentions
            self.userprofile["mentions"] = mentions
            self.save()
    def getLastMood(self):
        return self.lastmood
    def setLastMood(self, mood):
        self.lastmood = mood.value()
        self.userprofile["lastmood"] = self.lastmood
        self.save()
    def getTheme(self):
        return self.theme
    def getAutoIdentify(self):
        return self.autoidentify
    def setAutoIdentify(self, b):
        self.autoidentify = b
        if self.chat.handle not in self.passwd:
            self.passwd[self.chat.handle] = {}
        self.passwd[self.chat.handle]["auto"] = b
        self.saveNickServPass()
    def getNickServPass(self):
        return self.nickservpass
    def setNickServPass(self, pw):
        self.nickservpass = pw
        if self.chat.handle not in self.passwd:
            self.passwd[self.chat.handle] = {}
        self.passwd[self.chat.handle]["pw"] = pw
        self.saveNickServPass()
    def getAutoJoins(self):
        return self.autojoins
    def setAutoJoins(self, autojoins):
        self.autojoins = autojoins
        self.userprofile["autojoins"] = self.autojoins
        self.save()
    def save(self):
        handle = self.chat.handle
        if handle[0:12] == "pesterClient":
            # dont save temp profiles
            return
        try:
            jsonoutput = json.dumps(self.userprofile)
        except ValueError as e:
            raise e
        fp = open("%s/%s.js" % (self.profiledir, handle), 'w')
        fp.write(jsonoutput)
        fp.close()
    def saveNickServPass(self):
        # remove profiles with no passwords
        for h,t in list(self.passwd.items()):
            if "auto" not in t or "pw" not in t or t["pw"] == "":
                del self.passwd[h]
        try:
            jsonoutput = json.dumps(self.passwd, indent=4)
        except ValueError as e:
            raise e
        with open(_datadir+"passwd.js", 'w') as fp:
            fp.write(jsonoutput)
    @staticmethod
    def newUserProfile(chatprofile):
        if os.path.exists("%s/%s.js" % (_datadir+"profiles", chatprofile.handle)):
            newprofile = userProfile(chatprofile.handle)
        else:
            newprofile = userProfile(chatprofile)
            newprofile.save()
        return newprofile
Example #5
0
    def userPresentChange(self, handle, channel, update):
        h = unicode(handle)
        c = unicode(channel)
        update = unicode(update)
        if update[0:4] == "kick": # yeah, i'm lazy.
            l = update.split(":")
            update = l[0]
            op = l[1]
        if update == "nick":
            l = h.split(":")
            oldnick = l[0]
            newnick = l[1]
            h = oldnick
        if (update in ["join","left", "kick", "+o"]) \
                and channel != self.channel:
            return
        chums = self.userlist.findItems(h, QtCore.Qt.MatchFlags(0))
        systemColor = QtGui.QColor(self.mainwindow.theme["memos/systemMsgColor"])
        # print exit
        if update == "quit" or update == "left" or update == "nick":
            for c in chums:
                chum = PesterProfile(h)
                self.userlist.takeItem(self.userlist.row(c))
                if not self.times.has_key(h):
                    self.times[h] = TimeTracker(timedelta(0))
                while self.times[h].getTime() is not None:
                    t = self.times[h]
                    grammar = t.getGrammar()
                    msg = chum.memoclosemsg(systemColor, grammar, self.mainwindow.theme["convo/text/closememo"])
                    self.textArea.append(convertTags(msg))
                    self.mainwindow.chatlog.log(self.channel, msg)
                    self.times[h].removeTime(t.getTime())
                if update == "nick":
                    self.addUser(newnick)
        elif update == "kick":
            if len(chums) == 0:
                return
            c = chums[0]
            chum = PesterProfile(h)
            if h == self.mainwindow.profile().handle:
                chum = self.mainwindow.profile()
                ttracker = self.time
                curtime = self.time.getTime()
            elif self.times.has_key(h):
                ttracker = self.times[h]
            else:
                ttracker = TimeTracker(timedelta(0))
            while ttracker.getTime() is not None:
                grammar = ttracker.getGrammar()
                opchum = PesterProfile(op)
                if self.times.has_key(op):
                    opgrammar = self.times[op].getGrammar()
                elif op == self.mainwindow.profile().handle:
                    opgrammar = self.time.getGrammar()
                else:
                    opgrammar = TimeGrammar("CURRENT", "C", "RIGHT NOW")
                msg = chum.memobanmsg(opchum, opgrammar, systemColor, grammar)
                self.textArea.append(convertTags(msg))
                self.mainwindow.chatlog.log(self.channel, msg)
                ttracker.removeTime(ttracker.getTime())

            if chum is self.mainwindow.profile():
                # are you next?
                msgbox = QtGui.QMessageBox()
                msgbox.setText(self.mainwindow.theme["convo/text/kickedmemo"])
                msgbox.setInformativeText("press 0k to rec0nnect or cancel to absc0nd")
                msgbox.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
                ret = msgbox.exec_()
                if ret == QtGui.QMessageBox.Ok:
                    self.userlist.clear()
                    self.time = TimeTracker(curtime)
                    self.resetSlider(curtime)
                    self.mainwindow.joinChannel.emit(self.channel)
                    me = self.mainwindow.profile()
                    self.time.openCurrentTime()
                    msg = me.memoopenmsg(systemColor, self.time.getTime(), self.time.getGrammar(), self.mainwindow.theme["convo/text/openmemo"], self.channel)
                    self.textArea.append(convertTags(msg))
                    self.mainwindow.chatlog.log(self.channel, msg)
                elif ret == QtGui.QMessageBox.Cancel:
                    if self.parent():
                        i = self.parent().tabIndices[self.channel]
                        self.parent().tabClose(i)
                    else:
                        self.close()
            else:
                # i warned you about those stairs bro
                self.userlist.takeItem(self.userlist.row(c))
        elif update == "join":
            self.addUser(h)
            time = self.time.getTime()
            serverText = "PESTERCHUM:TIME>"+delta2txt(time, "server")
            self.messageSent.emit(serverText, self.title())
        elif update == "+o":
            chums = self.userlist.findItems(h, QtCore.Qt.MatchFlags(0))
            for c in chums:
                icon = PesterIcon(self.mainwindow.theme["memos/op/icon"])
                c.setIcon(icon)
                if unicode(c.text()) == self.mainwindow.profile().handle:
                    self.userlist.optionsMenu.addAction(self.opAction)
                    self.userlist.optionsMenu.addAction(self.banuserAction)
Example #6
0
class userProfile(object):
    def __init__(self, user):
        self.profiledir = _datadir + "profiles"

        if type(user) is PesterProfile:
            self.chat = user
            self.userprofile = {
                "handle": user.handle,
                "color": unicode(user.color.name()),
                "quirks": [],
                "theme": "pesterchum"
            }
            self.theme = pesterTheme("pesterchum")
            self.chat.mood = Mood(self.theme["main/defaultmood"])
            self.lastmood = self.chat.mood.value()
            self.quirks = pesterQuirks([])
            self.randoms = False
            initials = self.chat.initials()
            if len(initials) >= 2:
                initials = (initials,
                            "%s%s" % (initials[0].lower(), initials[1]),
                            "%s%s" % (initials[0], initials[1].lower()))
                self.mentions = [r"\b(%s)\b" % ("|".join(initials))]
            else:
                self.mentions = []
            self.autojoins = []
        else:
            with open("%s/%s.js" % (self.profiledir, user)) as fp:
                self.userprofile = json.load(fp)
            try:
                self.theme = pesterTheme(self.userprofile["theme"])
            except ValueError:
                self.theme = pesterTheme("pesterchum")
            self.lastmood = self.userprofile.get(
                'lastmood', self.theme["main/defaultmood"])
            self.chat = PesterProfile(self.userprofile["handle"],
                                      QtGui.QColor(self.userprofile["color"]),
                                      Mood(self.lastmood))
            self.quirks = pesterQuirks(self.userprofile["quirks"])
            if "randoms" not in self.userprofile:
                self.userprofile["randoms"] = False
            self.randoms = self.userprofile["randoms"]
            if "mentions" not in self.userprofile:
                initials = self.chat.initials()
                if len(initials) >= 2:
                    initials = (initials,
                                "%s%s" % (initials[0].lower(), initials[1]),
                                "%s%s" % (initials[0], initials[1].lower()))
                    self.userprofile["mentions"] = [
                        r"\b(%s)\b" % ("|".join(initials))
                    ]
                else:
                    self.userprofile["mentions"] = []
            self.mentions = self.userprofile["mentions"]
            if "autojoins" not in self.userprofile:
                self.userprofile["autojoins"] = []
            self.autojoins = self.userprofile["autojoins"]

        try:
            with open(_datadir + "passwd.js") as fp:
                self.passwd = json.load(fp)
        except:
            self.passwd = {}
        self.autoidentify = False
        self.nickservpass = ""
        if self.chat.handle in self.passwd:
            self.autoidentify = self.passwd[self.chat.handle]["auto"]
            self.nickservpass = self.passwd[self.chat.handle]["pw"]

    def setMood(self, mood):
        self.chat.mood = mood

    def setTheme(self, theme):
        self.theme = theme
        self.userprofile["theme"] = theme.name
        self.save()

    def setColor(self, color):
        self.chat.color = color
        self.userprofile["color"] = unicode(color.name())
        self.save()

    def setQuirks(self, quirks):
        self.quirks = quirks
        self.userprofile["quirks"] = self.quirks.plainList()
        self.save()

    def getRandom(self):
        return self.randoms

    def setRandom(self, random):
        self.randoms = random
        self.userprofile["randoms"] = random
        self.save()

    def getMentions(self):
        return self.mentions

    def setMentions(self, mentions):
        try:
            for (i, m) in enumerate(mentions):
                re.compile(m)
        except re.error, e:
            logging.error("#%s Not a valid regular expression: %s" % (i, e))
        else:
Example #7
0
 def setNotes(self, handle, notes):
     if self.has_key(handle):
         self[handle].notes = notes
     else:
         self[handle] = PesterProfile(handle, notes=notes)
     self.save()
Example #8
0
 def setGroup(self, handle, theGroup):
     if self.has_key(handle):
         self[handle].group = theGroup
     else:
         self[handle] = PesterProfile(handle, group=theGroup)
     self.save()
Example #9
0
 def setColor(self, handle, color):
     if self.has_key(handle):
         self[handle].color = color
     else:
         self[handle] = PesterProfile(handle, color)