Remove most unnecessary str typecasts from pesterchum.py

This commit is contained in:
Dpeta 2023-02-19 20:06:59 +01:00
parent f6c5c1e804
commit 69f409b9d1
No known key found for this signature in database
GPG key ID: 51227517CEA0030C
3 changed files with 78 additions and 95 deletions

View file

@ -31,6 +31,7 @@ _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"
) )
def delta2txt(d, format="pc"): def delta2txt(d, format="pc"):
if isinstance(d, mysteryTime): if isinstance(d, mysteryTime):
return "?" return "?"
@ -1481,9 +1482,7 @@ class PesterMemo(PesterConvo):
def closeForbidden(self, channel, reason): def closeForbidden(self, channel, reason):
c = str(channel) c = str(channel)
if c.lower() == self.channel.lower(): if c.lower() == self.channel.lower():
self.mainwindow.forbiddenChan[str, str].disconnect( self.mainwindow.forbiddenChan[str, str].disconnect(self.closeForbidden)
self.closeForbidden
)
if self.parent(): if self.parent():
PchumLog.info(self.channel) PchumLog.info(self.channel)
i = self.parent().tabIndices[self.channel] i = self.parent().tabIndices[self.channel]

View file

@ -1846,9 +1846,7 @@ class PesterUserlist(QtWidgets.QDialog):
self.mainwindow.namesUpdated.connect(self.updateUsers) self.mainwindow.namesUpdated.connect(self.updateUsers)
self.mainwindow.userPresentSignal[str, str, str].connect( self.mainwindow.userPresentSignal[str, str, str].connect(self.updateUserPresent)
self.updateUserPresent
)
self.updateUsers() self.updateUsers()
self.searchbox.setFocus() self.searchbox.setFocus()

View file

@ -483,7 +483,7 @@ class chumArea(RightClickTree):
def getOptionsMenu(self): def getOptionsMenu(self):
if not self.currentItem(): if not self.currentItem():
return None return None
text = str(self.currentItem().text(0)) text = self.currentItem().text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
if text == "Chums": if text == "Chums":
@ -535,11 +535,11 @@ class chumArea(RightClickTree):
else: else:
event.ignore() event.ignore()
return return
thisitem = str(event.source().currentItem().text(0)) thisitem = event.source().currentItem().text(0)
if thisitem.rfind(" (") != -1: if thisitem.rfind(" (") != -1:
thisitem = thisitem[0 : thisitem.rfind(" (")] thisitem = thisitem[0 : thisitem.rfind(" (")]
# Drop item is a group # Drop item is a group
thisitem = str(event.source().currentItem().text(0)) thisitem = event.source().currentItem().text(0)
if thisitem.rfind(" (") != -1: if thisitem.rfind(" (") != -1:
thisitem = thisitem[0 : thisitem.rfind(" (")] thisitem = thisitem[0 : thisitem.rfind(" (")]
if thisitem == "Chums" or thisitem in self.groups: if thisitem == "Chums" or thisitem in self.groups:
@ -551,7 +551,7 @@ class chumArea(RightClickTree):
droppos = self.itemAt(event.pos()) droppos = self.itemAt(event.pos())
if not droppos: if not droppos:
return return
droppos = str(droppos.text(0)) droppos = droppos.text(0)
if droppos.rfind(" ") != -1: if droppos.rfind(" ") != -1:
droppos = droppos[0 : droppos.rfind(" ")] droppos = droppos[0 : droppos.rfind(" ")]
if droppos == "Chums" or droppos in self.groups: if droppos == "Chums" or droppos in self.groups:
@ -573,10 +573,10 @@ class chumArea(RightClickTree):
gTemp = [] gTemp = []
for i in range(self.topLevelItemCount()): for i in range(self.topLevelItemCount()):
text = str(self.topLevelItem(i).text(0)) text = self.topLevelItem(i).text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
gTemp.append([str(text), self.topLevelItem(i).isExpanded()]) gTemp.append([text, self.topLevelItem(i).isExpanded()])
self.mainwindow.config.saveGroups(gTemp) self.mainwindow.config.saveGroups(gTemp)
# Drop item is a chum # Drop item is a chum
else: else:
@ -588,7 +588,7 @@ class chumArea(RightClickTree):
eventpos = event.pos() eventpos = event.pos()
item = self.itemAt(eventpos) item = self.itemAt(eventpos)
if item: if item:
text = str(item.text(0)) text = item.text(0)
# Figure out which group to drop into # Figure out which group to drop into
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
@ -596,7 +596,7 @@ class chumArea(RightClickTree):
group = text group = text
gitem = item gitem = item
else: else:
ptext = str(item.parent().text(0)) ptext = item.parent().text(0)
if ptext.rfind(" ") != -1: if ptext.rfind(" ") != -1:
ptext = ptext[0 : ptext.rfind(" ")] ptext = ptext[0 : ptext.rfind(" ")]
group = ptext group = ptext
@ -615,11 +615,11 @@ class chumArea(RightClickTree):
chums = self.mainwindow.config.chums() chums = self.mainwindow.config.chums()
if item == gitem: if item == gitem:
item = gitem.child(0) item = gitem.child(0)
inPos = chums.index(str(item.text(0))) inPos = chums.index(item.text(0))
if chums.index(thisitem) < inPos: if chums.index(thisitem) < inPos:
inPos -= 1 inPos -= 1
chums.remove(thisitem) chums.remove(thisitem)
chums.insert(inPos, str(thisitem)) chums.insert(inPos, thisitem)
self.mainwindow.config.setChums(chums) self.mainwindow.config.setChums(chums)
else: else:
@ -631,9 +631,9 @@ class chumArea(RightClickTree):
currentGroup = self.currentItem() currentGroup = self.currentItem()
if currentGroup: if currentGroup:
if currentGroup.parent(): if currentGroup.parent():
text = str(currentGroup.parent().text(0)) text = currentGroup.parent().text(0)
else: else:
text = str(currentGroup.text(0)) text = currentGroup.text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
currentGroup = text currentGroup = text
@ -701,7 +701,7 @@ class chumArea(RightClickTree):
return return
curgroups = [] curgroups = []
for i in range(self.topLevelItemCount()): for i in range(self.topLevelItemCount()):
text = str(self.topLevelItem(i).text(0)) text = self.topLevelItem(i).text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
curgroups.append(text) curgroups.append(text)
@ -726,24 +726,24 @@ class chumArea(RightClickTree):
totals = {"Chums": 0} totals = {"Chums": 0}
online = {"Chums": 0} online = {"Chums": 0}
for g in self.groups: for g in self.groups:
totals[str(g)] = 0 totals[g] = 0
online[str(g)] = 0 online[g] = 0
for c in self.chums: for c in self.chums:
yes = c.mood.name() != "offline" yes = c.mood.name() != "offline"
if c.group == "Chums": if c.group == "Chums":
totals[str(c.group)] = totals[str(c.group)] + 1 totals[c.group] = totals[c.group] + 1
if yes: if yes:
online[str(c.group)] = online[str(c.group)] + 1 online[c.group] = online[c.group] + 1
elif c.group in totals: elif c.group in totals:
totals[str(c.group)] = totals[str(c.group)] + 1 totals[c.group] = totals[c.group] + 1
if yes: if yes:
online[str(c.group)] = online[str(c.group)] + 1 online[c.group] = online[c.group] + 1
else: else:
totals["Chums"] = totals["Chums"] + 1 totals["Chums"] = totals["Chums"] + 1
if yes: if yes:
online["Chums"] = online["Chums"] + 1 online["Chums"] = online["Chums"] + 1
for i in range(self.topLevelItemCount()): for i in range(self.topLevelItemCount()):
text = str(self.topLevelItem(i).text(0)) text = self.topLevelItem(i).text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
if text in online: if text in online:
@ -753,7 +753,7 @@ class chumArea(RightClickTree):
def hideOnlineNumbers(self): def hideOnlineNumbers(self):
for i in range(self.topLevelItemCount()): for i in range(self.topLevelItemCount()):
text = str(self.topLevelItem(i).text(0)) text = self.topLevelItem(i).text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
self.topLevelItem(i).setText(0, "%s" % (text)) self.topLevelItem(i).setText(0, "%s" % (text))
@ -771,7 +771,7 @@ class chumArea(RightClickTree):
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def expandGroup(self): def expandGroup(self):
item = self.currentItem() item = self.currentItem()
text = str(item.text(0)) text = item.text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
@ -787,7 +787,7 @@ class chumArea(RightClickTree):
self.mainwindow.config.addGroup("Chums") self.mainwindow.config.addGroup("Chums")
curgroups = [] curgroups = []
for i in range(self.topLevelItemCount()): for i in range(self.topLevelItemCount()):
text = str(self.topLevelItem(i).text(0)) text = self.topLevelItem(i).text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
curgroups.append(text) curgroups.append(text)
@ -810,7 +810,7 @@ class chumArea(RightClickTree):
]: ]:
child_1.setExpanded(True) child_1.setExpanded(True)
for i in range(self.topLevelItemCount()): for i in range(self.topLevelItemCount()):
text = str(self.topLevelItem(i).text(0)) text = self.topLevelItem(i).text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
if text == chumLabel.chum.group: if text == chumLabel.chum.group:
@ -830,7 +830,7 @@ class chumArea(RightClickTree):
if fi > 0: if fi > 0:
while not bestj: while not bestj:
for j in range(self.topLevelItem(i).childCount()): for j in range(self.topLevelItem(i).childCount()):
if chums[fi - c] == str( if chums[fi - c] == (
self.topLevelItem(i).child(j).text(0) self.topLevelItem(i).child(j).text(0)
): ):
bestj = j bestj = j
@ -1063,7 +1063,6 @@ class chumArea(RightClickTree):
self, "Notes", "Enter your notes..." self, "Notes", "Enter your notes..."
) )
if ok: if ok:
notes = str(notes)
self.mainwindow.chumdb.setNotes(currentChum.handle, notes) self.mainwindow.chumdb.setNotes(currentChum.handle, notes)
currentChum.setToolTip(0, "{}: {}".format(currentChum.handle, notes)) currentChum.setToolTip(0, "{}: {}".format(currentChum.handle, notes))
@ -1076,7 +1075,6 @@ class chumArea(RightClickTree):
self, "Rename Group", "Enter a new name for the group:" self, "Rename Group", "Enter a new name for the group:"
) )
if ok: if ok:
gname = str(gname)
if re.search(r"[^A-Za-z0-9_\s]", gname) is not None: if re.search(r"[^A-Za-z0-9_\s]", gname) is not None:
msgbox = QtWidgets.QMessageBox() msgbox = QtWidgets.QMessageBox()
msgbox.setStyleSheet( msgbox.setStyleSheet(
@ -1094,7 +1092,7 @@ class chumArea(RightClickTree):
index = self.indexOfTopLevelItem(currentGroup) index = self.indexOfTopLevelItem(currentGroup)
if index != -1: if index != -1:
expanded = currentGroup.isExpanded() expanded = currentGroup.isExpanded()
text = str(currentGroup.text(0)) text = currentGroup.text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
self.mainwindow.config.delGroup(text) self.mainwindow.config.delGroup(text)
@ -1117,7 +1115,7 @@ class chumArea(RightClickTree):
currentGroup = self.currentItem() currentGroup = self.currentItem()
if not currentGroup: if not currentGroup:
return return
text = str(currentGroup.text(0)) text = currentGroup.text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
self.mainwindow.config.delGroup(text) self.mainwindow.config.delGroup(text)
@ -1141,7 +1139,7 @@ class chumArea(RightClickTree):
def moveToGroup(self, item): def moveToGroup(self, item):
if not item: if not item:
return return
group = str(item.text()) group = item.text()
chumLabel = self.currentItem() chumLabel = self.currentItem()
if not chumLabel: if not chumLabel:
return return
@ -1280,7 +1278,6 @@ class TrollSlumWindow(QtWidgets.QFrame):
self, "Add Troll", "Enter Troll Handle:" self, "Add Troll", "Enter Troll Handle:"
) )
if ok: if ok:
handle = str(handle)
if not ( if not (
PesterProfile.checkLength(handle) PesterProfile.checkLength(handle)
and PesterProfile.checkValid(handle)[0] and PesterProfile.checkValid(handle)[0]
@ -2025,15 +2022,16 @@ class PesterWindow(MovingWindow):
self.tabconvo.show() self.tabconvo.show()
else: else:
convoWindow = PesterConvo(chum, initiated, self) convoWindow = PesterConvo(chum, initiated, self)
convoWindow.messageSent[str, str].connect( convoWindow.messageSent[str, str].connect(self.sendMessage[str, str])
self.sendMessage[str, str]
)
convoWindow.windowClosed[str].connect(self.closeConvo) convoWindow.windowClosed[str].connect(self.closeConvo)
self.convos[chum.handle] = convoWindow self.convos[chum.handle] = convoWindow
if chum.handle.upper() in BOTNAMES: if chum.handle.upper() in BOTNAMES:
convoWindow.toggleQuirks(True) convoWindow.toggleQuirks(True)
convoWindow.quirksOff.setChecked(True) convoWindow.quirksOff.setChecked(True)
if not self.config.irc_compatibility_mode() or chum.handle.upper() in CUSTOMBOTS: if (
not self.config.irc_compatibility_mode()
or chum.handle.upper() in CUSTOMBOTS
):
self.newConvoStarted.emit(chum.handle, initiated) self.newConvoStarted.emit(chum.handle, initiated)
else: else:
self.newConvoStarted.emit(chum.handle, initiated) self.newConvoStarted.emit(chum.handle, initiated)
@ -2134,15 +2132,11 @@ class PesterWindow(MovingWindow):
# connect signals # connect signals
self.inviteOnlyChan[str].connect(memoWindow.closeInviteOnly) self.inviteOnlyChan[str].connect(memoWindow.closeInviteOnly)
self.forbiddenChan[str, str].connect(memoWindow.closeForbidden) self.forbiddenChan[str, str].connect(memoWindow.closeForbidden)
memoWindow.messageSent[str, str].connect( memoWindow.messageSent[str, str].connect(self.sendMessage[str, str])
self.sendMessage[str, str]
)
memoWindow.windowClosed[str].connect(self.closeMemo) memoWindow.windowClosed[str].connect(self.closeMemo)
self.namesUpdated[str].connect(memoWindow.namesUpdated) self.namesUpdated[str].connect(memoWindow.namesUpdated)
self.modesUpdated[str, str].connect(memoWindow.modesUpdated) self.modesUpdated[str, str].connect(memoWindow.modesUpdated)
self.userPresentSignal[str, str, str].connect( self.userPresentSignal[str, str, str].connect(memoWindow.userPresentChange)
memoWindow.userPresentChange
)
# chat client send memo open # chat client send memo open
self.memos[channel] = memoWindow self.memos[channel] = memoWindow
self.joinChannel.emit(channel) # race condition? self.joinChannel.emit(channel) # race condition?
@ -2591,7 +2585,7 @@ class PesterWindow(MovingWindow):
def pesterSelectedChum(self): def pesterSelectedChum(self):
curChum = self.chumList.currentItem() curChum = self.chumList.currentItem()
if curChum: if curChum:
text = str(curChum.text(0)) text = curChum.text(0)
if text.rfind(" (") != -1: if text.rfind(" (") != -1:
text = text[0 : text.rfind(" (")] text = text[0 : text.rfind(" (")]
if text not in self.chumList.groups and text != "Chums": if text not in self.chumList.groups and text != "Chums":
@ -2608,7 +2602,7 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def closeConvo(self, handle): def closeConvo(self, handle):
h = str(handle) h = handle
try: try:
chum = self.convos[h].chum chum = self.convos[h].chum
except KeyError: except KeyError:
@ -2633,7 +2627,7 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def closeMemo(self, channel): def closeMemo(self, channel):
c = str(channel) c = channel
self.chatlog.finish(c) self.chatlog.finish(c)
self.leftChannel.emit(channel) self.leftChannel.emit(channel)
try: try:
@ -2656,7 +2650,7 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot(str, Mood) @QtCore.pyqtSlot(str, Mood)
def updateMoodSlot(self, handle, mood): def updateMoodSlot(self, handle, mood):
h = str(handle) h = handle
self.updateMood(h, mood) self.updateMood(h, mood)
@QtCore.pyqtSlot(str, QtGui.QColor) @QtCore.pyqtSlot(str, QtGui.QColor)
@ -2666,19 +2660,18 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot(str, str) @QtCore.pyqtSlot(str, str)
def deliverMessage(self, handle, msg): def deliverMessage(self, handle, msg):
h = str(handle) h = handle
m = str(msg) m = msg
self.newMessage(h, m) self.newMessage(h, m)
@QtCore.pyqtSlot(str, str, str) @QtCore.pyqtSlot(str, str, str)
def deliverMemo(self, chan, handle, msg): def deliverMemo(self, chan, handle, msg):
(c, h, m) = (str(chan), str(handle), str(msg)) self.newMemoMsg(chan, handle, msg)
self.newMemoMsg(c, h, m)
@QtCore.pyqtSlot(str, str) @QtCore.pyqtSlot(str, str)
def deliverNotice(self, handle, msg): def deliverNotice(self, handle, msg):
h = str(handle) h = handle
m = str(msg) m = msg
if h.upper() == "NICKSERV" and m.startswith( if h.upper() == "NICKSERV" and m.startswith(
"Your nickname is now being changed to" "Your nickname is now being changed to"
): ):
@ -2751,30 +2744,27 @@ class PesterWindow(MovingWindow):
# self.modesUpdated.emit(channel, modes) # self.modesUpdated.emit(channel, modes)
@QtCore.pyqtSlot(str, str, str) @QtCore.pyqtSlot(str, str, str)
def timeCommand(self, chan, handle, command): def timeCommand(self, chan, handle, command):
(c, h, cmd) = (str(chan), str(handle), str(command)) if self.memos[chan]:
if self.memos[c]: self.memos[chan].timeUpdate(handle, command)
self.memos[c].timeUpdate(h, cmd)
@QtCore.pyqtSlot(str, str, str) @QtCore.pyqtSlot(str, str, str)
def quirkDisable(self, channel, msg, op): def quirkDisable(self, channel, msg, op):
(c, msg, op) = (str(channel), str(msg), str(op)) if channel not in self.memos:
if c not in self.memos:
return return
memo = self.memos[c] memo = self.memos[channel]
memo.quirkDisable(op, msg) memo.quirkDisable(op, msg)
@QtCore.pyqtSlot(str, PesterList) @QtCore.pyqtSlot(str, PesterList)
def updateNames(self, channel, names): def updateNames(self, channel, names):
c = str(channel)
# update name DB # update name DB
self.namesdb[c] = names self.namesdb[channel] = names
# warn interested party of names # warn interested party of names
self.namesUpdated.emit(c) self.namesUpdated.emit(channel)
@QtCore.pyqtSlot(str, str, str) @QtCore.pyqtSlot(str, str, str)
def userPresentUpdate(self, handle, channel, update): def userPresentUpdate(self, handle, channel, update):
c = str(channel) c = channel
n = str(handle) n = handle
# print("c=%s\nn=%s\nupdate=%s\n" % (c, n, update)) # print("c=%s\nn=%s\nupdate=%s\n" % (c, n, update))
if update == "nick": if update == "nick":
l = n.split(":") l = n.split(":")
@ -2829,12 +2819,11 @@ class PesterWindow(MovingWindow):
available_groups = [g[0] for g in self.config.getGroups()] available_groups = [g[0] for g in self.config.getGroups()]
self.addchumdialog = AddChumDialog(available_groups, self) self.addchumdialog = AddChumDialog(available_groups, self)
ok = self.addchumdialog.exec() ok = self.addchumdialog.exec()
handle = str(self.addchumdialog.chumBox.text()).strip() handle = (self.addchumdialog.chumBox.text()).strip()
newgroup = str(self.addchumdialog.newgroup.text()).strip() newgroup = (self.addchumdialog.newgroup.text()).strip()
selectedGroup = self.addchumdialog.groupBox.currentText() selectedGroup = self.addchumdialog.groupBox.currentText()
group = newgroup if newgroup else selectedGroup group = newgroup if newgroup else selectedGroup
if ok: if ok:
handle = str(handle)
if handle in [h.handle for h in self.chumList.chums]: if handle in [h.handle for h in self.chumList.chums]:
self.addchumdialog = None self.addchumdialog = None
return return
@ -2874,7 +2863,7 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def blockChum(self, handle): def blockChum(self, handle):
h = str(handle) h = handle
self.config.addBlocklist(h) self.config.addBlocklist(h)
self.config.removeChum(h) self.config.removeChum(h)
if h in self.convos: if h in self.convos:
@ -2897,7 +2886,7 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def unblockChum(self, handle): def unblockChum(self, handle):
h = str(handle) h = handle
self.config.delBlocklist(h) self.config.delBlocklist(h)
if h in self.convos: if h in self.convos:
convo = self.convos[h] convo = self.convos[h]
@ -3054,25 +3043,25 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def joinSelectedMemo(self): def joinSelectedMemo(self):
time = str(self.memochooser.timeinput.text()) time = self.memochooser.timeinput.text()
secret = self.memochooser.secretChannel.isChecked() secret = self.memochooser.secretChannel.isChecked()
invite = self.memochooser.inviteChannel.isChecked() invite = self.memochooser.inviteChannel.isChecked()
# Join the ones on the list first # Join the ones on the list first
for SelectedMemo in self.memochooser.SelectedMemos(): for SelectedMemo in self.memochooser.SelectedMemos():
channel = "#" + str(SelectedMemo.target) channel = f"#{SelectedMemo.target}"
self.newMemo(channel, time) self.newMemo(channel, time)
if self.memochooser.newmemoname(): if self.memochooser.newmemoname():
newmemo = self.memochooser.newmemoname() newmemo = self.memochooser.newmemoname()
channel = str(newmemo).replace(" ", "_") channel = newmemo.replace(" ", "_")
channel = re.sub(r"[^A-Za-z0-9#_\,]", "", channel) channel = re.sub(r"[^A-Za-z0-9#_\,]", "", channel)
# Allow us to join more than one with this. # Allow us to join more than one with this.
chans = channel.split(",") chans = channel.split(",")
# Filter out empty entries. # Filter out empty entries.
chans = [_f for _f in chans if _f] chans = [_f for _f in chans if _f]
for c in chans: for c in chans:
c = "#" + c c = f"#{c}"
# We should really change this code to only make the memo once # We should really change this code to only make the memo once
# the server has confirmed that we've joined.... # the server has confirmed that we've joined....
self.newMemo(c, time, secret=secret, invite=invite) self.newMemo(c, time, secret=secret, invite=invite)
@ -3103,14 +3092,12 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def userListAdd(self, handle): def userListAdd(self, handle):
h = str(handle) chum = PesterProfile(handle, chumdb=self.chumdb)
chum = PesterProfile(h, chumdb=self.chumdb)
self.addChum(chum) self.addChum(chum)
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def userListPester(self, handle): def userListPester(self, handle):
h = str(handle) self.newConversation(handle)
self.newConversation(h)
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def userListClose(self): def userListClose(self):
@ -3131,7 +3118,7 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def updateQuirks(self): def updateQuirks(self):
for i in range(self.quirkmenu.quirkList.topLevelItemCount()): for i in range(self.quirkmenu.quirkList.topLevelItemCount()):
curgroup = str(self.quirkmenu.quirkList.topLevelItem(i).text(0)) curgroup = self.quirkmenu.quirkList.topLevelItem(i).text(0)
for j in range(self.quirkmenu.quirkList.topLevelItem(i).childCount()): for j in range(self.quirkmenu.quirkList.topLevelItem(i).childCount()):
item = self.quirkmenu.quirkList.topLevelItem(i).child(j) item = self.quirkmenu.quirkList.topLevelItem(i).child(j)
item.quirk.quirk["on"] = item.quirk.on = ( item.quirk.quirk["on"] = item.quirk.on = (
@ -3160,7 +3147,7 @@ class PesterWindow(MovingWindow):
) )
try: try:
if ok: if ok:
self.newConversation(str(chum)) self.newConversation(chum)
except: except:
pass pass
finally: finally:
@ -3192,7 +3179,6 @@ class PesterWindow(MovingWindow):
self, "Add Group", "Enter a name for the new group:" self, "Add Group", "Enter a name for the new group:"
) )
if ok: if ok:
gname = str(gname)
if re.search(r"[^A-Za-z0-9_\s]", gname) is not None: if re.search(r"[^A-Za-z0-9_\s]", gname) is not None:
msgbox = QtWidgets.QMessageBox() msgbox = QtWidgets.QMessageBox()
msgbox.setInformativeText("THIS IS NOT A VALID GROUP NAME") msgbox.setInformativeText("THIS IS NOT A VALID GROUP NAME")
@ -3333,7 +3319,7 @@ class PesterWindow(MovingWindow):
# timestamps # timestamps
timestampsetting = self.optionmenu.timestampcheck.isChecked() timestampsetting = self.optionmenu.timestampcheck.isChecked()
self.config.set("showTimeStamps", timestampsetting) self.config.set("showTimeStamps", timestampsetting)
timeformatsetting = str(self.optionmenu.timestampBox.currentText()) timeformatsetting = self.optionmenu.timestampBox.currentText()
if timeformatsetting == "12 hour": if timeformatsetting == "12 hour":
self.config.set("time12Format", True) self.config.set("time12Format", True)
else: else:
@ -3443,7 +3429,7 @@ class PesterWindow(MovingWindow):
self.config.set("blink", blinksetting) self.config.set("blink", blinksetting)
# toast notifications # toast notifications
self.tm.setEnabled(self.optionmenu.notifycheck.isChecked()) self.tm.setEnabled(self.optionmenu.notifycheck.isChecked())
self.tm.setCurrentType(str(self.optionmenu.notifyOptions.currentText())) self.tm.setCurrentType(self.optionmenu.notifyOptions.currentText())
notifysetting = 0 notifysetting = 0
if self.optionmenu.notifySigninCheck.isChecked(): if self.optionmenu.notifySigninCheck.isChecked():
notifysetting |= self.config.SIGNIN notifysetting |= self.config.SIGNIN
@ -3476,11 +3462,11 @@ class PesterWindow(MovingWindow):
autoidentify = self.optionmenu.autonickserv.isChecked() autoidentify = self.optionmenu.autonickserv.isChecked()
nickservpass = self.optionmenu.nickservpass.text() nickservpass = self.optionmenu.nickservpass.text()
self.userprofile.setAutoIdentify(autoidentify) self.userprofile.setAutoIdentify(autoidentify)
self.userprofile.setNickServPass(str(nickservpass)) self.userprofile.setNickServPass(nickservpass)
# auto join memos # auto join memos
autojoins = [] autojoins = []
for i in range(self.optionmenu.autojoinlist.count()): for i in range(self.optionmenu.autojoinlist.count()):
autojoins.append(str(self.optionmenu.autojoinlist.item(i).text())) autojoins.append(self.optionmenu.autojoinlist.item(i).text())
self.userprofile.setAutoJoins(autojoins) self.userprofile.setAutoJoins(autojoins)
# advanced # advanced
## user mode ## user mode
@ -3515,7 +3501,7 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def themeSelected(self, override=False): def themeSelected(self, override=False):
if not override: if not override:
themename = str(self.optionmenu.themeBox.currentText()) themename = self.optionmenu.themeBox.currentText()
else: else:
themename = override themename = override
if override or themename != self.theme.name: if override or themename != self.theme.name:
@ -3541,7 +3527,7 @@ class PesterWindow(MovingWindow):
self.chooseprofile.profileBox self.chooseprofile.profileBox
and self.chooseprofile.profileBox.currentIndex() > 0 and self.chooseprofile.profileBox.currentIndex() > 0
): ):
handle = str(self.chooseprofile.profileBox.currentText()) handle = self.chooseprofile.profileBox.currentText()
if handle == self.profile().handle: if handle == self.profile().handle:
self.chooseprofile = None self.chooseprofile = None
return return
@ -3584,7 +3570,7 @@ class PesterWindow(MovingWindow):
msgBox.exec() msgBox.exec()
return return
else: else:
handle = str(self.chooseprofile.chumHandle.text()) handle = self.chooseprofile.chumHandle.text()
if handle == self.profile().handle: if handle == self.profile().handle:
self.chooseprofile = None self.chooseprofile = None
return return
@ -3742,7 +3728,7 @@ class PesterWindow(MovingWindow):
if not hasattr(self, "chooseprofile"): if not hasattr(self, "chooseprofile"):
self.chooseprofile = None self.chooseprofile = None
if not self.chooseprofile: if not self.chooseprofile:
h = str(handle) h = handle
self.changeProfile(collision=h) self.changeProfile(collision=h)
@QtCore.pyqtSlot(str, str) @QtCore.pyqtSlot(str, str)
@ -4605,7 +4591,7 @@ class MainProgram(QtCore.QObject):
traceback.print_tb(tb, file=f) traceback.print_tb(tb, file=f)
f.close() f.close()
except Exception as e: except Exception as e:
print(str(e)) print(e)
# Show msgbox # Show msgbox
msgbox = QtWidgets.QMessageBox() msgbox = QtWidgets.QMessageBox()
@ -4615,7 +4601,7 @@ class MainProgram(QtCore.QObject):
"QMessageBox{" + self.widget.theme["main/defaultwindow/style"] + "}" "QMessageBox{" + self.widget.theme["main/defaultwindow/style"] + "}"
) )
except Exception as e: except Exception as e:
print(str(e)) print(e)
msgbox.setStyleSheet( msgbox.setStyleSheet(
"background-color: red; color: black; font-size: x-large;" "background-color: red; color: black; font-size: x-large;"
) )
@ -4625,7 +4611,7 @@ class MainProgram(QtCore.QObject):
) )
msgbox.exec() msgbox.exec()
except Exception as e: except Exception as e:
print("failed to process uncaught except: " + str(e)) print(f"Failed to process uncaught except: {e}")
PchumLog.exception("app error") PchumLog.exception("app error")
def run(self): def run(self):