Changed the way the chosen server is communicated. (Still not ideal,

please do tell me if anyone knows how to do this properly.)
Commented part of code related to updates.
This commit is contained in:
Hi 2020-11-22 18:43:03 +01:00
parent 14f412d835
commit a8b82f7473
4 changed files with 32 additions and 41 deletions

5
irc.py
View file

@ -20,17 +20,18 @@ else:
logging.basicConfig(level=logging.WARNING)
class PesterIRC(QtCore.QThread):
def __init__(self, config, window):
def __init__(self, config, window, server):
QtCore.QThread.__init__(self)
self.mainwindow = window
self.config = config
self.server = server
self.registeredIRC = False
self.stopIRC = None
self.NickServ = services.NickServ()
self.ChanServ = services.ChanServ()
def IRCConnect(self):
server = self.config.server()
port = self.config.port()
server = self.server
self.cli = IRCClient(PesterHandler, host=server, port=int(port), nick=self.mainwindow.profile().handle, real_name='pcc31', blocking=True, timeout=120)
self.cli.command_handler.parent = self
self.cli.command_handler.mainwindow = self.mainwindow

View file

@ -1,6 +1,5 @@
# pesterchum
import os, shutil, sys, getopt
import configparser
if os.path.dirname(sys.argv[0]):
os.chdir(os.path.dirname(sys.argv[0]))
import logging
@ -3055,25 +3054,16 @@ class MainProgram(QtCore.QObject):
msgBox.addButton(QtGui.QPushButton('kaliope.ddns.net (Unofficial)'), QtGui.QMessageBox.RejectRole)
ret = msgBox.exec_()
reply = msgBox.buttonRole(msgBox.clickedButton())
config = configparser.ConfigParser()
config.read('server.ini')
if (reply==QtGui.QMessageBox.YesRole):
print("Server is: irc.mindfang.org")
config['SERVER']['server'] = 'irc.mindfang.org'
server = "irc.mindfang.org"
if (reply==QtGui.QMessageBox.NoRole):
print("Server is: pesterchum.xyz")
config['SERVER']['server'] = 'pesterchum.xyz'
server = "pesterchum.xyz"
if (reply==QtGui.QMessageBox.RejectRole):
print("Server is: kaliope.ddns.net")
config['SERVER']['server'] = 'kaliope.ddns.net'
#Write result to server.ini
with open('server.ini', 'w') as configfile:
config.write(configfile)
server = "kaliope.ddns.net"
def doSoundInit():
# TODO: Make this more uniform, adapt it into a general function.
@ -3149,31 +3139,36 @@ class MainProgram(QtCore.QObject):
self.attempts = 0
self.irc = PesterIRC(self.widget.config, self.widget)
# The way server is passed here now is also not ideal,
# but it's at least better than the way it was before.
self.irc = PesterIRC(self.widget.config, self.widget, server)
self.connectWidgets(self.irc, self.widget)
self.connect(self.widget, QtCore.SIGNAL('gainAttention(QWidget*)'),
self, QtCore.SLOT('alertWindow(QWidget*)'))
# This doesn't know as far as I'm aware, so it's commented out for now.
# 0 Once a day
# 1 Once a week
# 2 Only on start
# 3 Never
check = self.widget.config.checkForUpdates()
if check == 2:
self.runUpdateSlot()
elif check == 0:
seconds = 60 * 60 * 24
if int(time()) - self.widget.config.lastUCheck() < seconds:
seconds -= int(time()) - self.widget.config.lastUCheck()
if seconds < 0: seconds = 0
QtCore.QTimer.singleShot(1000*seconds, self, QtCore.SLOT('runUpdateSlot()'))
elif check == 1:
seconds = 60 * 60 * 24 * 7
if int(time()) - self.widget.config.lastUCheck() < seconds:
seconds -= int(time()) - self.widget.config.lastUCheck()
if seconds < 0: seconds = 0
QtCore.QTimer.singleShot(1000*seconds, self, QtCore.SLOT('runUpdateSlot()'))
#check = self.widget.config.checkForUpdates()
#if check == 2:
# self.runUpdateSlot()
#elif check == 0:
# seconds = 60 * 60 * 24
# if int(time()) - self.widget.config.lastUCheck() < seconds:
# seconds -= int(time()) - self.widget.config.lastUCheck()
# if seconds < 0: seconds = 0
# QtCore.QTimer.singleShot(1000*seconds, self, QtCore.SLOT('runUpdateSlot()'))
#elif check == 1:
# seconds = 60 * 60 * 24 * 7
# if int(time()) - self.widget.config.lastUCheck() < seconds:
# seconds -= int(time()) - self.widget.config.lastUCheck()
# if seconds < 0: seconds = 0
# QtCore.QTimer.singleShot(1000*seconds, self, QtCore.SLOT('runUpdateSlot()'))
@QtCore.pyqtSlot()
def runUpdateSlot(self):
@ -3379,7 +3374,7 @@ Click this message to never see this again.")
else:
stop = None
if stop is None:
self.irc = PesterIRC(self.widget.config, self.widget)
self.irc = PesterIRC(self.widget.config, self.widget, server)
self.connectWidgets(self.irc, self.widget)
self.irc.start()
if self.attempts == 1:

View file

@ -14,8 +14,6 @@ from mood import Mood
from dataobjs import PesterProfile, pesterQuirk, pesterQuirks
from parsetools import convertTags, addTimeInitial, themeChecker, ThemeException
import configparser # For loading server.ini
_datadir = ostools.getDataDir()
class PesterLog(object):
@ -287,10 +285,9 @@ class userConfig(object):
def server(self):
if hasattr(self.parent, 'serverOverride'):
return self.parent.serverOverride
# Get chosen server from server.ini
config = configparser.ConfigParser()
config.read('server.ini')
return self.config.get('server', config['SERVER']['server'])
# This is no longer used for choosing the server.
return self.config.get('server', "pesterchum.xyz")
def port(self):
if hasattr(self.parent, 'portOverride'):
return self.parent.portOverride

View file

@ -1,2 +0,0 @@
[SERVER]
server = 178.84.124.125