Merge pull request #159 from mocchapi/RE-fix

fixed RE bot not being told about preference on connect
This commit is contained in:
Dpeta 2023-10-20 15:33:39 +02:00 committed by GitHub
commit 371b588dab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 17 deletions

View file

@ -1552,15 +1552,7 @@ class PesterWindow(MovingWindow):
self.chooseServerAskedToReset = False
self.chooseServer()
# Update RE bot
try:
if self.userprofile.getRandom():
code = "+"
else:
code = "-"
self.sendNotice.emit(code, RANDNICK)
except:
PchumLog.warning("No randomEncounter set in userconfig?")
# Update RE bot used 2 b here but has now been moved to self.connected(), since this is too early (~lisanne)
# Client --> Server pings
self.pingtimer = QtCore.QTimer()
@ -1999,6 +1991,9 @@ class PesterWindow(MovingWindow):
# ~lisanne : loads fonts from the `main/fonts` key in a theme
# 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`
# >>> 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)
fontID = QtGui.QFontDatabase.addApplicationFont(font_path)
if fontID == -1:
@ -2343,6 +2338,19 @@ class PesterWindow(MovingWindow):
else:
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()
def blockSelectedChum(self):
curChumListing = self.chumList.currentItem()
@ -3383,11 +3391,8 @@ class PesterWindow(MovingWindow):
self.changeProfile()
# Update RE bot
try:
if self.userprofile.getRandom():
code = "+"
else:
code = "-"
self.sendNotice.emit(code, RANDNICK)
if self.randhandler.running:
self.randhandler.setRandomer(self.userprofile.getRandom(), force=True)
except:
PchumLog.warning("No randomEncounter set in userconfig?")
self.mycolorUpdated.emit()

View file

@ -28,9 +28,12 @@ class RandomHandler(QtCore.QObject):
self.queue.append("?")
self.mainwindow.sendNotice.emit("?", self.randNick)
def setRandomer(self, r):
if r != self.mainwindow.userprofile.getRandom():
if r:
def setRandomer(self, value, force=False):
# Notifies randomEncounter of our preferences
# 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 = "+"
else:
code = "-"