fixed RE bot not being told about preference on connect + tiny code clarification

This commit is contained in:
anne 2023-10-18 16:03:19 +02:00
parent 31a06b8bcc
commit 86f4fc1325
2 changed files with 25 additions and 17 deletions

View file

@ -1552,15 +1552,7 @@ class PesterWindow(MovingWindow):
self.chooseServerAskedToReset = False self.chooseServerAskedToReset = False
self.chooseServer() self.chooseServer()
# Update RE bot # Update RE bot used 2 b here but has now been moved to self.connected(), since this is too early (~lisanne)
try:
if self.userprofile.getRandom():
code = "+"
else:
code = "-"
self.sendNotice.emit(code, RANDNICK)
except:
PchumLog.warning("No randomEncounter set in userconfig?")
# Client --> Server pings # Client --> Server pings
self.pingtimer = QtCore.QTimer() self.pingtimer = QtCore.QTimer()
@ -1999,6 +1991,9 @@ class PesterWindow(MovingWindow):
# ~lisanne : loads fonts from the `main/fonts` key in a theme # ~lisanne : loads fonts from the `main/fonts` key in a theme
# Note that this wont load fonts from inherited themes # Note that this wont load fonts from inherited themes
# that seems fine imo, esp since u could still load them through `$path/../inheritedtheme/somefont.ttf` # that seems fine imo, esp since u could still load them through `$path/../inheritedtheme/somefont.ttf`
# >>> Im from the future, loading like that breaks ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# >>> if the source or target theme is installed thru repo and the other manual
# >>> oh well.
PchumLog.debug("Loading font %s", font_path) PchumLog.debug("Loading font %s", font_path)
fontID = QtGui.QFontDatabase.addApplicationFont(font_path) fontID = QtGui.QFontDatabase.addApplicationFont(font_path)
if fontID == -1: if fontID == -1:
@ -2343,6 +2338,19 @@ class PesterWindow(MovingWindow):
else: else:
PchumLog.warning("No ping timer.") PchumLog.warning("No ping timer.")
# ~Lisanne: tell randomEncounter our preferences
# This does not account for the RE bot restarting while we're connected
# But thats rare enough that it probably does not really matter
try:
if self.randhandler.running:
self.randhandler.setRandomer(self.userprofile.getRandom(), force=True)
else:
PchumLog.warning(
"Could not tell randomEncounter of our preferences because it is offline"
)
except Exception as e:
PchumLog.warning("No randomEncounter set in userconfig?")
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def blockSelectedChum(self): def blockSelectedChum(self):
curChumListing = self.chumList.currentItem() curChumListing = self.chumList.currentItem()
@ -3383,11 +3391,8 @@ class PesterWindow(MovingWindow):
self.changeProfile() self.changeProfile()
# Update RE bot # Update RE bot
try: try:
if self.userprofile.getRandom(): if self.randhandler.running:
code = "+" self.randhandler.setRandomer(self.userprofile.getRandom(), force=True)
else:
code = "-"
self.sendNotice.emit(code, RANDNICK)
except: except:
PchumLog.warning("No randomEncounter set in userconfig?") PchumLog.warning("No randomEncounter set in userconfig?")
self.mycolorUpdated.emit() self.mycolorUpdated.emit()

View file

@ -28,9 +28,12 @@ class RandomHandler(QtCore.QObject):
self.queue.append("?") self.queue.append("?")
self.mainwindow.sendNotice.emit("?", self.randNick) self.mainwindow.sendNotice.emit("?", self.randNick)
def setRandomer(self, r): def setRandomer(self, value, force=False):
if r != self.mainwindow.userprofile.getRandom(): # Notifies randomEncounter of our preferences
if r: # Only does so if the new value differs from what is stored in userprofile
# Can be forced to notify anyways by providing `force=True`
if value != self.mainwindow.userprofile.getRandom() or force:
if value:
code = "+" code = "+"
else: else:
code = "-" code = "-"