2021-03-23 17:36:43 -04:00
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
2011-06-09 03:42:56 -04:00
|
|
|
|
2014-01-12 02:33:33 -05:00
|
|
|
RANDNICK = "randomEncounter"
|
|
|
|
|
2011-06-09 03:42:56 -04:00
|
|
|
class RandomHandler(QtCore.QObject):
|
|
|
|
def __init__(self, parent):
|
|
|
|
QtCore.QObject.__init__(self, parent)
|
2014-01-12 02:33:33 -05:00
|
|
|
self.randNick = RANDNICK
|
2011-06-09 03:42:56 -04:00
|
|
|
self.mainwindow = parent
|
|
|
|
self.queue = []
|
2011-08-29 04:56:44 -04:00
|
|
|
self.running = False
|
|
|
|
|
|
|
|
def setRunning(self, on):
|
|
|
|
self.running = on
|
|
|
|
self.mainwindow.rand.setEnabled(on)
|
2011-06-09 03:42:56 -04:00
|
|
|
|
|
|
|
def getRandomer(self):
|
|
|
|
self.queue.append("?")
|
|
|
|
self.mainwindow.sendNotice.emit("?", self.randNick)
|
|
|
|
|
|
|
|
def setRandomer(self, r):
|
2011-07-19 19:26:27 -04:00
|
|
|
if r != self.mainwindow.userprofile.getRandom():
|
|
|
|
if r: code = "+"
|
|
|
|
else: code = "-"
|
|
|
|
self.queue.append(code)
|
|
|
|
self.mainwindow.sendNotice.emit(code, self.randNick)
|
2011-06-09 03:42:56 -04:00
|
|
|
|
2012-01-20 15:46:44 -05:00
|
|
|
def setIdle(self, i):
|
|
|
|
if i: code = "~"
|
|
|
|
else: code = "*"
|
|
|
|
self.queue.append(code)
|
|
|
|
self.mainwindow.sendNotice.emit(code, self.randNick)
|
|
|
|
|
2011-06-09 03:42:56 -04:00
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def getEncounter(self):
|
|
|
|
self.queue.append("!")
|
|
|
|
self.mainwindow.sendNotice.emit("!", self.randNick)
|
|
|
|
|
|
|
|
def incoming(self, msg):
|
|
|
|
l = msg.split("=")
|
|
|
|
code = l[0][0]
|
|
|
|
if code not in self.queue:
|
|
|
|
return # Ignore if we didn't request this
|
|
|
|
self.queue.remove(code)
|
|
|
|
if code == "?":
|
|
|
|
if l[1][0] == "y":
|
|
|
|
self.mainwindow.userprofile.setRandom(True)
|
|
|
|
elif l[1][0] == "n":
|
|
|
|
self.mainwindow.userprofile.setRandom(False)
|
|
|
|
elif code in ["+","-"]:
|
|
|
|
if l[1][0] == "k":
|
|
|
|
if code == "+":
|
|
|
|
self.mainwindow.userprofile.setRandom(True)
|
|
|
|
else:
|
|
|
|
self.mainwindow.userprofile.setRandom(False)
|
2012-01-20 15:46:44 -05:00
|
|
|
elif code in ["~","*"]:
|
|
|
|
if l[1][0] == "k":
|
|
|
|
pass
|
2011-06-09 03:42:56 -04:00
|
|
|
elif code == "!":
|
|
|
|
if l[1] == "x":
|
2021-03-23 17:36:43 -04:00
|
|
|
from PyQt5 import QtGui, QtWidgets
|
|
|
|
msgbox = QtWidgets.QMessageBox()
|
2021-03-25 12:52:43 -04:00
|
|
|
msgbox.setStyleSheet("QMessageBox{" + self.theme["main/defaultwindow/style"] + "}")
|
2011-06-09 03:42:56 -04:00
|
|
|
msgbox.setText("Unable to fetch you a random encounter!")
|
|
|
|
msgbox.setInformativeText("Try again later :(")
|
|
|
|
msgbox.exec_()
|
|
|
|
return
|
2021-03-23 17:36:43 -04:00
|
|
|
name = str(l[1])
|
|
|
|
print(name)
|
2011-06-09 03:42:56 -04:00
|
|
|
self.mainwindow.newConversation(name)
|