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) logging.basicConfig(level=logging.WARNING)
class PesterIRC(QtCore.QThread): class PesterIRC(QtCore.QThread):
def __init__(self, config, window): def __init__(self, config, window, server):
QtCore.QThread.__init__(self) QtCore.QThread.__init__(self)
self.mainwindow = window self.mainwindow = window
self.config = config self.config = config
self.server = server
self.registeredIRC = False self.registeredIRC = False
self.stopIRC = None self.stopIRC = None
self.NickServ = services.NickServ() self.NickServ = services.NickServ()
self.ChanServ = services.ChanServ() self.ChanServ = services.ChanServ()
def IRCConnect(self): def IRCConnect(self):
server = self.config.server()
port = self.config.port() 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 = 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.parent = self
self.cli.command_handler.mainwindow = self.mainwindow self.cli.command_handler.mainwindow = self.mainwindow

View file

@ -1,6 +1,5 @@
# pesterchum # pesterchum
import os, shutil, sys, getopt import os, shutil, sys, getopt
import configparser
if os.path.dirname(sys.argv[0]): if os.path.dirname(sys.argv[0]):
os.chdir(os.path.dirname(sys.argv[0])) os.chdir(os.path.dirname(sys.argv[0]))
import logging import logging
@ -3056,24 +3055,15 @@ class MainProgram(QtCore.QObject):
ret = msgBox.exec_() ret = msgBox.exec_()
reply = msgBox.buttonRole(msgBox.clickedButton()) reply = msgBox.buttonRole(msgBox.clickedButton())
config = configparser.ConfigParser()
config.read('server.ini')
if (reply==QtGui.QMessageBox.YesRole): if (reply==QtGui.QMessageBox.YesRole):
print("Server is: irc.mindfang.org") print("Server is: irc.mindfang.org")
config['SERVER']['server'] = 'irc.mindfang.org' server = "irc.mindfang.org"
if (reply==QtGui.QMessageBox.NoRole): if (reply==QtGui.QMessageBox.NoRole):
print("Server is: pesterchum.xyz") print("Server is: pesterchum.xyz")
config['SERVER']['server'] = 'pesterchum.xyz' server = "pesterchum.xyz"
if (reply==QtGui.QMessageBox.RejectRole): if (reply==QtGui.QMessageBox.RejectRole):
print("Server is: kaliope.ddns.net") print("Server is: kaliope.ddns.net")
config['SERVER']['server'] = 'kaliope.ddns.net' server = "kaliope.ddns.net"
#Write result to server.ini
with open('server.ini', 'w') as configfile:
config.write(configfile)
def doSoundInit(): def doSoundInit():
# TODO: Make this more uniform, adapt it into a general function. # TODO: Make this more uniform, adapt it into a general function.
@ -3149,31 +3139,36 @@ class MainProgram(QtCore.QObject):
self.attempts = 0 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.connectWidgets(self.irc, self.widget)
self.connect(self.widget, QtCore.SIGNAL('gainAttention(QWidget*)'), self.connect(self.widget, QtCore.SIGNAL('gainAttention(QWidget*)'),
self, QtCore.SLOT('alertWindow(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 # 0 Once a day
# 1 Once a week # 1 Once a week
# 2 Only on start # 2 Only on start
# 3 Never # 3 Never
check = self.widget.config.checkForUpdates() #check = self.widget.config.checkForUpdates()
if check == 2: #if check == 2:
self.runUpdateSlot() # self.runUpdateSlot()
elif check == 0: #elif check == 0:
seconds = 60 * 60 * 24 # seconds = 60 * 60 * 24
if int(time()) - self.widget.config.lastUCheck() < seconds: # if int(time()) - self.widget.config.lastUCheck() < seconds:
seconds -= int(time()) - self.widget.config.lastUCheck() # seconds -= int(time()) - self.widget.config.lastUCheck()
if seconds < 0: seconds = 0 # if seconds < 0: seconds = 0
QtCore.QTimer.singleShot(1000*seconds, self, QtCore.SLOT('runUpdateSlot()')) # QtCore.QTimer.singleShot(1000*seconds, self, QtCore.SLOT('runUpdateSlot()'))
elif check == 1: #elif check == 1:
seconds = 60 * 60 * 24 * 7 # seconds = 60 * 60 * 24 * 7
if int(time()) - self.widget.config.lastUCheck() < seconds: # if int(time()) - self.widget.config.lastUCheck() < seconds:
seconds -= int(time()) - self.widget.config.lastUCheck() # seconds -= int(time()) - self.widget.config.lastUCheck()
if seconds < 0: seconds = 0 # if seconds < 0: seconds = 0
QtCore.QTimer.singleShot(1000*seconds, self, QtCore.SLOT('runUpdateSlot()')) # QtCore.QTimer.singleShot(1000*seconds, self, QtCore.SLOT('runUpdateSlot()'))
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def runUpdateSlot(self): def runUpdateSlot(self):
@ -3379,7 +3374,7 @@ Click this message to never see this again.")
else: else:
stop = None stop = None
if stop is 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.connectWidgets(self.irc, self.widget)
self.irc.start() self.irc.start()
if self.attempts == 1: if self.attempts == 1:

View file

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

View file

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