Add IRC compatibility mode (only disables things for now . . .)

This commit is contained in:
Dpeta 2023-02-15 20:57:31 +01:00
parent ccf462d8a8
commit 938cf69b85
No known key found for this signature in database
GPG key ID: 51227517CEA0030C
7 changed files with 73 additions and 60 deletions

View file

@ -898,7 +898,7 @@ class PesterConvo(QtWidgets.QFrame):
self.chum.color = color self.chum.color = color
def addMessage(self, msg, me=True): def addMessage(self, msg, me=True):
if type(msg) in [str, str]: if isinstance(msg, str):
lexmsg = lexMessage(msg) lexmsg = lexMessage(msg)
else: else:
lexmsg = msg lexmsg = msg
@ -1096,7 +1096,7 @@ class PesterConvo(QtWidgets.QFrame):
text = self.textInput.text() text = self.textInput.text()
text = str(self.textInput.text()) text = str(self.textInput.text())
return parsetools.kxhandleInput(self, text, flavor="convo") return parsetools.kxhandleInput(self, text, flavor="convo", irc_compatible=self.mainwindow.config.irc_compatibility_mode())
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def addThisChum(self): def addThisChum(self):

7
irc.py
View file

@ -829,7 +829,8 @@ class PesterIRC(QtCore.QThread):
) )
self.connected.emit() # Alert main thread that we've connected. self.connected.emit() # Alert main thread that we've connected.
profile = self.mainwindow.profile() profile = self.mainwindow.profile()
if not self.mainwindow.config.lowBandwidth(): if self.mainwindow.config.irc_compatibility_mode():
return
# Negotiate capabilities # Negotiate capabilities
self._send_irc.cap("REQ", "message-tags") self._send_irc.cap("REQ", "message-tags")
self._send_irc.cap( self._send_irc.cap(
@ -857,8 +858,8 @@ class PesterIRC(QtCore.QThread):
""" """
features = params[:-1] features = params[:-1]
PchumLog.info("Server _featurelist: %s", features) PchumLog.info("Server _featurelist: %s", features)
for feature in features: if not self.metadata_supported:
if feature.casefold().startswith("metadata"): if any(feature.startswith("METADATA") for feature in features):
PchumLog.info("Server supports metadata.") PchumLog.info("Server supports metadata.")
self.metadata_supported = True self.metadata_supported = True

View file

@ -357,7 +357,7 @@ class MemoText(PesterText):
pass pass
def addMessage(self, msg, chum): def addMessage(self, msg, chum):
if type(msg) in [str, str]: if isinstance(msg, str):
lexmsg = lexMessage(msg) lexmsg = lexMessage(msg)
else: else:
lexmsg = msg lexmsg = msg
@ -698,6 +698,8 @@ class PesterMemo(PesterConvo):
return PesterIcon(self.mainwindow.theme["memos/memoicon"]) return PesterIcon(self.mainwindow.theme["memos/memoicon"])
def sendTimeInfo(self, newChum=False): def sendTimeInfo(self, newChum=False):
if self.mainwindow.config.irc_compatibility_mode():
return
if newChum: if newChum:
self.messageSent.emit( self.messageSent.emit(
"PESTERCHUM:TIME>%s" % (delta2txt(self.time.getTime(), "server") + "i"), "PESTERCHUM:TIME>%s" % (delta2txt(self.time.getTime(), "server") + "i"),
@ -1398,7 +1400,7 @@ class PesterMemo(PesterConvo):
def sentMessage(self): def sentMessage(self):
text = str(self.textInput.text()) text = str(self.textInput.text())
return parsetools.kxhandleInput(self, text, flavor="memos") return parsetools.kxhandleInput(self, text, flavor="memos", irc_compatible=self.mainwindow.config.irc_compatibility_mode())
@QtCore.pyqtSlot(QString) @QtCore.pyqtSlot(QString)
def namesUpdated(self, channel): def namesUpdated(self, channel):
@ -1730,7 +1732,7 @@ class PesterMemo(PesterConvo):
txt_time = delta2txt(time, "server") txt_time = delta2txt(time, "server")
# Only send if time isn't CURRENT, it's very spammy otherwise. # Only send if time isn't CURRENT, it's very spammy otherwise.
# CURRENT should be the default already. # CURRENT should be the default already.
if txt_time != "i": if txt_time != "i" and not self.mainwindow.config.irc_compatibility_mode():
serverText = "PESTERCHUM:TIME>" + txt_time serverText = "PESTERCHUM:TIME>" + txt_time
self.messageSent.emit(serverText, self.title()) self.messageSent.emit(serverText, self.title())
elif update == "+q": elif update == "+q":
@ -1951,6 +1953,8 @@ class PesterMemo(PesterConvo):
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def sendtime(self): def sendtime(self):
if self.mainwindow.config.irc_compatibility_mode():
return
# me = self.mainwindow.profile() # me = self.mainwindow.profile()
# systemColor = QtGui.QColor(self.mainwindow.theme["memos/systemMsgColor"]) # systemColor = QtGui.QColor(self.mainwindow.theme["memos/systemMsgColor"])
time = txt2delta(self.timeinput.text()) time = txt2delta(self.timeinput.text())

View file

@ -323,10 +323,10 @@ class QuirkTesterWindow(QtWidgets.QDialog):
def sentMessage(self): def sentMessage(self):
text = str(self.textInput.text()) text = str(self.textInput.text())
return parsetools.kxhandleInput(self, text, "menus") return parsetools.kxhandleInput(self, text, "menus", irc_compatible=self.mainwindow.config.irc_compatibility_mode())
def addMessage(self, msg, me=True): def addMessage(self, msg, me=True):
if type(msg) in [str, str]: if isinstance(msg, str):
lexmsg = lexMessage(msg) lexmsg = lexMessage(msg)
else: else:
lexmsg = msg lexmsg = msg
@ -1233,12 +1233,17 @@ class PesterOptions(QtWidgets.QDialog):
self.tabs.button(-2).setChecked(True) self.tabs.button(-2).setChecked(True)
self.pages = QtWidgets.QStackedWidget(self) self.pages = QtWidgets.QStackedWidget(self)
self.bandwidthcheck = QtWidgets.QCheckBox("Low Bandwidth", self) self.irc_mode_check = QtWidgets.QCheckBox("IRC compatibility mode", self)
if self.config.lowBandwidth(): if self.config.irc_compatibility_mode():
self.bandwidthcheck.setChecked(True) self.irc_mode_check.setChecked(True)
bandwidthLabel = QtWidgets.QLabel( bandwidthLabel = QtWidgets.QLabel(
"(Stops you for receiving the flood of MOODS,\n" "Enable this if you're planning on using Pesterchum on a server with normal IRC clients."
" though stops chumlist from working properly)" "\nDisables at least the following features:"
"\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 - PESTERCHUM:X commands (BEGIN, CEASE, BLOCK, IDLE, etc.)"
) )
font = bandwidthLabel.font() font = bandwidthLabel.font()
font.setPointSize(8) font.setPointSize(8)
@ -1617,7 +1622,7 @@ class PesterOptions(QtWidgets.QDialog):
widget = QtWidgets.QWidget() widget = QtWidgets.QWidget()
layout_connect = QtWidgets.QVBoxLayout(widget) layout_connect = QtWidgets.QVBoxLayout(widget)
layout_connect.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop) layout_connect.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)
layout_connect.addWidget(self.bandwidthcheck) layout_connect.addWidget(self.irc_mode_check)
layout_connect.addWidget(bandwidthLabel) layout_connect.addWidget(bandwidthLabel)
layout_connect.addWidget(self.autonickserv) layout_connect.addWidget(self.autonickserv)
layout_indent = QtWidgets.QVBoxLayout() layout_indent = QtWidgets.QVBoxLayout()

View file

@ -283,8 +283,7 @@ def kxlexMsg(string):
# ...and that's it for this. # ...and that's it for this.
return msg return msg
def lexMessage(string: str):
def lexMessage(string):
lexlist = [ lexlist = [
(mecmd, _mecmdre), (mecmd, _mecmdre),
(colorBegin, _ctag_begin), (colorBegin, _ctag_begin),
@ -302,10 +301,11 @@ def lexMessage(string):
(honker, _honk), (honker, _honk),
] ]
string = str(string)
string = string.replace("\n", " ").replace("\r", " ") string = string.replace("\n", " ").replace("\r", " ")
lexed = lexer(str(string), lexlist) lexed = lexer(string, lexlist)
return balance(lexed)
def balance(lexed):
balanced = [] balanced = []
beginc = 0 beginc = 0
endc = 0 endc = 0
@ -683,7 +683,7 @@ def _is_ooc(msg, strict=True):
return False return False
def kxhandleInput(ctx, text=None, flavor=None): def kxhandleInput(ctx, text=None, flavor=None, irc_compatible=False):
"""The function that user input that should be sent to the server is routed """The function that user input that should be sent to the server is routed
through. Handles lexing, splitting, and quirk application, as well as through. Handles lexing, splitting, and quirk application, as well as
sending.""" sending."""
@ -699,11 +699,10 @@ def kxhandleInput(ctx, text=None, flavor=None):
if text is None: if text is None:
# Fetch the raw text from the input box. # Fetch the raw text from the input box.
text = ctx.textInput.text() text = ctx.textInput.text()
text = str(ctx.textInput.text())
# Preprocessing stuff. # Preprocessing stuff.
msg = text.strip() msg = text.strip()
if msg == "" or msg.startswith("PESTERCHUM:"): if not msg or msg.startswith("PESTERCHUM:"):
# We don't allow users to send system messages. There's also no # We don't allow users to send system messages. There's also no
# point if they haven't entered anything. # point if they haven't entered anything.
return return
@ -736,7 +735,7 @@ def kxhandleInput(ctx, text=None, flavor=None):
# Begin message processing. # Begin message processing.
# We use 'text' despite its lack of processing because it's simpler. # We use 'text' despite its lack of processing because it's simpler.
if should_quirk and not (is_action or is_ooc): if should_quirk and not (is_action or is_ooc or irc_compatible):
if flavor != "menus": if flavor != "menus":
# Fetch the quirks we'll have to apply. # Fetch the quirks we'll have to apply.
quirks = ctx.mainwindow.userprofile.quirks quirks = ctx.mainwindow.userprofile.quirks
@ -827,6 +826,7 @@ def kxhandleInput(ctx, text=None, flavor=None):
if flavor == "convo": if flavor == "convo":
# if ceased, rebegin # if ceased, rebegin
if hasattr(ctx, "chumopen") and not ctx.chumopen: if hasattr(ctx, "chumopen") and not ctx.chumopen:
if not irc_compatible:
ctx.mainwindow.newConvoStarted.emit(QString(ctx.title()), True) ctx.mainwindow.newConvoStarted.emit(QString(ctx.title()), True)
ctx.setChumOpen(True) ctx.setChumOpen(True)
@ -846,7 +846,7 @@ def kxhandleInput(ctx, text=None, flavor=None):
serverMsg = copy(lm) serverMsg = copy(lm)
# Memo-specific processing. # Memo-specific processing.
if flavor == "memos" and not is_action: if flavor == "memos" and not is_action and not irc_compatible:
# Quirks were already applied, so get the prefix/postfix stuff # Quirks were already applied, so get the prefix/postfix stuff
# ready. # ready.
# We fetched the information outside of the loop, so just # We fetched the information outside of the loop, so just

View file

@ -1897,7 +1897,7 @@ class PesterWindow(MovingWindow):
event.accept() event.accept()
def newMessage(self, handle, msg): def newMessage(self, handle, msg):
if handle in self.config.getBlocklist(): if not self.config.irc_compatibility_mode() and handle in self.config.getBlocklist():
# yeah suck on this # yeah suck on this
self.sendMessage.emit("PESTERCHUM:BLOCKED", handle) self.sendMessage.emit("PESTERCHUM:BLOCKED", handle)
return return
@ -2007,7 +2007,7 @@ class PesterWindow(MovingWindow):
self.trollslum.updateMood(handle, mood) self.trollslum.updateMood(handle, mood)
def newConversation(self, chum, initiated=True): def newConversation(self, chum, initiated=True):
if type(chum) in [str, str]: if isinstance(chum, str):
matchingChums = [c for c in self.chumList.chums if c.handle == chum] matchingChums = [c for c in self.chumList.chums if c.handle == chum]
if len(matchingChums) > 0: if len(matchingChums) > 0:
mood = matchingChums[0].mood mood = matchingChums[0].mood
@ -2032,7 +2032,7 @@ class PesterWindow(MovingWindow):
) )
convoWindow.windowClosed["QString"].connect(self.closeConvo) convoWindow.windowClosed["QString"].connect(self.closeConvo)
self.convos[chum.handle] = convoWindow self.convos[chum.handle] = convoWindow
if str(chum.handle).upper() in BOTNAMES: if chum.handle.upper() in BOTNAMES or self.config.irc_compatibility_mode():
convoWindow.toggleQuirks(True) convoWindow.toggleQuirks(True)
convoWindow.quirksOff.setChecked(True) convoWindow.quirksOff.setChecked(True)
if str(chum.handle).upper() in CUSTOMBOTS: if str(chum.handle).upper() in CUSTOMBOTS:
@ -2616,6 +2616,7 @@ class PesterWindow(MovingWindow):
self.theme["convo/text/ceasepester"], self.theme["convo/text/ceasepester"],
), ),
) )
if not self.config.irc_compatibility_mode():
self.convoClosed.emit(handle) self.convoClosed.emit(handle)
self.chatlog.finish(h) self.chatlog.finish(h)
del self.convos[h] del self.convos[h]
@ -2881,6 +2882,7 @@ class PesterWindow(MovingWindow):
newtroll = PesterProfile(h) newtroll = PesterProfile(h)
self.trollslum.addTroll(newtroll) self.trollslum.addTroll(newtroll)
self.moodRequest.emit(newtroll) self.moodRequest.emit(newtroll)
if not self.config.irc_compatibility_mode():
self.blockedChum.emit(handle) self.blockedChum.emit(handle)
@QtCore.pyqtSlot(QString) @QtCore.pyqtSlot(QString)
@ -2902,6 +2904,7 @@ class PesterWindow(MovingWindow):
self.trollslum.removeTroll(handle) self.trollslum.removeTroll(handle)
self.config.addChum(chum) self.config.addChum(chum)
self.chumList.addChum(chum) self.chumList.addChum(chum)
if not self.config.irc_compatibility_mode():
self.moodRequest.emit(chum) self.moodRequest.emit(chum)
self.unblockedChum.emit(handle) self.unblockedChum.emit(handle)
@ -2968,7 +2971,7 @@ class PesterWindow(MovingWindow):
# might affect, but I've been using it for months and haven't # might affect, but I've been using it for months and haven't
# noticed any issues.... # noticed any issues....
handle = convo.chum.handle handle = convo.chum.handle
if self.isBot(handle): if self.isBot(handle) and not self.config.irc_compatibility_mode():
# Don't send these idle messages. # Don't send these idle messages.
continue continue
# karxi: Now we just use 'handle' instead of 'h'. # karxi: Now we just use 'handle' instead of 'h'.
@ -3440,11 +3443,11 @@ class PesterWindow(MovingWindow):
if notifysetting != curnotify: if notifysetting != curnotify:
self.config.set("notifyOptions", notifysetting) self.config.set("notifyOptions", notifysetting)
# low bandwidth # low bandwidth
bandwidthsetting = self.optionmenu.bandwidthcheck.isChecked() irc_mode_setting = self.optionmenu.irc_mode_check.isChecked()
curbandwidth = self.config.lowBandwidth() curbandwidth = self.config.irc_compatibility_mode()
if bandwidthsetting != curbandwidth: if irc_mode_setting != curbandwidth:
self.config.set("lowBandwidth", bandwidthsetting) self.config.set("irc_compatibility_mode", irc_mode_setting)
if bandwidthsetting: if irc_mode_setting:
self.leftChannel.emit("#pesterchum") self.leftChannel.emit("#pesterchum")
else: else:
self.joinChannel.emit("#pesterchum") self.joinChannel.emit("#pesterchum")

View file

@ -358,8 +358,8 @@ with a backup from: <a href='%s'>%s</a></h3></html>"
"notifyOptions", self.SIGNIN | self.NEWMSG | self.NEWCONVO | self.INITIALS "notifyOptions", self.SIGNIN | self.NEWMSG | self.NEWCONVO | self.INITIALS
) )
def lowBandwidth(self): def irc_compatibility_mode(self):
return self.config.get("lowBandwidth", False) return self.config.get("irc_compatibility_mode", False)
def ghostchum(self): def ghostchum(self):
return self.config.get("ghostchum", False) return self.config.get("ghostchum", False)