2023-02-22 19:25:13 -05:00
|
|
|
import re
|
|
|
|
import random
|
|
|
|
import itertools
|
2022-03-19 19:48:19 -04:00
|
|
|
import logging
|
2023-02-22 19:25:13 -05:00
|
|
|
from datetime import datetime
|
2022-10-07 16:51:40 -04:00
|
|
|
|
|
|
|
PchumLog = logging.getLogger("pchumLogger")
|
2022-08-19 07:12:58 -04:00
|
|
|
try:
|
|
|
|
from PyQt6 import QtGui
|
|
|
|
except ImportError:
|
|
|
|
print("PyQt5 fallback (dataobjs.py)")
|
|
|
|
from PyQt5 import QtGui
|
2011-02-03 01:20:37 -05:00
|
|
|
|
2011-09-15 03:09:56 -04:00
|
|
|
from mood import Mood
|
2022-10-07 16:51:40 -04:00
|
|
|
from parsetools import (
|
|
|
|
timeDifference,
|
|
|
|
convertTags,
|
|
|
|
lexMessage,
|
|
|
|
parseRegexpFunctions,
|
|
|
|
smiledict,
|
|
|
|
)
|
2011-02-13 20:32:02 -05:00
|
|
|
from mispeller import mispeller
|
|
|
|
|
2022-06-16 23:23:52 -04:00
|
|
|
_urlre = re.compile(r"(?i)(?:^|(?<=\s))(?:(?:https?|ftp)://|magnet:)[^\s]+")
|
2022-10-07 16:51:40 -04:00
|
|
|
# _url2re = re.compile(r"(?i)(?<!//)\bwww\.[^\s]+?\.")
|
2011-04-10 05:22:06 -04:00
|
|
|
_groupre = re.compile(r"\\([0-9]+)")
|
|
|
|
_upperre = re.compile(r"upper\(([\w<>\\]+)\)")
|
|
|
|
_lowerre = re.compile(r"lower\(([\w<>\\]+)\)")
|
|
|
|
_scramblere = re.compile(r"scramble\(([\w<>\\]+)\)")
|
|
|
|
_reversere = re.compile(r"reverse\(([\w<>\\]+)\)")
|
2022-06-16 23:23:52 -04:00
|
|
|
_ctagre = re.compile("(</?c=?.*?>)", re.I)
|
2022-06-21 15:50:48 -04:00
|
|
|
_smilere = re.compile("|".join(list(smiledict.keys())))
|
|
|
|
_memore = re.compile(r"(\s|^)(#[A-Za-z0-9_]+)")
|
|
|
|
_handlere = re.compile(r"(\s|^)(@[A-Za-z0-9_]+)")
|
2023-02-22 20:12:16 -05:00
|
|
|
_alternian = re.compile(r"<alt>.*?</alt>")
|
2011-02-03 01:20:37 -05:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2023-01-14 16:59:59 -05:00
|
|
|
class pesterQuirk:
|
2011-02-03 01:20:37 -05:00
|
|
|
def __init__(self, quirk):
|
2023-02-15 11:01:27 -05:00
|
|
|
if not isinstance(quirk, dict):
|
2011-02-03 01:20:37 -05:00
|
|
|
raise ValueError("Quirks must be given a dictionary")
|
|
|
|
self.quirk = quirk
|
|
|
|
self.type = self.quirk["type"]
|
2011-04-17 03:46:11 -04:00
|
|
|
if "on" not in self.quirk:
|
|
|
|
self.quirk["on"] = True
|
|
|
|
self.on = self.quirk["on"]
|
2011-05-25 04:38:36 -04:00
|
|
|
if "group" not in self.quirk:
|
|
|
|
self.quirk["group"] = "Miscellaneous"
|
|
|
|
self.group = self.quirk["group"]
|
2022-06-21 15:50:48 -04:00
|
|
|
try:
|
|
|
|
self.checkstate = self.quirk["checkstate"]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-06-23 13:14:28 -04:00
|
|
|
def apply(self, string, first=False, last=False):
|
2011-04-17 03:46:11 -04:00
|
|
|
if not self.on:
|
|
|
|
return string
|
|
|
|
elif self.type == "prefix":
|
2011-02-03 01:20:37 -05:00
|
|
|
return self.quirk["value"] + string
|
2011-02-13 04:27:12 -05:00
|
|
|
elif self.type == "suffix":
|
2011-02-03 01:20:37 -05:00
|
|
|
return string + self.quirk["value"]
|
2011-02-13 04:27:12 -05:00
|
|
|
elif self.type == "replace":
|
2022-06-23 13:14:28 -04:00
|
|
|
return string.replace(self.quirk["from"], self.quirk["to"])
|
2011-02-13 04:27:12 -05:00
|
|
|
elif self.type == "regexp":
|
|
|
|
fr = self.quirk["from"]
|
|
|
|
if not first and len(fr) > 0 and fr[0] == "^":
|
|
|
|
return string
|
2022-10-07 16:51:40 -04:00
|
|
|
if not last and len(fr) > 0 and fr[len(fr) - 1] == "$":
|
2011-02-13 04:27:12 -05:00
|
|
|
return string
|
2011-04-14 03:07:05 -04:00
|
|
|
to = self.quirk["to"]
|
|
|
|
pt = parseRegexpFunctions(to)
|
2022-06-23 13:14:28 -04:00
|
|
|
return re.sub(fr, pt.expand, string)
|
2011-02-13 04:27:12 -05:00
|
|
|
elif self.type == "random":
|
2011-02-21 18:58:07 -05:00
|
|
|
if len(self.quirk["randomlist"]) == 0:
|
|
|
|
return string
|
2022-06-23 13:14:28 -04:00
|
|
|
fr = self.quirk["from"]
|
2011-02-13 04:27:12 -05:00
|
|
|
if not first and len(fr) > 0 and fr[0] == "^":
|
|
|
|
return string
|
2022-10-07 16:51:40 -04:00
|
|
|
if not last and len(fr) > 0 and fr[len(fr) - 1] == "$":
|
2011-02-13 04:27:12 -05:00
|
|
|
return string
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-13 04:27:12 -05:00
|
|
|
def randomrep(mo):
|
|
|
|
choice = random.choice(self.quirk["randomlist"])
|
2011-04-14 03:07:05 -04:00
|
|
|
pt = parseRegexpFunctions(choice)
|
|
|
|
return pt.expand(mo)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-06-23 13:14:28 -04:00
|
|
|
return re.sub(self.quirk["from"], randomrep, string)
|
2011-02-13 20:32:02 -05:00
|
|
|
elif self.type == "spelling":
|
2022-10-07 16:51:40 -04:00
|
|
|
percentage = self.quirk["percentage"] / 100.0
|
2011-02-13 20:32:02 -05:00
|
|
|
words = string.split(" ")
|
|
|
|
newl = []
|
2022-06-23 13:14:28 -04:00
|
|
|
ctag = re.compile("(</?c=?.*?>)", re.I)
|
2011-02-13 20:32:02 -05:00
|
|
|
for w in words:
|
2022-06-23 13:14:28 -04:00
|
|
|
p = random.random()
|
|
|
|
if not ctag.search(w) and p < percentage:
|
|
|
|
newl.append(mispeller(w))
|
|
|
|
elif p < percentage:
|
|
|
|
split = ctag.split(w)
|
|
|
|
tmp = []
|
|
|
|
for s in split:
|
|
|
|
if s and not ctag.search(s):
|
|
|
|
tmp.append(mispeller(s))
|
2011-09-08 00:56:47 -04:00
|
|
|
else:
|
2022-06-23 13:14:28 -04:00
|
|
|
tmp.append(s)
|
|
|
|
newl.append("".join(tmp))
|
2011-02-13 20:32:02 -05:00
|
|
|
else:
|
2022-06-23 13:14:28 -04:00
|
|
|
newl.append(w)
|
2011-02-13 20:32:02 -05:00
|
|
|
return " ".join(newl)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
def __str__(self):
|
|
|
|
if self.type == "prefix":
|
|
|
|
return "BEGIN WITH: %s" % (self.quirk["value"])
|
|
|
|
elif self.type == "suffix":
|
|
|
|
return "END WITH: %s" % (self.quirk["value"])
|
|
|
|
elif self.type == "replace":
|
2023-01-14 16:59:59 -05:00
|
|
|
return "REPLACE {} WITH {}".format(self.quirk["from"], self.quirk["to"])
|
2011-02-03 01:20:37 -05:00
|
|
|
elif self.type == "regexp":
|
2023-01-14 16:59:59 -05:00
|
|
|
return "REGEXP: {} REPLACED WITH {}".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
self.quirk["from"],
|
|
|
|
self.quirk["to"],
|
|
|
|
)
|
2011-02-13 04:27:12 -05:00
|
|
|
elif self.type == "random":
|
2023-01-14 16:59:59 -05:00
|
|
|
return "REGEXP: {} RANDOMLY REPLACED WITH {}".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
self.quirk["from"],
|
|
|
|
[r for r in self.quirk["randomlist"]],
|
|
|
|
)
|
2011-02-13 20:32:02 -05:00
|
|
|
elif self.type == "spelling":
|
|
|
|
return "MISPELLER: %d%%" % (self.quirk["percentage"])
|
2011-02-03 01:20:37 -05:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2023-01-14 16:59:59 -05:00
|
|
|
class pesterQuirks:
|
2011-02-03 01:20:37 -05:00
|
|
|
def __init__(self, quirklist):
|
|
|
|
self.quirklist = []
|
|
|
|
for q in quirklist:
|
2011-02-24 21:15:21 -05:00
|
|
|
self.addQuirk(q)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
def plainList(self):
|
|
|
|
return [q.quirk for q in self.quirklist]
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-24 21:15:21 -05:00
|
|
|
def addQuirk(self, q):
|
2023-02-15 11:01:27 -05:00
|
|
|
if isinstance(q, dict):
|
2011-02-24 21:15:21 -05:00
|
|
|
self.quirklist.append(pesterQuirk(q))
|
2023-02-15 11:01:27 -05:00
|
|
|
elif isinstance(q, pesterQuirk):
|
2011-02-24 21:15:21 -05:00
|
|
|
self.quirklist.append(q)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-13 04:27:12 -05:00
|
|
|
def apply(self, lexed, first=False, last=False):
|
2022-10-07 16:51:40 -04:00
|
|
|
prefix = [q for q in self.quirklist if q.type == "prefix"]
|
2022-11-17 02:44:23 -05:00
|
|
|
# suffix = [q for q in self.quirklist if q.type == "suffix"]
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-13 04:27:12 -05:00
|
|
|
newlist = []
|
2023-02-09 14:52:26 -05:00
|
|
|
for i, o in enumerate(lexed):
|
2023-02-19 15:10:35 -05:00
|
|
|
if not isinstance(o, str):
|
2011-02-13 05:30:08 -05:00
|
|
|
if i == 0:
|
|
|
|
string = " "
|
|
|
|
for p in prefix:
|
|
|
|
string += p.apply(string)
|
|
|
|
newlist.append(string)
|
2011-02-13 04:27:12 -05:00
|
|
|
newlist.append(o)
|
|
|
|
continue
|
2022-10-07 16:51:40 -04:00
|
|
|
lastStr = i == len(lexed) - 1
|
2011-02-13 04:27:12 -05:00
|
|
|
string = o
|
2011-05-05 05:26:36 -04:00
|
|
|
for q in self.quirklist:
|
2022-06-21 15:50:48 -04:00
|
|
|
try:
|
|
|
|
checkstate = int(q.checkstate)
|
|
|
|
except Exception:
|
|
|
|
checkstate = 0
|
2022-06-23 22:55:18 -04:00
|
|
|
|
|
|
|
# Exclude option is checked
|
|
|
|
if checkstate == 2:
|
|
|
|
# Check for substring that should be excluded.
|
2023-02-14 13:55:23 -05:00
|
|
|
excludes = []
|
2023-02-22 19:25:13 -05:00
|
|
|
# Return matches for links, smilies, handles, memos.
|
|
|
|
# Chain the iterators and add to excludes list.
|
|
|
|
matches = itertools.chain(
|
|
|
|
re.finditer(_urlre, string),
|
|
|
|
re.finditer(_smilere, string),
|
|
|
|
re.finditer(_handlere, string),
|
|
|
|
re.finditer(_memore, string),
|
2023-02-22 20:12:16 -05:00
|
|
|
re.finditer(_alternian, string),
|
2023-02-22 19:25:13 -05:00
|
|
|
)
|
|
|
|
excludes.extend(matches)
|
|
|
|
|
|
|
|
if excludes:
|
2022-06-23 22:55:18 -04:00
|
|
|
# SORT !!!
|
|
|
|
excludes.sort(key=lambda exclude: exclude.start())
|
2022-06-23 23:30:06 -04:00
|
|
|
# Recursion check.
|
|
|
|
# Strings like http://:3: require this.
|
2022-10-07 16:51:40 -04:00
|
|
|
for n in range(0, len(excludes) - 1):
|
|
|
|
if excludes[n].end() > excludes[n + 1].start():
|
2022-06-23 23:30:06 -04:00
|
|
|
excludes.pop(n)
|
2022-06-23 22:55:18 -04:00
|
|
|
# Seperate parts to be quirked.
|
2023-02-14 13:55:23 -05:00
|
|
|
sendparts = []
|
2022-06-23 22:55:18 -04:00
|
|
|
# Add string until start of exclude at index 0.
|
|
|
|
until = excludes[0].start()
|
2022-10-07 16:51:40 -04:00
|
|
|
sendparts.append(string[:until])
|
2022-06-23 22:55:18 -04:00
|
|
|
# Add strings between excludes.
|
|
|
|
for part in range(1, len(excludes)):
|
2022-10-07 16:51:40 -04:00
|
|
|
after = excludes[part - 1].end()
|
2022-06-23 22:55:18 -04:00
|
|
|
until = excludes[part].start()
|
|
|
|
sendparts.append(string[after:until])
|
|
|
|
# Add string after exclude at last index.
|
|
|
|
after = excludes[-1].end()
|
|
|
|
sendparts.append(string[after:])
|
|
|
|
|
|
|
|
# Quirk to-be-quirked parts.
|
2023-02-14 13:55:23 -05:00
|
|
|
recvparts = []
|
2022-06-23 22:55:18 -04:00
|
|
|
for part in sendparts:
|
|
|
|
# No split, apply like normal.
|
2023-02-14 13:55:23 -05:00
|
|
|
if q.type in ("regexp", "random"):
|
2022-10-07 16:51:40 -04:00
|
|
|
recvparts.append(
|
|
|
|
q.apply(part, first=(i == 0), last=lastStr)
|
|
|
|
)
|
|
|
|
elif q.type == "prefix" and i == 0:
|
2022-06-23 22:55:18 -04:00
|
|
|
recvparts.append(q.apply(part))
|
2022-10-07 16:51:40 -04:00
|
|
|
elif q.type == "suffix" and lastStr:
|
2022-06-23 22:55:18 -04:00
|
|
|
recvparts.append(q.apply(part))
|
|
|
|
else:
|
|
|
|
recvparts.append(q.apply(part))
|
|
|
|
# Reconstruct and update string.
|
2022-10-07 16:51:40 -04:00
|
|
|
string = ""
|
|
|
|
# print("excludes: " + str(excludes))
|
|
|
|
# print("sendparts: " + str(sendparts))
|
|
|
|
# print("recvparts: " + str(recvparts))
|
2023-02-16 20:22:50 -05:00
|
|
|
for part, exclude in enumerate(excludes):
|
2022-06-23 22:55:18 -04:00
|
|
|
string += recvparts[part]
|
2023-02-16 20:22:50 -05:00
|
|
|
string += exclude.group()
|
2022-06-23 22:55:18 -04:00
|
|
|
string += recvparts[-1]
|
|
|
|
else:
|
|
|
|
# No split, apply like normal.
|
2023-02-14 13:55:23 -05:00
|
|
|
if q.type not in ("prefix", "suffix"):
|
|
|
|
if q.type in ("regexp", "random"):
|
2022-10-07 16:51:40 -04:00
|
|
|
string = q.apply(string, first=(i == 0), last=lastStr)
|
2022-06-23 22:55:18 -04:00
|
|
|
else:
|
|
|
|
string = q.apply(string)
|
2022-10-07 16:51:40 -04:00
|
|
|
elif q.type == "prefix" and i == 0:
|
2022-06-23 22:55:18 -04:00
|
|
|
string = q.apply(string)
|
2022-10-07 16:51:40 -04:00
|
|
|
elif q.type == "suffix" and lastStr:
|
2022-06-23 22:55:18 -04:00
|
|
|
string = q.apply(string)
|
|
|
|
else:
|
2022-06-23 13:14:28 -04:00
|
|
|
# No split, apply like normal.
|
2023-02-14 13:55:23 -05:00
|
|
|
if q.type not in ("prefix", "suffix"):
|
|
|
|
if q.type in ("regexp", "random"):
|
2022-10-07 16:51:40 -04:00
|
|
|
string = q.apply(string, first=(i == 0), last=lastStr)
|
2022-06-23 13:14:28 -04:00
|
|
|
else:
|
|
|
|
string = q.apply(string)
|
2022-10-07 16:51:40 -04:00
|
|
|
elif q.type == "prefix" and i == 0:
|
2011-05-05 05:26:36 -04:00
|
|
|
string = q.apply(string)
|
2022-10-07 16:51:40 -04:00
|
|
|
elif q.type == "suffix" and lastStr:
|
2022-06-23 13:14:28 -04:00
|
|
|
string = q.apply(string)
|
|
|
|
newlist.append(string)
|
2011-02-21 14:07:59 -05:00
|
|
|
final = []
|
|
|
|
for n in newlist:
|
2023-02-19 15:10:35 -05:00
|
|
|
if isinstance(n, str):
|
2011-02-21 14:07:59 -05:00
|
|
|
final.extend(lexMessage(n))
|
|
|
|
else:
|
|
|
|
final.append(n)
|
|
|
|
return final
|
2011-02-03 01:20:37 -05:00
|
|
|
|
|
|
|
def __iter__(self):
|
2023-01-14 16:59:59 -05:00
|
|
|
yield from self.quirklist
|
2011-02-03 01:20:37 -05:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2023-01-14 16:59:59 -05:00
|
|
|
class PesterProfile:
|
2022-10-07 16:51:40 -04:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
handle,
|
|
|
|
color=None,
|
|
|
|
mood=Mood("offline"),
|
|
|
|
group=None,
|
|
|
|
notes="",
|
|
|
|
chumdb=None,
|
|
|
|
):
|
2011-02-03 01:20:37 -05:00
|
|
|
self.handle = handle
|
|
|
|
if color is None:
|
|
|
|
if chumdb:
|
|
|
|
color = chumdb.getColor(handle, QtGui.QColor("black"))
|
|
|
|
else:
|
|
|
|
color = QtGui.QColor("black")
|
|
|
|
self.color = color
|
|
|
|
self.mood = mood
|
2011-04-14 03:04:33 -04:00
|
|
|
if group is None:
|
|
|
|
if chumdb:
|
|
|
|
group = chumdb.getGroup(handle, "Chums")
|
|
|
|
else:
|
|
|
|
group = "Chums"
|
|
|
|
self.group = group
|
2011-08-22 04:13:43 -04:00
|
|
|
self.notes = notes
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
def initials(self, time=None):
|
2011-02-03 01:20:37 -05:00
|
|
|
handle = self.handle
|
|
|
|
caps = [l for l in handle if l.isupper()]
|
|
|
|
if not caps:
|
|
|
|
caps = [""]
|
2023-02-13 14:26:05 -05:00
|
|
|
PchumLog.debug("handle = %s", handle)
|
|
|
|
PchumLog.debug("caps = %s", caps)
|
2021-08-24 09:49:50 -04:00
|
|
|
# Fallback for invalid string
|
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
initials = (handle[0] + caps[0]).upper()
|
2021-08-24 09:49:50 -04:00
|
|
|
except:
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog.exception("")
|
2021-08-24 09:49:50 -04:00
|
|
|
initials = "XX"
|
2023-02-13 14:26:05 -05:00
|
|
|
PchumLog.debug("initials = %s", initials)
|
2023-02-12 19:21:14 -05:00
|
|
|
if hasattr(self, "time"):
|
|
|
|
if time:
|
|
|
|
if self.time > time:
|
|
|
|
return "F" + initials
|
|
|
|
elif self.time < time:
|
|
|
|
return "P" + initials
|
|
|
|
else:
|
|
|
|
return "C" + initials
|
2011-02-05 12:17:33 -05:00
|
|
|
else:
|
2023-02-12 19:21:14 -05:00
|
|
|
return initials
|
2011-02-05 12:17:33 -05:00
|
|
|
else:
|
2021-08-24 09:49:50 -04:00
|
|
|
return initials
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
def colorhtml(self):
|
2011-03-03 04:03:41 -05:00
|
|
|
if self.color:
|
|
|
|
return self.color.name()
|
|
|
|
else:
|
|
|
|
return "#000000"
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
def colorcmd(self):
|
2011-03-03 04:03:41 -05:00
|
|
|
if self.color:
|
2023-02-15 16:49:52 -05:00
|
|
|
(r, g, b, _a) = self.color.getRgb()
|
2022-10-07 16:51:40 -04:00
|
|
|
return "%d,%d,%d" % (r, g, b)
|
2011-03-03 04:03:41 -05:00
|
|
|
else:
|
|
|
|
return "0,0,0"
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
def plaindict(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
return (
|
|
|
|
self.handle,
|
|
|
|
{
|
|
|
|
"handle": self.handle,
|
|
|
|
"mood": self.mood.name(),
|
|
|
|
"color": str(self.color.name()),
|
|
|
|
"group": str(self.group),
|
|
|
|
"notes": str(self.notes),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
def blocked(self, config):
|
|
|
|
return self.handle in config.getBlocklist()
|
|
|
|
|
2011-02-13 04:27:12 -05:00
|
|
|
def memsg(self, syscolor, lexmsg, time=None):
|
|
|
|
suffix = lexmsg[0].suffix
|
|
|
|
msg = convertTags(lexmsg[1:], "text")
|
2011-02-03 04:45:48 -05:00
|
|
|
uppersuffix = suffix.upper()
|
2011-02-05 12:17:33 -05:00
|
|
|
if time is not None:
|
2023-01-14 16:59:59 -05:00
|
|
|
handle = f"{time.temporal} {self.handle}"
|
2022-10-07 16:51:40 -04:00
|
|
|
initials = time.pcf + self.initials() + time.number + uppersuffix
|
2011-02-05 12:17:33 -05:00
|
|
|
else:
|
|
|
|
handle = self.handle
|
2022-10-07 16:51:40 -04:00
|
|
|
initials = self.initials() + uppersuffix
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}>-- {}{} <c={}>[{}]</c> {} --</c>".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
syscolor.name(),
|
|
|
|
handle,
|
|
|
|
suffix,
|
|
|
|
self.colorhtml(),
|
|
|
|
initials,
|
|
|
|
msg,
|
|
|
|
)
|
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
def pestermsg(self, otherchum, syscolor, verb):
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}>-- {} <c={}>[{}]</c> {} {} <c={}>[{}]</c> at {} --</c>".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
syscolor.name(),
|
|
|
|
self.handle,
|
|
|
|
self.colorhtml(),
|
|
|
|
self.initials(),
|
|
|
|
verb,
|
|
|
|
otherchum.handle,
|
|
|
|
otherchum.colorhtml(),
|
|
|
|
otherchum.initials(),
|
|
|
|
datetime.now().strftime("%H:%M"),
|
|
|
|
)
|
|
|
|
|
2011-02-10 13:00:06 -05:00
|
|
|
def moodmsg(self, mood, syscolor, theme):
|
2022-10-07 16:51:40 -04:00
|
|
|
return (
|
|
|
|
"<c=%s>-- %s <c=%s>[%s]</c> changed their mood to %s <img src='%s' /> --</c>"
|
|
|
|
% (
|
|
|
|
syscolor.name(),
|
|
|
|
self.handle,
|
|
|
|
self.colorhtml(),
|
|
|
|
self.initials(),
|
|
|
|
mood.name().upper(),
|
|
|
|
theme["main/chums/moods"][mood.name()]["icon"],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2011-02-10 20:55:45 -05:00
|
|
|
def idlemsg(self, syscolor, verb):
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}>-- {} <c={}>[{}]</c> {} --</c>".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
syscolor.name(),
|
|
|
|
self.handle,
|
|
|
|
self.colorhtml(),
|
|
|
|
self.initials(),
|
|
|
|
verb,
|
|
|
|
)
|
|
|
|
|
2011-07-02 17:10:59 -04:00
|
|
|
def memoclosemsg(self, syscolor, initials, verb):
|
2023-02-14 13:55:23 -05:00
|
|
|
if isinstance(initials, list):
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}><c={}>{}</c> {}.</c>".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
syscolor.name(),
|
|
|
|
self.colorhtml(),
|
|
|
|
", ".join(initials),
|
|
|
|
verb,
|
|
|
|
)
|
2023-02-14 13:55:23 -05:00
|
|
|
return "<c={}><c={}>{}{}{}</c> {}.</c>".format(
|
|
|
|
syscolor.name(),
|
|
|
|
self.colorhtml(),
|
|
|
|
initials.pcf,
|
|
|
|
self.initials(),
|
|
|
|
initials.number,
|
|
|
|
verb,
|
|
|
|
)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-07-17 04:58:19 -04:00
|
|
|
def memonetsplitmsg(self, syscolor, initials):
|
2011-08-23 06:58:16 -04:00
|
|
|
if len(initials) <= 0:
|
|
|
|
return "<c=%s>Netsplit quits: <c=black>None</c></c>" % (syscolor.name())
|
|
|
|
else:
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}>Netsplit quits: <c=black>{}</c></c>".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
syscolor.name(),
|
|
|
|
", ".join(initials),
|
|
|
|
)
|
|
|
|
|
2011-02-05 13:56:25 -05:00
|
|
|
def memoopenmsg(self, syscolor, td, timeGrammar, verb, channel):
|
2022-11-17 02:42:10 -05:00
|
|
|
"""timeGrammar.temporal and timeGrammar.when are unused"""
|
2011-02-05 13:56:25 -05:00
|
|
|
timetext = timeDifference(td)
|
2021-08-24 09:49:50 -04:00
|
|
|
PchumLog.debug("pre pcf+self.initials()")
|
2022-11-17 02:42:10 -05:00
|
|
|
initials = timeGrammar.pcf + self.initials()
|
2021-08-24 09:49:50 -04:00
|
|
|
PchumLog.debug("post pcf+self.initials()")
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}><c={}>{}</c> {} {} {}.</c>".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
syscolor.name(),
|
|
|
|
self.colorhtml(),
|
|
|
|
initials,
|
|
|
|
timetext,
|
|
|
|
verb,
|
|
|
|
channel[1:].upper().replace("_", " "),
|
|
|
|
)
|
|
|
|
|
2011-08-24 03:10:23 -04:00
|
|
|
def memobanmsg(self, opchum, opgrammar, syscolor, initials, reason):
|
2022-10-07 16:51:40 -04:00
|
|
|
opinit = opgrammar.pcf + opchum.initials() + opgrammar.number
|
2023-02-14 13:55:23 -05:00
|
|
|
if isinstance(initials, list):
|
2011-08-24 03:10:23 -04:00
|
|
|
if opchum.handle == reason:
|
2023-01-14 16:59:59 -05:00
|
|
|
return (
|
|
|
|
"<c={}>{}</c> banned <c={}>{}</c> from responding to memo.".format(
|
|
|
|
opchum.colorhtml(),
|
|
|
|
opinit,
|
|
|
|
self.colorhtml(),
|
|
|
|
", ".join(initials),
|
|
|
|
)
|
2022-10-07 16:51:40 -04:00
|
|
|
)
|
2011-08-24 03:10:23 -04:00
|
|
|
else:
|
2022-10-07 16:51:40 -04:00
|
|
|
return (
|
|
|
|
"<c=%s>%s</c> banned <c=%s>%s</c> from responding to memo: <c=black>[%s]</c>."
|
|
|
|
% (
|
|
|
|
opchum.colorhtml(),
|
|
|
|
opinit,
|
|
|
|
self.colorhtml(),
|
|
|
|
", ".join(initials),
|
2023-02-19 15:10:35 -05:00
|
|
|
reason,
|
2022-10-07 16:51:40 -04:00
|
|
|
)
|
|
|
|
)
|
2011-06-13 16:37:07 -04:00
|
|
|
else:
|
2023-02-12 19:21:14 -05:00
|
|
|
PchumLog.exception("")
|
|
|
|
initials = self.initials()
|
|
|
|
if opchum.handle == reason:
|
2023-02-12 19:34:13 -05:00
|
|
|
return "<c=%s>%s</c> banned <c=%s>%s</c> from responding to memo." % (
|
|
|
|
opchum.colorhtml(),
|
|
|
|
opinit,
|
|
|
|
self.colorhtml(),
|
|
|
|
initials,
|
2023-02-12 19:21:14 -05:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
return (
|
|
|
|
"<c=%s>%s</c> banned <c=%s>%s</c> from responding to memo: <c=black>[%s]</c>."
|
|
|
|
% (
|
|
|
|
opchum.colorhtml(),
|
|
|
|
opinit,
|
|
|
|
self.colorhtml(),
|
|
|
|
initials,
|
2023-02-19 15:10:35 -05:00
|
|
|
reason,
|
2022-10-07 16:51:40 -04:00
|
|
|
)
|
2023-02-12 19:21:14 -05:00
|
|
|
)
|
2022-04-10 23:57:13 -04:00
|
|
|
|
2022-06-30 03:59:34 -04:00
|
|
|
# As far as I'm aware, there's no IRC reply for this, this seems impossible to check for in practice.
|
2011-08-24 03:10:23 -04:00
|
|
|
def memopermabanmsg(self, opchum, opgrammar, syscolor, timeGrammar):
|
2022-10-07 16:51:40 -04:00
|
|
|
initials = timeGrammar.pcf + self.initials() + timeGrammar.number
|
|
|
|
opinit = opgrammar.pcf + opchum.initials() + opgrammar.number
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}>{}</c> permabanned <c={}>{}</c> from the memo.".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
opchum.colorhtml(),
|
|
|
|
opinit,
|
|
|
|
self.colorhtml(),
|
|
|
|
initials,
|
|
|
|
)
|
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
def memojoinmsg(self, syscolor, td, timeGrammar, verb):
|
2022-10-07 16:51:40 -04:00
|
|
|
# (temporal, pcf, when) = (timeGrammar.temporal, timeGrammar.pcf, timeGrammar.when)
|
2011-02-05 13:56:25 -05:00
|
|
|
timetext = timeDifference(td)
|
2022-10-07 16:51:40 -04:00
|
|
|
initials = timeGrammar.pcf + self.initials() + timeGrammar.number
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}><c={}>{} {} [{}]</c> {} {}.</c>".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
syscolor.name(),
|
|
|
|
self.colorhtml(),
|
|
|
|
timeGrammar.temporal,
|
|
|
|
self.handle,
|
|
|
|
initials,
|
|
|
|
timetext,
|
|
|
|
verb,
|
|
|
|
)
|
|
|
|
|
2011-05-12 02:28:07 -04:00
|
|
|
def memoopmsg(self, opchum, opgrammar, syscolor):
|
2022-10-07 16:51:40 -04:00
|
|
|
opinit = opgrammar.pcf + opchum.initials() + opgrammar.number
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}>{}</c> made <c={}>{}</c> an OP.".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
opchum.colorhtml(),
|
|
|
|
opinit,
|
|
|
|
self.colorhtml(),
|
|
|
|
self.initials(),
|
|
|
|
)
|
|
|
|
|
2011-05-12 02:28:07 -04:00
|
|
|
def memodeopmsg(self, opchum, opgrammar, syscolor):
|
2022-10-07 16:51:40 -04:00
|
|
|
opinit = opgrammar.pcf + opchum.initials() + opgrammar.number
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}>{}</c> took away <c={}>{}</c>'s OP powers.".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
opchum.colorhtml(),
|
|
|
|
opinit,
|
|
|
|
self.colorhtml(),
|
|
|
|
self.initials(),
|
|
|
|
)
|
|
|
|
|
2011-05-12 02:28:07 -04:00
|
|
|
def memovoicemsg(self, opchum, opgrammar, syscolor):
|
2022-10-07 16:51:40 -04:00
|
|
|
opinit = opgrammar.pcf + opchum.initials() + opgrammar.number
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}>{}</c> gave <c={}>{}</c> voice.".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
opchum.colorhtml(),
|
|
|
|
opinit,
|
|
|
|
self.colorhtml(),
|
|
|
|
self.initials(),
|
|
|
|
)
|
|
|
|
|
2011-05-12 02:28:07 -04:00
|
|
|
def memodevoicemsg(self, opchum, opgrammar, syscolor):
|
2022-10-07 16:51:40 -04:00
|
|
|
opinit = opgrammar.pcf + opchum.initials() + opgrammar.number
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}>{}</c> took away <c={}>{}</c>'s voice.".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
opchum.colorhtml(),
|
|
|
|
opinit,
|
|
|
|
self.colorhtml(),
|
|
|
|
self.initials(),
|
|
|
|
)
|
|
|
|
|
2011-07-10 05:13:00 -04:00
|
|
|
def memomodemsg(self, opchum, opgrammar, syscolor, modeverb, modeon):
|
2022-10-07 16:51:40 -04:00
|
|
|
opinit = opgrammar.pcf + opchum.initials() + opgrammar.number
|
|
|
|
if modeon:
|
|
|
|
modeon = "now"
|
|
|
|
else:
|
|
|
|
modeon = "no longer"
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}>Memo is {} <c=black>{}</c> by <c={}>{}</c></c>".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
syscolor.name(),
|
|
|
|
modeon,
|
|
|
|
modeverb,
|
|
|
|
opchum.colorhtml(),
|
|
|
|
opinit,
|
|
|
|
)
|
|
|
|
|
2011-07-11 19:55:44 -04:00
|
|
|
def memoquirkkillmsg(self, opchum, opgrammar, syscolor):
|
2022-10-07 16:51:40 -04:00
|
|
|
opinit = opgrammar.pcf + opchum.initials() + opgrammar.number
|
2023-01-14 16:59:59 -05:00
|
|
|
return "<c={}><c={}>{}</c> turned off your quirk.</c>".format(
|
2022-10-07 16:51:40 -04:00
|
|
|
syscolor.name(),
|
|
|
|
opchum.colorhtml(),
|
|
|
|
opinit,
|
|
|
|
)
|
2011-02-03 01:20:37 -05:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def checkLength(handle):
|
|
|
|
return len(handle) <= 256
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-03 01:20:37 -05:00
|
|
|
@staticmethod
|
|
|
|
def checkValid(handle):
|
|
|
|
caps = [l for l in handle if l.isupper()]
|
2011-08-23 06:23:59 -04:00
|
|
|
if len(caps) != 1:
|
|
|
|
return (False, "Must have exactly 1 uppercase letter")
|
|
|
|
if handle[0].isupper():
|
|
|
|
return (False, "Cannot start with uppercase letter")
|
2011-02-03 01:20:37 -05:00
|
|
|
if re.search("[^A-Za-z0-9]", handle) is not None:
|
2011-08-23 06:23:59 -04:00
|
|
|
return (False, "Only alphanumeric characters allowed")
|
2022-11-16 00:41:00 -05:00
|
|
|
if handle[0].isnumeric(): # IRC doesn't allow this
|
|
|
|
return (False, "Handles may not start with a number")
|
2011-08-23 06:23:59 -04:00
|
|
|
return (True,)
|
2011-02-03 01:20:37 -05:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2023-01-14 16:59:59 -05:00
|
|
|
class PesterHistory:
|
2011-02-08 17:59:25 -05:00
|
|
|
def __init__(self):
|
|
|
|
self.history = []
|
2011-02-09 01:26:23 -05:00
|
|
|
self.current = 0
|
|
|
|
self.saved = None
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-09 01:26:23 -05:00
|
|
|
def next(self, text):
|
|
|
|
if self.current == 0:
|
|
|
|
return None
|
|
|
|
if self.current == len(self.history):
|
|
|
|
self.save(text)
|
|
|
|
self.current -= 1
|
2011-02-08 17:59:25 -05:00
|
|
|
text = self.history[self.current]
|
|
|
|
return text
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-08 17:59:25 -05:00
|
|
|
def prev(self):
|
|
|
|
self.current += 1
|
2011-02-09 01:26:23 -05:00
|
|
|
if self.current >= len(self.history):
|
|
|
|
self.current = len(self.history)
|
|
|
|
return self.retrieve()
|
2011-02-08 17:59:25 -05:00
|
|
|
return self.history[self.current]
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-08 17:59:25 -05:00
|
|
|
def reset(self):
|
2011-02-09 01:26:23 -05:00
|
|
|
self.current = len(self.history)
|
|
|
|
self.saved = None
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-09 01:26:23 -05:00
|
|
|
def save(self, text):
|
|
|
|
self.saved = text
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-09 01:26:23 -05:00
|
|
|
def retrieve(self):
|
|
|
|
return self.saved
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-08 17:59:25 -05:00
|
|
|
def add(self, text):
|
2022-10-07 16:51:40 -04:00
|
|
|
if len(self.history) == 0 or text != self.history[len(self.history) - 1]:
|
2011-02-09 01:26:23 -05:00
|
|
|
self.history.append(text)
|
|
|
|
self.reset()
|