Only use metadata if server supports it. (RPL_ISUPPORT)

This commit is contained in:
Dpeta 2022-06-05 02:02:53 +02:00
parent 1120290539
commit 13608a3336

59
irc.py
View file

@ -2,7 +2,7 @@ import logging
import logging.config import logging.config
import socket import socket
import random import random
from time import time import time
from PyQt5 import QtCore, QtGui from PyQt5 import QtCore, QtGui
@ -35,6 +35,7 @@ class PesterIRC(QtCore.QThread):
self.mainwindow = window self.mainwindow = window
self.config = config self.config = config
self.registeredIRC = False self.registeredIRC = False
self.metadata_supported = False
self.stopIRC = None self.stopIRC = None
self.NickServ = services.NickServ() self.NickServ = services.NickServ()
self.ChanServ = services.ChanServ() self.ChanServ = services.ChanServ()
@ -331,7 +332,7 @@ class PesterIRC(QtCore.QThread):
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def pingServer(self): def pingServer(self):
try: try:
self.cli.send("PING %s" % int(time())) self.cli.send("PING %s" % int(time.time()))
except socket.error as e: except socket.error as e:
PchumLog.warning(e) PchumLog.warning(e)
self.setConnectionBroken() self.setConnectionBroken()
@ -488,8 +489,6 @@ class PesterHandler(DefaultCommandHandler):
#mychumhandle = self.mainwindow.profile().handle #mychumhandle = self.mainwindow.profile().handle
mymood = self.mainwindow.profile().mood.value() mymood = self.mainwindow.profile().mood.value()
if not self.mainwindow.config.lowBandwidth(): if not self.mainwindow.config.lowBandwidth():
from time import sleep
sleep(0.5) # To prevent TLS from dying </3
helpers.join(self.client, "#pesterchum") helpers.join(self.client, "#pesterchum")
# Moods via metadata # Moods via metadata
helpers.metadata(self.client, '*', 'sub', 'mood') helpers.metadata(self.client, '*', 'sub', 'mood')
@ -521,10 +520,10 @@ class PesterHandler(DefaultCommandHandler):
# RPL_ISUPPORT # RPL_ISUPPORT
features = params[:-1] features = params[:-1]
PchumLog.info("Server featurelist: " + str(features)) PchumLog.info("Server featurelist: " + str(features))
# for x in features: for x in features:
# if x.upper().startswith("METADATA"): if x.upper().startswith("METADATA"):
# print("True") PchumLog.info("Server supports metadata.")
# self.metadata_supported = True self.parent.metadata_supported = True
def nicknameinuse(self, server, cmd, nick, msg): def nicknameinuse(self, server, cmd, nick, msg):
newnick = "pesterClient%d" % (random.randint(100,999)) newnick = "pesterClient%d" % (random.randint(100,999))
@ -728,19 +727,47 @@ class PesterHandler(DefaultCommandHandler):
self.parent.tooManyPeeps.emit() self.parent.tooManyPeeps.emit()
def ping(self, prefix, server): def ping(self, prefix, server):
self.parent.mainwindow.lastping = int(time()) self.parent.mainwindow.lastping = int(time.time())
self.client.send('PONG', server) self.client.send('PONG', server)
def getMood(self, *chums): def getMood(self, *chums):
# Try to get mood via metadata get. # Try to get mood via metadata get.
# If it fails the old code is excecuted. # If it fails the old code is excecuted.
for c in chums:
chandle = c.handle # Wait for server to send welcome to verify RPL_ISUPPORT has been send.
try: while self.parent.registeredIRC == False:
helpers.metadata(self.client, chandle, "get", "mood") time.sleep(0.1)
except socket.error as e:
PchumLog.warning(e) # Get via metadata or via legacy method
self.parent.setConnectionBroken() if self.parent.metadata_supported == True:
# Metadata
for c in chums:
chandle = c.handle
try:
helpers.metadata(self.client, chandle, "get", "mood")
except socket.error as e:
PchumLog.warning(e)
self.parent.setConnectionBroken()
else:
# Legacy
chumglub = "GETMOOD "
for c in chums:
chandle = c.handle
if len(chumglub+chandle) >= 350:
try:
helpers.msg(self.client, "#pesterchum", chumglub)
except socket.error as e:
PchumLog.warning(e)
self.parent.setConnectionBroken()
chumglub = "GETMOOD "
chumglub += chandle
if chumglub != "GETMOOD ":
try:
helpers.msg(self.client, "#pesterchum", chumglub)
except socket.error as e:
PchumLog.warning(e)
self.parent.setConnectionBroken()
#def isOn(self, *chums): #def isOn(self, *chums):
# isonNicks = "" # isonNicks = ""