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 = [] 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, 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"]
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 = [] 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, 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"]
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:
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
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: # Trying to fix: # IOError: [Errno 2] # No such file or directory: # u'XXX\\AppData\\Local\\pesterchum/profiles/XXX.js' # Part 3 :( try: with open("%s/%s.js" % (self.profiledir, user)) as fp: self.userprofile = json.load(fp) except: msgBox = QtWidgets.QMessageBox() msgBox.setIcon(QtWidgets.QMessageBox.Information) msgBox.setWindowTitle(":(") self.filename = _datadir+"pesterchum.js" msgBox.setText("Failed to open \"" + \ ("%s/%s.js" % (self.profiledir, user)) + \ "\n You should switch to a different profile and set it as the default.") #"\" if pesterchum acts oddly you might want to try backing up and then deleting \"" + \ #_datadir+"pesterchum.js" + \ #"\"") msgBox.exec_() 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: # Fix for: # Traceback (most recent call last): # File "pesterchum.py", line 2944, in nickCollision # File "pesterchum.py", line 1692, in changeProfile # File "XXX\menus.py", line 795, in init # File "XXX\profile.py", line 350, in availableProfiles # File "XXX\profile.py", line 432, in init # KeyError: 'pw' if "auto" in self.passwd[self.chat.handle]: self.autoidentify = self.passwd[self.chat.handle]["auto"] if "pw" in self.passwd[self.chat.handle]: 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 with open("%s/%s.js" % (self.profiledir, handle), 'w') as fp: fp.write(jsonoutput) def saveNickServPass(self): # remove profiles with no passwords for h,t in list(self.passwd.items()): if "auto" not in t and ("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
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: # Trying to fix: # IOError: [Errno 2] # No such file or directory: # u'XXX\\AppData\\Local\\pesterchum/profiles/XXX.js' # Part 3 :( try: with open("%s/%s.js" % (self.profiledir, user)) as fp: self.userprofile = json.load(fp) except: msgBox = QtGui.QMessageBox() msgBox.setIcon(QtGui.QMessageBox.Information) msgBox.setWindowTitle(":(") self.filename = _datadir + "pesterchum.js" msgBox.setText("Failed to open \"" + \ ("%s/%s.js" % (self.profiledir, user)) + \ "\n You should switch to a different profile and set it as the default.") #"\" if pesterchum acts oddly you might want to try backing up and then deleting \"" + \ #_datadir+"pesterchum.js" + \ #"\"") msgBox.exec_() 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: # Fix for: # Traceback (most recent call last): # File "pesterchum.py", line 2944, in nickCollision # File "pesterchum.py", line 1692, in changeProfile # File "XXX\menus.py", line 795, in init # File "XXX\profile.py", line 350, in availableProfiles # File "XXX\profile.py", line 432, in init # KeyError: 'pw' if "auto" in self.passwd[self.chat.handle]: self.autoidentify = self.passwd[self.chat.handle]["auto"] if "pw" in self.passwd[self.chat.handle]: 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: