2011-09-12 22:02:00 -04:00
|
|
|
import os
|
2022-03-17 18:30:04 -04:00
|
|
|
import sys
|
2011-09-12 22:02:00 -04:00
|
|
|
import json
|
|
|
|
import re
|
|
|
|
import codecs
|
2022-03-17 18:30:04 -04:00
|
|
|
import shutil
|
2022-03-17 21:05:14 -04:00
|
|
|
import zipfile
|
2022-04-10 23:57:13 -04:00
|
|
|
import logging
|
2022-03-19 19:48:19 -04:00
|
|
|
from string import Template
|
2022-04-10 23:57:13 -04:00
|
|
|
from datetime import datetime
|
|
|
|
from time import strftime
|
2022-03-19 19:48:19 -04:00
|
|
|
|
2022-08-19 07:12:58 -04:00
|
|
|
try:
|
|
|
|
from PyQt6 import QtCore, QtGui, QtWidgets
|
|
|
|
except ImportError:
|
|
|
|
print("PyQt5 fallback (profile.py)")
|
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
2011-09-12 22:02:00 -04:00
|
|
|
|
|
|
|
import ostools
|
2011-09-15 03:09:56 -04:00
|
|
|
from mood import Mood
|
2022-04-10 23:57:13 -04:00
|
|
|
from dataobjs import PesterProfile, pesterQuirks
|
|
|
|
from parsetools import convertTags
|
2011-09-12 22:02:00 -04:00
|
|
|
|
|
|
|
_datadir = ostools.getDataDir()
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog = logging.getLogger("pchumLogger")
|
2022-03-19 19:48:19 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
|
2023-01-14 16:59:59 -05:00
|
|
|
class PesterLog:
|
2011-09-12 22:02:00 -04:00
|
|
|
def __init__(self, handle, parent=None):
|
|
|
|
global _datadir
|
|
|
|
self.parent = parent
|
|
|
|
self.handle = handle
|
|
|
|
self.convos = {}
|
2022-10-07 16:51:40 -04:00
|
|
|
self.logpath = _datadir + "logs"
|
2011-09-12 22:02:00 -04:00
|
|
|
|
|
|
|
def log(self, handle, msg):
|
|
|
|
if self.parent.config.time12Format():
|
2022-04-10 23:57:13 -04:00
|
|
|
log_time = strftime("[%I:%M")
|
2011-09-12 22:02:00 -04:00
|
|
|
else:
|
2022-04-10 23:57:13 -04:00
|
|
|
log_time = strftime("[%H:%M")
|
2011-09-12 22:02:00 -04:00
|
|
|
if self.parent.config.showSeconds():
|
2022-04-10 23:57:13 -04:00
|
|
|
log_time += strftime(":%S] ")
|
2011-09-12 22:02:00 -04:00
|
|
|
else:
|
2022-04-10 23:57:13 -04:00
|
|
|
log_time += "] "
|
2022-10-07 16:51:40 -04:00
|
|
|
if handle[0] == "#":
|
|
|
|
if not self.parent.config.logMemos() & self.parent.config.LOG:
|
|
|
|
return
|
2011-09-12 22:02:00 -04:00
|
|
|
if not self.parent.config.logMemos() & self.parent.config.STAMP:
|
2022-04-10 23:57:13 -04:00
|
|
|
log_time = ""
|
2011-09-12 22:02:00 -04:00
|
|
|
else:
|
2022-10-07 16:51:40 -04:00
|
|
|
if not self.parent.config.logPesters() & self.parent.config.LOG:
|
|
|
|
return
|
2011-09-12 22:02:00 -04:00
|
|
|
if not self.parent.config.logPesters() & self.parent.config.STAMP:
|
2022-04-10 23:57:13 -04:00
|
|
|
log_time = ""
|
2022-10-07 16:51:40 -04:00
|
|
|
if self.parent.isBot(handle):
|
|
|
|
return
|
|
|
|
# watch out for illegal characters
|
2011-09-12 22:02:00 -04:00
|
|
|
handle = re.sub(r'[<>:"/\\|?*]', "_", handle)
|
2022-04-10 23:57:13 -04:00
|
|
|
bbcodemsg = log_time + convertTags(msg, "bbcode")
|
2022-10-07 16:51:40 -04:00
|
|
|
html = log_time + convertTags(msg, "html") + "<br />"
|
|
|
|
msg = log_time + convertTags(msg, "text")
|
2011-09-12 22:02:00 -04:00
|
|
|
modes = {"bbcode": bbcodemsg, "html": html, "text": msg}
|
2022-06-30 03:59:34 -04:00
|
|
|
try:
|
|
|
|
if handle not in self.convos:
|
|
|
|
log_time = datetime.now().strftime("%Y-%m-%d.%H.%M")
|
|
|
|
self.convos[handle] = {}
|
|
|
|
for (format, t) in modes.items():
|
2022-10-07 16:51:40 -04:00
|
|
|
if not os.path.exists(
|
2023-01-14 16:59:59 -05:00
|
|
|
"{}/{}/{}/{}".format(self.logpath, self.handle, handle, format)
|
2022-10-07 16:51:40 -04:00
|
|
|
):
|
|
|
|
os.makedirs(
|
2023-01-14 16:59:59 -05:00
|
|
|
"{}/{}/{}/{}".format(
|
|
|
|
self.logpath, self.handle, handle, format
|
|
|
|
)
|
2022-10-07 16:51:40 -04:00
|
|
|
)
|
|
|
|
fp = codecs.open(
|
|
|
|
"%s/%s/%s/%s/%s.%s.txt"
|
|
|
|
% (self.logpath, self.handle, handle, format, handle, log_time),
|
|
|
|
encoding="utf-8",
|
|
|
|
mode="a",
|
|
|
|
)
|
2022-06-30 03:59:34 -04:00
|
|
|
self.convos[handle][format] = fp
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-03-23 13:32:59 -04:00
|
|
|
for (format, t) in modes.items():
|
2022-06-30 03:59:34 -04:00
|
|
|
f = self.convos[handle][format]
|
2022-10-07 16:51:40 -04:00
|
|
|
f.write(t + "\r\n")
|
2022-06-30 03:59:34 -04:00
|
|
|
# flush + fsync force a write,
|
|
|
|
# makes sure logs are saved in the case of a crash.
|
|
|
|
f.flush()
|
|
|
|
os.fsync(f.fileno())
|
|
|
|
|
|
|
|
# This way the file descriptors are closed and reopened for every message,
|
|
|
|
# which is sub-optimal and definitely a performance drain but,
|
|
|
|
# otherwise we still run into the ulimit on platforms like MacOS fairly easily.
|
2022-10-07 16:51:40 -04:00
|
|
|
# if ostools.isOSX() == True:
|
2022-06-30 03:59:34 -04:00
|
|
|
# for (format, t) in modes.items():
|
|
|
|
# self.finish(handle)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2023-01-14 16:59:59 -05:00
|
|
|
except (OSError, KeyError, IndexError, ValueError) as e:
|
2022-06-30 03:59:34 -04:00
|
|
|
# Catching this exception does not stop pchum from dying if we run out of file handles </3
|
|
|
|
PchumLog.critical(e)
|
|
|
|
errmsg = QtWidgets.QMessageBox()
|
|
|
|
errmsg.setIcon(QtWidgets.QMessageBox.Icon.Warning)
|
2022-10-07 16:51:40 -04:00
|
|
|
errmsg.setText(
|
|
|
|
"Warning: Pesterchum could not open the log file for %s!" % (handle)
|
|
|
|
)
|
|
|
|
errmsg.setInformativeText(
|
|
|
|
"Your log for %s will not be saved because something went wrong. We suggest restarting Pesterchum. Sorry :("
|
|
|
|
% (handle)
|
|
|
|
+ "\n"
|
|
|
|
+ str(e)
|
|
|
|
)
|
2022-06-30 03:59:34 -04:00
|
|
|
errmsg.setWindowTitle(":(")
|
|
|
|
errmsg.exec()
|
|
|
|
PchumLog.debug("post-error msg")
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def finish(self, handle):
|
2021-03-23 17:36:43 -04:00
|
|
|
if handle not in self.convos:
|
2011-09-12 22:02:00 -04:00
|
|
|
return
|
2021-03-23 17:36:43 -04:00
|
|
|
for f in list(self.convos[handle].values()):
|
2011-09-12 22:02:00 -04:00
|
|
|
f.close()
|
|
|
|
del self.convos[handle]
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def close(self):
|
2021-03-23 17:36:43 -04:00
|
|
|
for h in list(self.convos.keys()):
|
|
|
|
for f in list(self.convos[h].values()):
|
2011-09-12 22:02:00 -04:00
|
|
|
f.close()
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2023-01-14 16:59:59 -05:00
|
|
|
class userConfig:
|
2011-09-12 22:02:00 -04:00
|
|
|
def __init__(self, parent):
|
|
|
|
self.parent = parent
|
|
|
|
# Use for bit flag log setting
|
|
|
|
self.LOG = 1
|
|
|
|
self.STAMP = 2
|
|
|
|
# Use for bit flag blink
|
|
|
|
self.PBLINK = 1
|
|
|
|
self.MBLINK = 2
|
|
|
|
# Use for bit flag notfications
|
2022-10-07 16:51:40 -04:00
|
|
|
self.SIGNIN = 1
|
|
|
|
self.SIGNOUT = 2
|
|
|
|
self.NEWMSG = 4
|
2011-09-12 22:02:00 -04:00
|
|
|
self.NEWCONVO = 8
|
2022-10-07 16:51:40 -04:00
|
|
|
self.INITIALS = 16
|
|
|
|
self.filename = _datadir + "pesterchum.js"
|
2022-03-17 18:30:04 -04:00
|
|
|
try:
|
|
|
|
with open(self.filename) as fp:
|
|
|
|
self.config = json.load(fp)
|
|
|
|
except json.decoder.JSONDecodeError as e:
|
|
|
|
PchumLog.critical("ohno :(")
|
|
|
|
PchumLog.critical("failed to load pesterchum.js")
|
|
|
|
PchumLog.critical(e)
|
|
|
|
msgbox = QtWidgets.QMessageBox()
|
2022-06-28 19:50:08 -04:00
|
|
|
msgbox.setIcon(QtWidgets.QMessageBox.Icon.Warning)
|
2022-03-17 18:30:04 -04:00
|
|
|
msgbox.setWindowTitle(":(")
|
2022-10-07 16:51:40 -04:00
|
|
|
msgbox.setTextFormat(QtCore.Qt.TextFormat.RichText) # Clickable html links
|
|
|
|
msgbox.setInformativeText(
|
|
|
|
"<html><h3>Failed to load pesterchum.js, this might require manual intervention.<br><br>\
|
2022-03-17 18:30:04 -04:00
|
|
|
Consider overriding: <a href='%s'>%s</a> <br>\
|
2022-10-07 16:51:40 -04:00
|
|
|
with a backup from: <a href='%s'>%s</a></h3></html>"
|
|
|
|
% (
|
|
|
|
_datadir,
|
|
|
|
self.filename,
|
|
|
|
os.path.join(_datadir, "backup"),
|
|
|
|
os.path.join(_datadir, "backup"),
|
|
|
|
)
|
|
|
|
)
|
2022-06-26 22:18:37 -04:00
|
|
|
msgbox.exec()
|
2022-03-17 18:30:04 -04:00
|
|
|
sys.exit()
|
|
|
|
|
2021-02-13 19:47:06 -05:00
|
|
|
# Trying to fix:
|
|
|
|
# IOError: [Errno 2]
|
|
|
|
# No such file or directory:
|
|
|
|
# u'XXX\\AppData\\Local\\pesterchum/profiles/XXX.js'
|
|
|
|
# Part 2 :(
|
2021-03-23 17:36:43 -04:00
|
|
|
if "defaultprofile" in self.config:
|
2021-02-13 19:47:06 -05:00
|
|
|
try:
|
|
|
|
self.userprofile = userProfile(self.config["defaultprofile"])
|
|
|
|
except:
|
|
|
|
self.userprofile = None
|
2011-09-12 22:02:00 -04:00
|
|
|
else:
|
|
|
|
self.userprofile = None
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
self.logpath = _datadir + "logs"
|
2011-09-12 22:02:00 -04:00
|
|
|
|
|
|
|
if not os.path.exists(self.logpath):
|
|
|
|
os.makedirs(self.logpath)
|
|
|
|
try:
|
2023-01-14 16:59:59 -05:00
|
|
|
with open("%s/groups.js" % (self.logpath)) as fp:
|
2016-11-29 15:20:41 -05:00
|
|
|
self.groups = json.load(fp)
|
2023-01-14 16:59:59 -05:00
|
|
|
except (OSError, ValueError):
|
2011-09-12 22:02:00 -04:00
|
|
|
self.groups = {}
|
2022-10-07 16:51:40 -04:00
|
|
|
with open("%s/groups.js" % (self.logpath), "w") as fp:
|
2016-11-29 15:20:41 -05:00
|
|
|
json.dump(self.groups, fp)
|
2011-09-12 22:02:00 -04:00
|
|
|
|
2022-03-17 18:30:04 -04:00
|
|
|
self.backup()
|
|
|
|
|
|
|
|
def backup(self):
|
2022-03-17 21:05:14 -04:00
|
|
|
# Backups
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-03-17 18:30:04 -04:00
|
|
|
try:
|
2022-03-17 21:05:14 -04:00
|
|
|
# Backup pesterchum.js file.
|
|
|
|
# Useful because it seems to randomly get blanked for people.
|
2022-03-17 18:30:04 -04:00
|
|
|
backup_path = os.path.join(_datadir, "backup")
|
|
|
|
if os.path.exists(backup_path) == False:
|
|
|
|
os.makedirs(backup_path)
|
|
|
|
current_backup = datetime.now().day % 5
|
2022-10-07 16:51:40 -04:00
|
|
|
shutil.copyfile(
|
|
|
|
self.filename,
|
|
|
|
os.path.join(
|
|
|
|
backup_path, "pesterchum.backup-" + str(current_backup) + ".js"
|
|
|
|
),
|
|
|
|
)
|
2022-03-17 21:05:14 -04:00
|
|
|
|
|
|
|
# Backup profiles.
|
|
|
|
# Useful because people don't know how to add underscores to handles.
|
|
|
|
profile_path = os.path.join(_datadir, "profiles")
|
|
|
|
profile_list = os.listdir(profile_path)
|
2022-10-07 16:51:40 -04:00
|
|
|
with zipfile.ZipFile(
|
|
|
|
os.path.join(backup_path, "profiles.backup-" + str(current_backup))
|
|
|
|
+ ".zip",
|
|
|
|
"w",
|
|
|
|
) as pzip:
|
2022-03-17 21:05:14 -04:00
|
|
|
for x in profile_list:
|
|
|
|
if x.endswith(".js") == True:
|
|
|
|
with open(self.filename) as f:
|
2022-10-07 16:51:40 -04:00
|
|
|
pzip.writestr(x, f.read())
|
2022-03-17 21:05:14 -04:00
|
|
|
|
|
|
|
PchumLog.info("Updated backups-%s." % current_backup)
|
2022-03-17 18:30:04 -04:00
|
|
|
except shutil.Error as e:
|
2023-01-14 15:52:07 -05:00
|
|
|
PchumLog.warning(f"Failed to make backup, shutil error?\n{e}")
|
2022-03-17 21:05:14 -04:00
|
|
|
except zipfile.BadZipFile as e:
|
2023-01-14 15:52:07 -05:00
|
|
|
PchumLog.warning(f"Failed to make backup, BadZipFile?\n{e}")
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(f"Failed to make backup, no permission?\n{e}")
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def chums(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if "chums" not in self.config:
|
2011-09-12 22:02:00 -04:00
|
|
|
self.set("chums", [])
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("chums", [])
|
|
|
|
|
2011-11-25 21:45:20 -05:00
|
|
|
def setChums(self, newchums):
|
2016-11-29 15:20:41 -05:00
|
|
|
with open(self.filename) as fp:
|
|
|
|
# what if we have two clients open??
|
|
|
|
newconfig = json.load(fp)
|
2022-10-07 16:51:40 -04:00
|
|
|
oldchums = newconfig["chums"]
|
2011-11-25 21:45:20 -05:00
|
|
|
# Time to merge these two! :OOO
|
|
|
|
for c in list(set(oldchums) - set(newchums)):
|
|
|
|
newchums.append(c)
|
|
|
|
|
|
|
|
self.set("chums", newchums)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def hideOfflineChums(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("hideOfflineChums", False)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def defaultprofile(self):
|
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config["defaultprofile"]
|
2011-09-12 22:02:00 -04:00
|
|
|
except KeyError:
|
|
|
|
return None
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def tabs(self):
|
|
|
|
return self.config.get("tabs", True)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-11-07 22:44:17 -05:00
|
|
|
def tabMemos(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if "tabmemos" not in self.config:
|
2011-11-07 22:44:17 -05:00
|
|
|
self.set("tabmemos", self.tabs())
|
|
|
|
return self.config.get("tabmemos", True)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def showTimeStamps(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if "showTimeStamps" not in self.config:
|
2011-09-12 22:02:00 -04:00
|
|
|
self.set("showTimeStamps", True)
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("showTimeStamps", True)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def time12Format(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if "time12Format" not in self.config:
|
2011-09-12 22:02:00 -04:00
|
|
|
self.set("time12Format", True)
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("time12Format", True)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def showSeconds(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if "showSeconds" not in self.config:
|
2011-09-12 22:02:00 -04:00
|
|
|
self.set("showSeconds", False)
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("showSeconds", False)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def sortMethod(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("sortMethod", 0)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def useGroups(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("useGroups", False)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def openDefaultGroup(self):
|
|
|
|
groups = self.getGroups()
|
|
|
|
for g in groups:
|
|
|
|
if g[0] == "Chums":
|
|
|
|
return g[1]
|
|
|
|
return True
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def showEmptyGroups(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if "emptyGroups" not in self.config:
|
2011-09-12 22:02:00 -04:00
|
|
|
self.set("emptyGroups", False)
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("emptyGroups", False)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def showOnlineNumbers(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if "onlineNumbers" not in self.config:
|
2011-09-12 22:02:00 -04:00
|
|
|
self.set("onlineNumbers", False)
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("onlineNumbers", False)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def logPesters(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("logPesters", self.LOG | self.STAMP)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def logMemos(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("logMemos", self.LOG)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def disableUserLinks(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return not self.config.get("userLinks", True)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def idleTime(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("idleTime", 10)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def minimizeAction(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("miniAction", 0)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def closeAction(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("closeAction", 1)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def opvoiceMessages(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("opvMessages", True)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def animations(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("animations", True)
|
|
|
|
|
|
|
|
# def checkForUpdates(self):
|
2022-09-06 07:26:14 -04:00
|
|
|
# u = self.config.get('checkUpdates', 0)
|
|
|
|
# if type(u) == type(bool()):
|
|
|
|
# if u: u = 2
|
|
|
|
# else: u = 3
|
|
|
|
# return u
|
|
|
|
# # Once a day
|
|
|
|
# # Once a week
|
|
|
|
# # Only on start
|
|
|
|
# # Never
|
2022-10-07 16:51:40 -04:00
|
|
|
# def lastUCheck(self):
|
2022-09-06 07:26:14 -04:00
|
|
|
# return self.config.get('lastUCheck', 0)
|
2022-10-07 16:51:40 -04:00
|
|
|
# def checkMSPA(self):
|
2022-09-06 07:26:14 -04:00
|
|
|
# return self.config.get('mspa', False)
|
2011-09-12 22:02:00 -04:00
|
|
|
def blink(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("blink", self.PBLINK | self.MBLINK)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def notify(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("notify", True)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def notifyType(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("notifyType", "default")
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def notifyOptions(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get(
|
|
|
|
"notifyOptions", self.SIGNIN | self.NEWMSG | self.NEWCONVO | self.INITIALS
|
|
|
|
)
|
|
|
|
|
2011-09-13 00:03:05 -04:00
|
|
|
def lowBandwidth(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("lowBandwidth", False)
|
|
|
|
|
2012-06-08 05:02:12 -04:00
|
|
|
def ghostchum(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("ghostchum", False)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def addChum(self, chum):
|
|
|
|
if chum.handle not in self.chums():
|
2016-11-29 15:20:41 -05:00
|
|
|
with open(self.filename) as fp:
|
|
|
|
# what if we have two clients open??
|
|
|
|
newconfig = json.load(fp)
|
2022-10-07 16:51:40 -04:00
|
|
|
newchums = newconfig["chums"] + [chum.handle]
|
2011-09-12 22:02:00 -04:00
|
|
|
self.set("chums", newchums)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def removeChum(self, chum):
|
|
|
|
if type(chum) is PesterProfile:
|
|
|
|
handle = chum.handle
|
|
|
|
else:
|
|
|
|
handle = chum
|
2022-10-07 16:51:40 -04:00
|
|
|
newchums = [c for c in self.config["chums"] if c != handle]
|
2011-09-12 22:02:00 -04:00
|
|
|
self.set("chums", newchums)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def getBlocklist(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if "block" not in self.config:
|
|
|
|
self.set("block", [])
|
|
|
|
return self.config["block"]
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def addBlocklist(self, handle):
|
|
|
|
l = self.getBlocklist()
|
|
|
|
if handle not in l:
|
|
|
|
l.append(handle)
|
2022-10-07 16:51:40 -04:00
|
|
|
self.set("block", l)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def delBlocklist(self, handle):
|
|
|
|
l = self.getBlocklist()
|
|
|
|
l.pop(l.index(handle))
|
2022-10-07 16:51:40 -04:00
|
|
|
self.set("block", l)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def getGroups(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if "groups" not in self.groups:
|
2011-09-12 22:02:00 -04:00
|
|
|
self.saveGroups([["Chums", True]])
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.groups.get("groups", [["Chums", True]])
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def addGroup(self, group, open=True):
|
|
|
|
l = self.getGroups()
|
|
|
|
exists = False
|
|
|
|
for g in l:
|
|
|
|
if g[0] == group:
|
|
|
|
exists = True
|
|
|
|
break
|
|
|
|
if not exists:
|
2022-10-07 16:51:40 -04:00
|
|
|
l.append([group, open])
|
2011-09-12 22:02:00 -04:00
|
|
|
l.sort()
|
|
|
|
self.saveGroups(l)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def delGroup(self, group):
|
|
|
|
l = self.getGroups()
|
|
|
|
i = 0
|
|
|
|
for g in l:
|
2022-10-07 16:51:40 -04:00
|
|
|
if g[0] == group:
|
|
|
|
break
|
|
|
|
i = i + 1
|
2011-09-12 22:02:00 -04:00
|
|
|
l.pop(i)
|
|
|
|
l.sort()
|
|
|
|
self.saveGroups(l)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def expandGroup(self, group, open=True):
|
|
|
|
l = self.getGroups()
|
|
|
|
for g in l:
|
|
|
|
if g[0] == group:
|
|
|
|
g[1] = open
|
|
|
|
break
|
|
|
|
self.saveGroups(l)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def saveGroups(self, groups):
|
2022-10-07 16:51:40 -04:00
|
|
|
self.groups["groups"] = groups
|
2011-09-12 22:02:00 -04:00
|
|
|
try:
|
|
|
|
jsonoutput = json.dumps(self.groups)
|
2016-11-29 15:20:41 -05:00
|
|
|
except ValueError as e:
|
2011-09-12 22:02:00 -04:00
|
|
|
raise e
|
2022-10-07 16:51:40 -04:00
|
|
|
with open("%s/groups.js" % (self.logpath), "w") as fp:
|
2016-11-29 15:20:41 -05:00
|
|
|
fp.write(jsonoutput)
|
2011-09-12 22:02:00 -04:00
|
|
|
|
|
|
|
def server(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self.parent, "serverOverride"):
|
2011-09-12 22:02:00 -04:00
|
|
|
return self.parent.serverOverride
|
2021-04-06 13:06:51 -04:00
|
|
|
try:
|
2023-01-14 16:59:59 -05:00
|
|
|
with open(_datadir + "server.json") as server_file:
|
2021-04-06 13:06:51 -04:00
|
|
|
read_file = server_file.read()
|
|
|
|
server_file.close()
|
|
|
|
server_obj = json.loads(read_file)
|
2022-10-07 16:51:40 -04:00
|
|
|
return server_obj["server"]
|
2021-04-06 13:06:51 -04:00
|
|
|
except:
|
|
|
|
try:
|
2021-04-08 20:38:34 -04:00
|
|
|
with open(_datadir + "server.json", "w") as server_file:
|
2021-04-06 13:06:51 -04:00
|
|
|
json_server_file = {
|
2022-10-07 16:51:40 -04:00
|
|
|
"server": "irc.pesterchum.xyz",
|
|
|
|
"port": "6697",
|
|
|
|
"TLS": True,
|
|
|
|
}
|
|
|
|
server_file.write(json.dumps(json_server_file, indent=4))
|
2021-04-06 13:06:51 -04:00
|
|
|
server_file.close()
|
|
|
|
server = "irc.pesterchum.xyz"
|
|
|
|
except:
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("server", "irc.pesterchum.xyz")
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def port(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self.parent, "portOverride"):
|
2011-09-12 22:02:00 -04:00
|
|
|
return self.parent.portOverride
|
2021-04-06 13:06:51 -04:00
|
|
|
try:
|
2023-01-14 16:59:59 -05:00
|
|
|
with open(_datadir + "server.json") as server_file:
|
2021-04-06 13:06:51 -04:00
|
|
|
read_file = server_file.read()
|
|
|
|
server_file.close()
|
|
|
|
server_obj = json.loads(read_file)
|
2022-10-07 16:51:40 -04:00
|
|
|
port = server_obj["port"]
|
2021-04-06 13:06:51 -04:00
|
|
|
return port
|
|
|
|
except:
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("port", "6697")
|
2022-06-16 14:25:24 -04:00
|
|
|
|
|
|
|
def ssl(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
# if hasattr(self.parent, 'tlsOverride'):
|
2022-06-16 14:25:24 -04:00
|
|
|
# return self.parent.tlsOverride
|
|
|
|
try:
|
2023-01-14 16:59:59 -05:00
|
|
|
with open(_datadir + "server.json") as server_file:
|
2022-06-16 14:25:24 -04:00
|
|
|
read_file = server_file.read()
|
|
|
|
server_file.close()
|
|
|
|
server_obj = json.loads(read_file)
|
2022-10-07 16:51:40 -04:00
|
|
|
return server_obj["TLS"]
|
2022-06-16 14:25:24 -04:00
|
|
|
except:
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("TLS", True)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def soundOn(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if "soundon" not in self.config:
|
|
|
|
self.set("soundon", True)
|
|
|
|
return self.config["soundon"]
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def chatSound(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("chatSound", True)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def memoSound(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("memoSound", True)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def memoPing(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("pingSound", True)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def nameSound(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("nameSound", True)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def volume(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("volume", 100)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def trayMessage(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return self.config.get("traymsg", True)
|
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def set(self, item, setting):
|
|
|
|
self.config[item] = setting
|
|
|
|
try:
|
|
|
|
jsonoutput = json.dumps(self.config)
|
2016-11-29 15:20:41 -05:00
|
|
|
except ValueError as e:
|
2011-09-12 22:02:00 -04:00
|
|
|
raise e
|
2022-10-07 16:51:40 -04:00
|
|
|
with open(self.filename, "w") as fp:
|
2016-11-29 15:20:41 -05:00
|
|
|
fp.write(jsonoutput)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def availableThemes(self):
|
|
|
|
themes = []
|
|
|
|
# Load user themes.
|
2022-10-07 16:51:40 -04:00
|
|
|
for dirname, dirnames, filenames in os.walk(_datadir + "themes"):
|
2011-09-12 22:02:00 -04:00
|
|
|
for d in dirnames:
|
|
|
|
themes.append(d)
|
2011-11-29 00:15:19 -05:00
|
|
|
# Also load embedded themes.
|
|
|
|
if _datadir:
|
2022-10-07 16:51:40 -04:00
|
|
|
for dirname, dirnames, filenames in os.walk("themes"):
|
2011-09-12 22:02:00 -04:00
|
|
|
for d in dirnames:
|
|
|
|
if d not in themes:
|
|
|
|
themes.append(d)
|
|
|
|
themes.sort()
|
|
|
|
return themes
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def availableProfiles(self):
|
|
|
|
profs = []
|
2022-10-07 16:51:40 -04:00
|
|
|
profileloc = _datadir + "profiles"
|
2011-09-12 22:02:00 -04:00
|
|
|
for dirname, dirnames, filenames in os.walk(profileloc):
|
|
|
|
for filename in filenames:
|
|
|
|
l = len(filename)
|
2022-10-07 16:51:40 -04:00
|
|
|
if filename[l - 3 : l] == ".js":
|
|
|
|
profs.append(filename[0 : l - 3])
|
2011-09-12 22:02:00 -04:00
|
|
|
profs.sort()
|
2022-03-17 21:05:14 -04:00
|
|
|
PchumLog.info("Profiles: %s" % str(profs))
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-03-17 21:05:14 -04:00
|
|
|
# Validity check
|
|
|
|
PchumLog.info("Starting profile check. . .")
|
|
|
|
for x in profs:
|
2022-10-07 16:51:40 -04:00
|
|
|
c_profile = os.path.join(profileloc, x + ".js")
|
2022-03-17 21:05:14 -04:00
|
|
|
try:
|
2022-04-10 23:57:13 -04:00
|
|
|
json.load(open(c_profile))
|
2022-03-17 21:05:14 -04:00
|
|
|
PchumLog.info(x + ": Pass.")
|
|
|
|
except json.JSONDecodeError as e:
|
|
|
|
PchumLog.warning(x + ": Fail.")
|
|
|
|
PchumLog.warning(e)
|
|
|
|
profs.remove(x)
|
|
|
|
PchumLog.warning(x + " removed from profile list.")
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-03-17 21:05:14 -04:00
|
|
|
msgBox = QtWidgets.QMessageBox()
|
2022-06-28 19:50:08 -04:00
|
|
|
msgBox.setIcon(QtWidgets.QMessageBox.Icon.Warning)
|
2022-03-17 21:05:14 -04:00
|
|
|
msgBox.setWindowTitle(":(")
|
2022-10-07 16:51:40 -04:00
|
|
|
msgBox.setTextFormat(
|
|
|
|
QtCore.Qt.TextFormat.RichText
|
|
|
|
) # Clickable html links
|
|
|
|
self.filename = _datadir + "pesterchum.js"
|
|
|
|
msgBox.setText(
|
|
|
|
"<html><h3>Failed to load "
|
|
|
|
+ x
|
|
|
|
+ ", removed from list."
|
|
|
|
+ "<br><br>Consider taking a look at: <a href="
|
|
|
|
+ profileloc
|
|
|
|
+ ">"
|
|
|
|
+ os.path.join(profileloc, x + ".js")
|
|
|
|
+ "</a>"
|
|
|
|
+ "<br><br>"
|
|
|
|
+ str(e)
|
2023-01-14 16:59:59 -05:00
|
|
|
+ r"<\h3><\html>"
|
2022-10-07 16:51:40 -04:00
|
|
|
)
|
|
|
|
# "\" if pesterchum acts oddly you might want to try backing up and then deleting \"" + \
|
|
|
|
# _datadir+"pesterchum.js" + \
|
|
|
|
# "\"")
|
2022-03-17 21:05:14 -04:00
|
|
|
PchumLog.critical(e)
|
2022-06-26 22:18:37 -04:00
|
|
|
msgBox.exec()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
return [userProfile(p) for p in profs]
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2023-01-14 16:59:59 -05:00
|
|
|
class userProfile:
|
2011-09-12 22:02:00 -04:00
|
|
|
def __init__(self, user):
|
2022-10-07 16:51:40 -04:00
|
|
|
self.profiledir = _datadir + "profiles"
|
2011-09-12 22:02:00 -04:00
|
|
|
|
|
|
|
if type(user) is PesterProfile:
|
|
|
|
self.chat = user
|
2022-10-07 16:51:40 -04:00
|
|
|
self.userprofile = {
|
|
|
|
"handle": user.handle,
|
|
|
|
"color": str(user.color.name()),
|
|
|
|
"quirks": [],
|
|
|
|
"theme": "pesterchum",
|
|
|
|
}
|
2011-09-12 22:02:00 -04:00
|
|
|
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:
|
2022-10-07 16:51:40 -04:00
|
|
|
initials = (
|
|
|
|
initials,
|
2023-01-14 16:59:59 -05:00
|
|
|
"{}{}".format(initials[0].lower(), initials[1]),
|
|
|
|
"{}{}".format(initials[0], initials[1].lower()),
|
2022-10-07 16:51:40 -04:00
|
|
|
)
|
2011-09-12 22:02:00 -04:00
|
|
|
self.mentions = [r"\b(%s)\b" % ("|".join(initials))]
|
|
|
|
else:
|
|
|
|
self.mentions = []
|
2014-01-12 20:50:01 -05:00
|
|
|
self.autojoins = []
|
2011-09-12 22:02:00 -04:00
|
|
|
else:
|
2021-02-13 19:47:06 -05:00
|
|
|
# Trying to fix:
|
|
|
|
# IOError: [Errno 2]
|
|
|
|
# No such file or directory:
|
|
|
|
# u'XXX\\AppData\\Local\\pesterchum/profiles/XXX.js'
|
|
|
|
# Part 3 :(
|
|
|
|
try:
|
2023-01-14 16:59:59 -05:00
|
|
|
with open("{}/{}.js".format(self.profiledir, user)) as fp:
|
2021-02-13 19:47:06 -05:00
|
|
|
self.userprofile = json.load(fp)
|
2022-03-17 23:09:48 -04:00
|
|
|
except (json.JSONDecodeError, FileNotFoundError) as e:
|
2021-03-23 17:36:43 -04:00
|
|
|
msgBox = QtWidgets.QMessageBox()
|
2022-06-28 19:50:08 -04:00
|
|
|
msgBox.setIcon(QtWidgets.QMessageBox.Icon.Warning)
|
2021-02-13 19:47:06 -05:00
|
|
|
msgBox.setWindowTitle(":(")
|
2022-10-07 16:51:40 -04:00
|
|
|
msgBox.setTextFormat(
|
|
|
|
QtCore.Qt.TextFormat.RichText
|
|
|
|
) # Clickable html links
|
|
|
|
self.filename = _datadir + "pesterchum.js"
|
|
|
|
msgBox.setText(
|
|
|
|
"<html><h3>Failed to load: "
|
|
|
|
+ (
|
|
|
|
"<a href='%s'>%s/%s.js</a>"
|
|
|
|
% (self.profiledir, self.profiledir, user)
|
|
|
|
)
|
|
|
|
+ "<br><br> Try to check for syntax errors if the file exists."
|
|
|
|
+ "<br><br>If you got this message at launch you may want to change your default profile."
|
|
|
|
+ "<br><br>"
|
|
|
|
+ str(e)
|
2023-01-14 16:59:59 -05:00
|
|
|
+ r"<\h3><\html>"
|
2022-10-07 16:51:40 -04:00
|
|
|
)
|
|
|
|
# "\" if pesterchum acts oddly you might want to try backing up and then deleting \"" + \
|
|
|
|
# _datadir+"pesterchum.js" + \
|
|
|
|
# "\"")
|
2022-03-17 21:05:14 -04:00
|
|
|
PchumLog.critical(e)
|
2022-06-26 22:18:37 -04:00
|
|
|
msgBox.exec()
|
2022-03-17 21:05:14 -04:00
|
|
|
raise ValueError(e)
|
2021-02-13 19:47:06 -05:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
try:
|
|
|
|
self.theme = pesterTheme(self.userprofile["theme"])
|
2016-11-29 15:20:41 -05:00
|
|
|
except ValueError:
|
2011-09-12 22:02:00 -04:00
|
|
|
self.theme = pesterTheme("pesterchum")
|
2022-10-07 16:51:40 -04:00
|
|
|
self.lastmood = self.userprofile.get(
|
|
|
|
"lastmood", self.theme["main/defaultmood"]
|
|
|
|
)
|
|
|
|
self.chat = PesterProfile(
|
|
|
|
self.userprofile["handle"],
|
|
|
|
QtGui.QColor(self.userprofile["color"]),
|
|
|
|
Mood(self.lastmood),
|
|
|
|
)
|
2011-09-12 22:02:00 -04:00
|
|
|
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:
|
2022-10-07 16:51:40 -04:00
|
|
|
initials = (
|
|
|
|
initials,
|
2023-01-14 16:59:59 -05:00
|
|
|
"{}{}".format(initials[0].lower(), initials[1]),
|
|
|
|
"{}{}".format(initials[0], initials[1].lower()),
|
2022-10-07 16:51:40 -04:00
|
|
|
)
|
2011-09-12 22:02:00 -04:00
|
|
|
self.userprofile["mentions"] = [r"\b(%s)\b" % ("|".join(initials))]
|
|
|
|
else:
|
|
|
|
self.userprofile["mentions"] = []
|
|
|
|
self.mentions = self.userprofile["mentions"]
|
2014-01-12 20:50:01 -05:00
|
|
|
if "autojoins" not in self.userprofile:
|
|
|
|
self.userprofile["autojoins"] = []
|
|
|
|
self.autojoins = self.userprofile["autojoins"]
|
2011-09-12 22:02:00 -04:00
|
|
|
|
2014-03-18 02:07:26 -04:00
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
with open(_datadir + "passwd.js") as fp:
|
2014-01-12 03:14:16 -05:00
|
|
|
self.passwd = json.load(fp)
|
2016-11-29 15:20:41 -05:00
|
|
|
except:
|
2014-03-18 02:07:26 -04:00
|
|
|
self.passwd = {}
|
2014-01-12 03:14:16 -05:00
|
|
|
self.autoidentify = False
|
|
|
|
self.nickservpass = ""
|
|
|
|
if self.chat.handle in self.passwd:
|
2021-02-25 13:51:05 -05:00
|
|
|
# Fix for:
|
2022-10-07 16:51:40 -04:00
|
|
|
# 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'
|
2021-02-25 13:51:05 -05:00
|
|
|
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"]
|
2014-01-12 03:14:16 -05:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def setMood(self, mood):
|
|
|
|
self.chat.mood = mood
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def setTheme(self, theme):
|
|
|
|
self.theme = theme
|
|
|
|
self.userprofile["theme"] = theme.name
|
|
|
|
self.save()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def setColor(self, color):
|
|
|
|
self.chat.color = color
|
2021-03-23 17:36:43 -04:00
|
|
|
self.userprofile["color"] = str(color.name())
|
2011-09-12 22:02:00 -04:00
|
|
|
self.save()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def setQuirks(self, quirks):
|
|
|
|
self.quirks = quirks
|
|
|
|
self.userprofile["quirks"] = self.quirks.plainList()
|
|
|
|
self.save()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def getRandom(self):
|
|
|
|
return self.randoms
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def setRandom(self, random):
|
|
|
|
self.randoms = random
|
|
|
|
self.userprofile["randoms"] = random
|
|
|
|
self.save()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def getMentions(self):
|
|
|
|
return self.mentions
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def setMentions(self, mentions):
|
2023-01-14 15:52:07 -05:00
|
|
|
i = None
|
2011-09-12 22:02:00 -04:00
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
for (i, m) in enumerate(mentions):
|
2011-09-12 22:02:00 -04:00
|
|
|
re.compile(m)
|
2021-03-23 17:36:43 -04:00
|
|
|
except re.error as e:
|
2023-01-14 16:59:59 -05:00
|
|
|
PchumLog.error("#{} Not a valid regular expression: {}".format(i, e))
|
2011-09-12 22:02:00 -04:00
|
|
|
else:
|
|
|
|
self.mentions = mentions
|
|
|
|
self.userprofile["mentions"] = mentions
|
|
|
|
self.save()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def getLastMood(self):
|
|
|
|
return self.lastmood
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def setLastMood(self, mood):
|
|
|
|
self.lastmood = mood.value()
|
|
|
|
self.userprofile["lastmood"] = self.lastmood
|
|
|
|
self.save()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def getTheme(self):
|
|
|
|
return self.theme
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2014-01-12 03:14:16 -05:00
|
|
|
def getAutoIdentify(self):
|
|
|
|
return self.autoidentify
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2014-01-12 03:14:16 -05:00
|
|
|
def setAutoIdentify(self, b):
|
|
|
|
self.autoidentify = b
|
2014-01-12 20:49:18 -05:00
|
|
|
if self.chat.handle not in self.passwd:
|
|
|
|
self.passwd[self.chat.handle] = {}
|
2014-01-12 03:14:16 -05:00
|
|
|
self.passwd[self.chat.handle]["auto"] = b
|
|
|
|
self.saveNickServPass()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2014-01-12 03:14:16 -05:00
|
|
|
def getNickServPass(self):
|
|
|
|
return self.nickservpass
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2014-01-12 03:14:16 -05:00
|
|
|
def setNickServPass(self, pw):
|
|
|
|
self.nickservpass = pw
|
2014-01-12 20:49:18 -05:00
|
|
|
if self.chat.handle not in self.passwd:
|
|
|
|
self.passwd[self.chat.handle] = {}
|
2014-01-12 03:14:16 -05:00
|
|
|
self.passwd[self.chat.handle]["pw"] = pw
|
|
|
|
self.saveNickServPass()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2014-01-12 20:50:01 -05:00
|
|
|
def getAutoJoins(self):
|
|
|
|
return self.autojoins
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2014-01-12 20:50:01 -05:00
|
|
|
def setAutoJoins(self, autojoins):
|
|
|
|
self.autojoins = autojoins
|
|
|
|
self.userprofile["autojoins"] = self.autojoins
|
|
|
|
self.save()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def save(self):
|
|
|
|
handle = self.chat.handle
|
|
|
|
if handle[0:12] == "pesterClient":
|
|
|
|
# dont save temp profiles
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
jsonoutput = json.dumps(self.userprofile)
|
2016-11-29 15:20:41 -05:00
|
|
|
except ValueError as e:
|
2011-09-12 22:02:00 -04:00
|
|
|
raise e
|
2023-01-14 16:59:59 -05:00
|
|
|
with open("{}/{}.js".format(self.profiledir, handle), "w") as fp:
|
2016-11-29 15:20:41 -05:00
|
|
|
fp.write(jsonoutput)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2014-01-12 03:14:16 -05:00
|
|
|
def saveNickServPass(self):
|
2014-01-12 20:49:18 -05:00
|
|
|
# remove profiles with no passwords
|
2022-10-07 16:51:40 -04:00
|
|
|
for h, t in list(self.passwd.items()):
|
2016-12-12 15:11:50 -05:00
|
|
|
if "auto" not in t and ("pw" not in t or t["pw"] == ""):
|
2014-01-12 20:49:18 -05:00
|
|
|
del self.passwd[h]
|
2014-01-12 03:14:16 -05:00
|
|
|
try:
|
|
|
|
jsonoutput = json.dumps(self.passwd, indent=4)
|
2016-11-29 15:20:41 -05:00
|
|
|
except ValueError as e:
|
2014-01-12 03:14:16 -05:00
|
|
|
raise e
|
2022-10-07 16:51:40 -04:00
|
|
|
with open(_datadir + "passwd.js", "w") as fp:
|
2014-01-12 03:14:16 -05:00
|
|
|
fp.write(jsonoutput)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
@staticmethod
|
|
|
|
def newUserProfile(chatprofile):
|
2023-01-14 16:59:59 -05:00
|
|
|
if os.path.exists("{}/{}.js".format(_datadir + "profiles", chatprofile.handle)):
|
2011-09-12 22:02:00 -04:00
|
|
|
newprofile = userProfile(chatprofile.handle)
|
|
|
|
else:
|
|
|
|
newprofile = userProfile(chatprofile)
|
|
|
|
newprofile.save()
|
|
|
|
return newprofile
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
class PesterProfileDB(dict):
|
|
|
|
def __init__(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
self.logpath = _datadir + "logs"
|
2011-09-12 22:02:00 -04:00
|
|
|
|
|
|
|
if not os.path.exists(self.logpath):
|
|
|
|
os.makedirs(self.logpath)
|
|
|
|
try:
|
2023-01-14 16:59:59 -05:00
|
|
|
with open("%s/chums.js" % (self.logpath)) as fp:
|
2016-11-29 15:20:41 -05:00
|
|
|
chumdict = json.load(fp)
|
2023-01-14 16:59:59 -05:00
|
|
|
except (OSError, ValueError):
|
2016-11-29 15:20:41 -05:00
|
|
|
# karxi: This code feels awfully familiar....
|
2011-09-12 22:02:00 -04:00
|
|
|
chumdict = {}
|
2022-10-07 16:51:40 -04:00
|
|
|
with open("%s/chums.js" % (self.logpath), "w") as fp:
|
2016-11-29 15:20:41 -05:00
|
|
|
json.dump(chumdict, fp)
|
2011-09-12 22:02:00 -04:00
|
|
|
|
|
|
|
u = []
|
2021-03-23 17:36:43 -04:00
|
|
|
for (handle, c) in chumdict.items():
|
2011-09-12 22:02:00 -04:00
|
|
|
options = dict()
|
2022-10-07 16:51:40 -04:00
|
|
|
if "group" in c:
|
|
|
|
options["group"] = c["group"]
|
|
|
|
if "notes" in c:
|
|
|
|
options["notes"] = c["notes"]
|
|
|
|
if "color" not in c:
|
|
|
|
c["color"] = "#000000"
|
|
|
|
if "mood" not in c:
|
|
|
|
c["mood"] = "offline"
|
|
|
|
u.append(
|
|
|
|
(
|
|
|
|
handle,
|
|
|
|
PesterProfile(
|
|
|
|
handle,
|
|
|
|
color=QtGui.QColor(c["color"]),
|
|
|
|
mood=Mood(c["mood"]),
|
2023-01-14 16:52:30 -05:00
|
|
|
**options,
|
2022-10-07 16:51:40 -04:00
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
2011-09-12 22:02:00 -04:00
|
|
|
converted = dict(u)
|
|
|
|
self.update(converted)
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
with open("%s/chums.js" % (self.logpath), "w") as fp:
|
2021-03-23 17:36:43 -04:00
|
|
|
chumdict = dict([p.plaindict() for p in self.values()])
|
2016-11-29 15:20:41 -05:00
|
|
|
json.dump(chumdict, fp)
|
|
|
|
except Exception as e:
|
2011-09-12 22:02:00 -04:00
|
|
|
raise e
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def getColor(self, handle, default=None):
|
2021-03-23 17:36:43 -04:00
|
|
|
if handle not in self:
|
2011-09-12 22:02:00 -04:00
|
|
|
return default
|
|
|
|
else:
|
|
|
|
return self[handle].color
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def setColor(self, handle, color):
|
2021-03-23 17:36:43 -04:00
|
|
|
if handle in self:
|
2011-09-12 22:02:00 -04:00
|
|
|
self[handle].color = color
|
|
|
|
else:
|
|
|
|
self[handle] = PesterProfile(handle, color)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def getGroup(self, handle, default="Chums"):
|
2021-03-23 17:36:43 -04:00
|
|
|
if handle not in self:
|
2011-09-12 22:02:00 -04:00
|
|
|
return default
|
|
|
|
else:
|
|
|
|
return self[handle].group
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def setGroup(self, handle, theGroup):
|
2021-03-23 17:36:43 -04:00
|
|
|
if handle in self:
|
2011-09-12 22:02:00 -04:00
|
|
|
self[handle].group = theGroup
|
|
|
|
else:
|
|
|
|
self[handle] = PesterProfile(handle, group=theGroup)
|
|
|
|
self.save()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def getNotes(self, handle, default=""):
|
2021-03-23 17:36:43 -04:00
|
|
|
if handle not in self:
|
2011-09-12 22:02:00 -04:00
|
|
|
return default
|
|
|
|
else:
|
|
|
|
return self[handle].notes
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def setNotes(self, handle, notes):
|
2021-03-23 17:36:43 -04:00
|
|
|
if handle in self:
|
2011-09-12 22:02:00 -04:00
|
|
|
self[handle].notes = notes
|
|
|
|
else:
|
|
|
|
self[handle] = PesterProfile(handle, notes=notes)
|
|
|
|
self.save()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def __setitem__(self, key, val):
|
|
|
|
dict.__setitem__(self, key, val)
|
|
|
|
self.save()
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
class pesterTheme(dict):
|
|
|
|
def __init__(self, name, default=False):
|
2022-10-07 16:51:40 -04:00
|
|
|
possiblepaths = (
|
|
|
|
_datadir + "themes/%s" % (name),
|
|
|
|
"themes/%s" % (name),
|
|
|
|
_datadir + "themes/pesterchum",
|
|
|
|
"themes/pesterchum",
|
|
|
|
)
|
2011-11-29 00:15:19 -05:00
|
|
|
self.path = "themes/pesterchum"
|
|
|
|
for p in possiblepaths:
|
|
|
|
if os.path.exists(p):
|
|
|
|
self.path = p
|
|
|
|
break
|
2011-09-12 22:02:00 -04:00
|
|
|
|
|
|
|
self.name = name
|
2011-09-13 00:15:35 -04:00
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
with open(self.path + "/style.js") as fp:
|
2016-11-29 15:20:41 -05:00
|
|
|
theme = json.load(fp, object_hook=self.pathHook)
|
2023-01-14 16:59:59 -05:00
|
|
|
except OSError:
|
2011-09-13 00:15:35 -04:00
|
|
|
theme = json.loads("{}")
|
2011-09-12 22:02:00 -04:00
|
|
|
self.update(theme)
|
2021-03-23 17:36:43 -04:00
|
|
|
if "inherits" in self:
|
2011-09-12 22:02:00 -04:00
|
|
|
self.inheritedTheme = pesterTheme(self["inherits"])
|
|
|
|
if not default:
|
|
|
|
self.defaultTheme = pesterTheme("pesterchum", default=True)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def __getitem__(self, key):
|
|
|
|
keys = key.split("/")
|
|
|
|
try:
|
2023-01-14 16:59:59 -05:00
|
|
|
v = super().__getitem__(keys.pop(0))
|
2016-11-29 15:20:41 -05:00
|
|
|
except KeyError as e:
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "inheritedTheme"):
|
|
|
|
return self.inheritedTheme[key]
|
|
|
|
elif hasattr(self, "defaultTheme"):
|
|
|
|
return self.defaultTheme[key]
|
|
|
|
else:
|
|
|
|
raise e
|
2011-09-12 22:02:00 -04:00
|
|
|
for k in keys:
|
|
|
|
try:
|
|
|
|
v = v[k]
|
2016-11-29 15:20:41 -05:00
|
|
|
except KeyError as e:
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "inheritedTheme"):
|
2011-09-12 22:02:00 -04:00
|
|
|
return self.inheritedTheme[key]
|
2022-10-07 16:51:40 -04:00
|
|
|
elif hasattr(self, "defaultTheme"):
|
2011-09-12 22:02:00 -04:00
|
|
|
return self.defaultTheme[key]
|
|
|
|
else:
|
|
|
|
raise e
|
|
|
|
return v
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def pathHook(self, d):
|
2021-03-23 17:36:43 -04:00
|
|
|
for (k, v) in d.items():
|
|
|
|
if isinstance(v, str):
|
2011-09-12 22:02:00 -04:00
|
|
|
s = Template(v)
|
|
|
|
d[k] = s.safe_substitute(path=self.path)
|
|
|
|
return d
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-09-12 22:02:00 -04:00
|
|
|
def get(self, key, default):
|
|
|
|
keys = key.split("/")
|
|
|
|
try:
|
2023-01-14 16:59:59 -05:00
|
|
|
v = super().__getitem__(keys.pop(0))
|
2011-09-12 22:02:00 -04:00
|
|
|
for k in keys:
|
|
|
|
v = v[k]
|
|
|
|
return default if v is None else v
|
|
|
|
except KeyError:
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "inheritedTheme"):
|
2011-09-12 22:02:00 -04:00
|
|
|
return self.inheritedTheme.get(key, default)
|
|
|
|
else:
|
|
|
|
return default
|
|
|
|
|
|
|
|
def has_key(self, key):
|
|
|
|
keys = key.split("/")
|
|
|
|
try:
|
2023-01-14 16:59:59 -05:00
|
|
|
v = super().__getitem__(keys.pop(0))
|
2011-09-12 22:02:00 -04:00
|
|
|
for k in keys:
|
|
|
|
v = v[k]
|
2022-10-07 16:51:40 -04:00
|
|
|
return v is not None
|
2011-09-12 22:02:00 -04:00
|
|
|
except KeyError:
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "inheritedTheme"):
|
2021-03-23 17:36:43 -04:00
|
|
|
return key in self.inheritedTheme
|
2011-09-12 22:02:00 -04:00
|
|
|
else:
|
|
|
|
return False
|