Finish up IRC compatibility & force-valid-prefix toggle

This commit is contained in:
Dpeta 2023-02-16 23:45:55 +01:00
parent 3f7caf73b2
commit ec0c6cdaf9
No known key found for this signature in database
GPG key ID: 51227517CEA0030C
4 changed files with 25 additions and 13 deletions

View file

@ -28,7 +28,7 @@ from logviewer import PesterLogViewer
PchumLog = logging.getLogger("pchumLogger")
_valid_memo_msg_start = re.compile(
r"^<c=((\d+,\d+,\d+)|(#([a-fA-F0-9]{6})|(#[a-fA-F0-9]{3})))>[A-Z]{3}:\s"
r"^<c=((\d+,\d+,\d+)|(#([a-fA-F0-9]{6})|(#[a-fA-F0-9]{3})))>([A-Z]{3}):\s"
)
# Python 3
QString = str
@ -361,9 +361,17 @@ class MemoText(PesterText):
def make_valid(self, msg, chum, parent, window, me):
"""Adds initials and color to a message if they're missing."""
if not re.match(_valid_memo_msg_start, msg):
initials = chum.initials()
match = re.match(_valid_memo_msg_start, msg)
detected_initials = None
if match:
try:
# Get initials used in msg, check if valid later
detected_initials = match.group(6)[1:]
except IndexError:
pass # IndexError is fine, just means the initials are invalid
if not match or detected_initials != initials:
if chum is me:
initials = me.initials()
color = me.colorcmd()
msg = f"<c={color}>{initials}: {msg}</c>"
msg = addTimeInitial(msg, parent.time.getGrammar())
@ -374,7 +382,6 @@ class MemoText(PesterText):
color = f"{r},{g},{b}"
else:
color = "0,0,0"
initials = chum.initials()
msg = f"<c={color}>{initials}: {msg}</c>"
msg = addTimeInitial(msg, parent.times[chum.handle].getGrammar())
return msg

View file

@ -1226,7 +1226,7 @@ class PesterOptions(QtWidgets.QDialog):
"Logging",
"Idle/Updates",
"Theme",
"Connection",
"IRC",
]
if parent.advanced:
self.tabNames.append("Advanced")
@ -1244,10 +1244,10 @@ class PesterOptions(QtWidgets.QDialog):
bandwidthLabel = QtWidgets.QLabel(
"Enable this if you're planning on using Pesterchum on a server with normal IRC clients."
"\nStops the client from sending or requesting:"
"\n - Moods (#pesterchum MOODs and METADATA moods)"
"\n - Message colors (COLOR > and METADATA color)"
"\n - Message color tags (<c=0,0,0>)"
"\n - Timelines (PESTERCHUM:CURRENT, etc.)"
"\n - Non-metadata moods (MOOD >0, GETMOOD, etc.)"
"\n - Non-metadata dm colors (COLOR >0,0,0)"
"\n - Memo message initials and color (<c=0,0,0>EB: </c>)"
"\n - Memo timelines"
"\n - Misc. PESTERCHUM:X commands (BEGIN, CEASE, BLOCK, IDLE, etc.)"
)
font = bandwidthLabel.font()
@ -1255,12 +1255,12 @@ class PesterOptions(QtWidgets.QDialog):
bandwidthLabel.setFont(font)
self.force_prefix_check = QtWidgets.QCheckBox(
"Add initials to memo messages without initials", self
"Force all memo messages to have valid initials.", self
)
if self.config.force_prefix():
self.force_prefix_check.setChecked(True)
initials_label = QtWidgets.QLabel(
"Enable this when chatting with normal IRC users or to forcibly un-scratch Doc Scratch."
"Disable to allow users to send messages without initials, like Doc Scratch."
)
font = initials_label.font()
font.setPointSize(8)

View file

@ -737,7 +737,7 @@ def kxhandleInput(ctx, text=None, flavor=None, irc_compatible=False):
# Begin message processing.
# We use 'text' despite its lack of processing because it's simpler.
if should_quirk and not (is_action or is_ooc or irc_compatible):
if should_quirk and not (is_action or is_ooc):
if flavor != "menus":
# Fetch the quirks we'll have to apply.
quirks = ctx.mainwindow.userprofile.quirks
@ -847,6 +847,11 @@ def kxhandleInput(ctx, text=None, flavor=None, irc_compatible=False):
clientMsg = copy(lm)
serverMsg = copy(lm)
# If in IRC-compatible mode, remove color tags.
if irc_compatible:
serverMsg = re.sub(_ctag_begin, "", serverMsg)
serverMsg = re.sub(_ctag_end, "", serverMsg)
# Memo-specific processing.
if flavor == "memos" and not is_action and not irc_compatible:
# Quirks were already applied, so get the prefix/postfix stuff

View file

@ -362,7 +362,7 @@ with a backup from: <a href='%s'>%s</a></h3></html>"
return self.config.get("irc_compatibility_mode", False)
def force_prefix(self):
return self.config.get("force_prefix", False)
return self.config.get("force_prefix", True)
def ghostchum(self):
return self.config.get("ghostchum", False)