Add force prefix option
This commit is contained in:
parent
938cf69b85
commit
3f7caf73b2
8 changed files with 82 additions and 18 deletions
7
convo.py
7
convo.py
|
@ -1096,7 +1096,12 @@ class PesterConvo(QtWidgets.QFrame):
|
|||
text = self.textInput.text()
|
||||
text = str(self.textInput.text())
|
||||
|
||||
return parsetools.kxhandleInput(self, text, flavor="convo", irc_compatible=self.mainwindow.config.irc_compatibility_mode())
|
||||
return parsetools.kxhandleInput(
|
||||
self,
|
||||
text,
|
||||
flavor="convo",
|
||||
irc_compatible=self.mainwindow.config.irc_compatibility_mode(),
|
||||
)
|
||||
|
||||
@QtCore.pyqtSlot()
|
||||
def addThisChum(self):
|
||||
|
|
|
@ -321,7 +321,7 @@ class PesterProfile:
|
|||
|
||||
def colorcmd(self):
|
||||
if self.color:
|
||||
(r, g, b, _) = self.color.getRgb()
|
||||
(r, g, b, _a) = self.color.getRgb()
|
||||
return "%d,%d,%d" % (r, g, b)
|
||||
else:
|
||||
return "0,0,0"
|
||||
|
|
2
irc.py
2
irc.py
|
@ -862,7 +862,7 @@ class PesterIRC(QtCore.QThread):
|
|||
if any(feature.startswith("METADATA") for feature in features):
|
||||
PchumLog.info("Server supports metadata.")
|
||||
self.metadata_supported = True
|
||||
|
||||
|
||||
def _cap(self, server, nick, subcommand, tag):
|
||||
"""IRCv3 capabilities command from server.
|
||||
|
||||
|
|
42
memos.py
42
memos.py
|
@ -20,13 +20,16 @@ from parsetools import (
|
|||
timeProtocol,
|
||||
lexMessage,
|
||||
colorBegin,
|
||||
addTimeInitial,
|
||||
mecmd,
|
||||
smiledict,
|
||||
)
|
||||
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"
|
||||
)
|
||||
# Python 3
|
||||
QString = str
|
||||
|
||||
|
@ -356,14 +359,36 @@ class MemoText(PesterText):
|
|||
except:
|
||||
pass
|
||||
|
||||
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):
|
||||
if chum is me:
|
||||
initials = me.initials()
|
||||
color = me.colorcmd()
|
||||
msg = f"<c={color}>{initials}: {msg}</c>"
|
||||
msg = addTimeInitial(msg, parent.time.getGrammar())
|
||||
else:
|
||||
color = window.chumdb.getColor(chum.handle)
|
||||
if color:
|
||||
(r, g, b, _a) = color.getRgb()
|
||||
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
|
||||
|
||||
def addMessage(self, msg, chum):
|
||||
if isinstance(msg, str):
|
||||
lexmsg = lexMessage(msg)
|
||||
else:
|
||||
lexmsg = msg
|
||||
parent = self.parent()
|
||||
window = parent.mainwindow
|
||||
me = window.profile()
|
||||
if isinstance(msg, str):
|
||||
if self.mainwindow.config.force_prefix():
|
||||
msg = self.make_valid(msg, chum, parent, window, me)
|
||||
lexmsg = lexMessage(msg)
|
||||
else:
|
||||
lexmsg = msg
|
||||
if self.mainwindow.config.animations():
|
||||
for m in self.urls:
|
||||
if convertTags(lexmsg).find(self.urls[m].toString()) != -1:
|
||||
|
@ -1400,7 +1425,12 @@ class PesterMemo(PesterConvo):
|
|||
def sentMessage(self):
|
||||
text = str(self.textInput.text())
|
||||
|
||||
return parsetools.kxhandleInput(self, text, flavor="memos", irc_compatible=self.mainwindow.config.irc_compatibility_mode())
|
||||
return parsetools.kxhandleInput(
|
||||
self,
|
||||
text,
|
||||
flavor="memos",
|
||||
irc_compatible=self.mainwindow.config.irc_compatibility_mode(),
|
||||
)
|
||||
|
||||
@QtCore.pyqtSlot(QString)
|
||||
def namesUpdated(self, channel):
|
||||
|
|
25
menus.py
25
menus.py
|
@ -323,7 +323,12 @@ class QuirkTesterWindow(QtWidgets.QDialog):
|
|||
def sentMessage(self):
|
||||
text = str(self.textInput.text())
|
||||
|
||||
return parsetools.kxhandleInput(self, text, "menus", irc_compatible=self.mainwindow.config.irc_compatibility_mode())
|
||||
return parsetools.kxhandleInput(
|
||||
self,
|
||||
text,
|
||||
"menus",
|
||||
irc_compatible=self.mainwindow.config.irc_compatibility_mode(),
|
||||
)
|
||||
|
||||
def addMessage(self, msg, me=True):
|
||||
if isinstance(msg, str):
|
||||
|
@ -1238,17 +1243,29 @@ class PesterOptions(QtWidgets.QDialog):
|
|||
self.irc_mode_check.setChecked(True)
|
||||
bandwidthLabel = QtWidgets.QLabel(
|
||||
"Enable this if you're planning on using Pesterchum on a server with normal IRC clients."
|
||||
"\nDisables at least the following features:"
|
||||
"\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 - PESTERCHUM:X commands (BEGIN, CEASE, BLOCK, IDLE, etc.)"
|
||||
"\n - Misc. PESTERCHUM:X commands (BEGIN, CEASE, BLOCK, IDLE, etc.)"
|
||||
)
|
||||
font = bandwidthLabel.font()
|
||||
font.setPointSize(8)
|
||||
bandwidthLabel.setFont(font)
|
||||
|
||||
self.force_prefix_check = QtWidgets.QCheckBox(
|
||||
"Add initials to memo messages without 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."
|
||||
)
|
||||
font = initials_label.font()
|
||||
font.setPointSize(8)
|
||||
initials_label.setFont(font)
|
||||
|
||||
self.autonickserv = QtWidgets.QCheckBox("Auto-Identify with NickServ", self)
|
||||
self.autonickserv.setChecked(parent.userprofile.getAutoIdentify())
|
||||
self.autonickserv.stateChanged[int].connect(self.autoNickServChange)
|
||||
|
@ -1624,6 +1641,8 @@ class PesterOptions(QtWidgets.QDialog):
|
|||
layout_connect.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)
|
||||
layout_connect.addWidget(self.irc_mode_check)
|
||||
layout_connect.addWidget(bandwidthLabel)
|
||||
layout_connect.addWidget(self.force_prefix_check)
|
||||
layout_connect.addWidget(initials_label)
|
||||
layout_connect.addWidget(self.autonickserv)
|
||||
layout_indent = QtWidgets.QVBoxLayout()
|
||||
layout_indent.addWidget(self.nickservpass)
|
||||
|
|
|
@ -283,6 +283,7 @@ def kxlexMsg(string):
|
|||
# ...and that's it for this.
|
||||
return msg
|
||||
|
||||
|
||||
def lexMessage(string: str):
|
||||
lexlist = [
|
||||
(mecmd, _mecmdre),
|
||||
|
@ -305,6 +306,7 @@ def lexMessage(string: str):
|
|||
lexed = lexer(string, lexlist)
|
||||
return balance(lexed)
|
||||
|
||||
|
||||
def balance(lexed):
|
||||
balanced = []
|
||||
beginc = 0
|
||||
|
|
|
@ -1897,9 +1897,10 @@ class PesterWindow(MovingWindow):
|
|||
event.accept()
|
||||
|
||||
def newMessage(self, handle, msg):
|
||||
if not self.config.irc_compatibility_mode() and handle in self.config.getBlocklist():
|
||||
if handle in self.config.getBlocklist():
|
||||
# yeah suck on this
|
||||
self.sendMessage.emit("PESTERCHUM:BLOCKED", handle)
|
||||
if not self.config.irc_compatibility_mode():
|
||||
self.sendMessage.emit("PESTERCHUM:BLOCKED", handle)
|
||||
return
|
||||
# notify
|
||||
if self.config.notifyOptions() & self.config.NEWMSG:
|
||||
|
@ -1951,7 +1952,6 @@ class PesterWindow(MovingWindow):
|
|||
# TODO: This is really bad practice. Fix it later.
|
||||
return
|
||||
memo = self.memos[chan]
|
||||
msg = str(msg)
|
||||
if handle not in memo.times:
|
||||
# new chum! time current
|
||||
newtime = datetime.timedelta(0)
|
||||
|
@ -3442,15 +3442,20 @@ class PesterWindow(MovingWindow):
|
|||
curnotify = self.config.notifyOptions()
|
||||
if notifysetting != curnotify:
|
||||
self.config.set("notifyOptions", notifysetting)
|
||||
# low bandwidth
|
||||
# IRC compatibility (previously low bandwidth)
|
||||
irc_mode_setting = self.optionmenu.irc_mode_check.isChecked()
|
||||
curbandwidth = self.config.irc_compatibility_mode()
|
||||
if irc_mode_setting != curbandwidth:
|
||||
current_irc_mode = self.config.irc_compatibility_mode()
|
||||
if irc_mode_setting != current_irc_mode:
|
||||
self.config.set("irc_compatibility_mode", irc_mode_setting)
|
||||
if irc_mode_setting:
|
||||
self.leftChannel.emit("#pesterchum")
|
||||
else:
|
||||
self.joinChannel.emit("#pesterchum")
|
||||
# Force prefix
|
||||
force_prefix_setting = self.optionmenu.force_prefix_check.isChecked()
|
||||
current_prefix_setting = self.config.force_prefix()
|
||||
if force_prefix_setting != current_prefix_setting:
|
||||
self.config.set("force_prefix", force_prefix_setting)
|
||||
# nickserv
|
||||
autoidentify = self.optionmenu.autonickserv.isChecked()
|
||||
nickservpass = self.optionmenu.nickservpass.text()
|
||||
|
|
|
@ -361,6 +361,9 @@ with a backup from: <a href='%s'>%s</a></h3></html>"
|
|||
def irc_compatibility_mode(self):
|
||||
return self.config.get("irc_compatibility_mode", False)
|
||||
|
||||
def force_prefix(self):
|
||||
return self.config.get("force_prefix", False)
|
||||
|
||||
def ghostchum(self):
|
||||
return self.config.get("ghostchum", False)
|
||||
|
||||
|
|
Loading…
Reference in a new issue