Partially revert _mode changes
This commit is contained in:
parent
b5899d3a0c
commit
3326d7af50
2 changed files with 57 additions and 20 deletions
72
irc.py
72
irc.py
|
@ -716,23 +716,50 @@ class PesterIRC(QtCore.QThread):
|
||||||
self.moodUpdated.emit(handle, Mood("chummy"))
|
self.moodUpdated.emit(handle, Mood("chummy"))
|
||||||
|
|
||||||
def _mode(self, op, channel, mode, *handles):
|
def _mode(self, op, channel, mode, *handles):
|
||||||
"""'MODE' message from server, a user or a channel's mode changed."""
|
"""'MODE' message from server, a user or a channel's mode changed.
|
||||||
PchumLog.debug(
|
|
||||||
"mode(op=%s, channel=%s, mode=%s, handles=%s)", op, channel, mode, handles
|
This and the functions it calls to in the main thread seem pretty broken,
|
||||||
)
|
modes that aren't internally tracked aren't updated correctly."""
|
||||||
if not handles:
|
|
||||||
|
if len(handles) <= 0:
|
||||||
handles = [""]
|
handles = [""]
|
||||||
# opnick = op[0 : op.find("!")]
|
opnick = op[0 : op.find("!")]
|
||||||
|
PchumLog.debug("opnick=" + opnick)
|
||||||
|
|
||||||
|
self.modesUpdated.emit(channel, mode)
|
||||||
|
|
||||||
# Channel section
|
# Channel section
|
||||||
|
# Okay so, as I understand it channel modes will always be applied to a channel even if the commands also sets a mode to a user.
|
||||||
|
# So "MODE #channel +ro handleHandle" will set +r to channel #channel as well as set +o to handleHandle
|
||||||
|
# Therefore the bellow method causes a crash if both user and channel mode are being set in one command.
|
||||||
|
|
||||||
|
# if op == channel or channel == self.parent.mainwindow.profile().handle:
|
||||||
|
# modes = list(self.parent.mainwindow.modes)
|
||||||
|
# if modes and modes[0] == "+": modes = modes[1:]
|
||||||
|
# if mode[0] == "+":
|
||||||
|
# for m in mode[1:]:
|
||||||
|
# if m not in modes:
|
||||||
|
# modes.extend(m)
|
||||||
|
# elif mode[0] == "-":
|
||||||
|
# for i in mode[1:]:
|
||||||
|
# try:
|
||||||
|
# modes.remove(i)
|
||||||
|
# except ValueError:
|
||||||
|
# pass
|
||||||
|
# modes.sort()
|
||||||
|
# self.parent.mainwindow.modes = "+" + "".join(modes)
|
||||||
|
|
||||||
|
# EXPIRIMENTAL FIX
|
||||||
|
# No clue how stable this is but since it doesn't seem to cause a crash it's probably an improvement.
|
||||||
# This might be clunky with non-unrealircd IRC servers
|
# This might be clunky with non-unrealircd IRC servers
|
||||||
channel_mode = ""
|
channel_mode = ""
|
||||||
unrealircd_channel_modes = "cCdfGHikKLlmMNnOPpQRrsSTtVzZ"
|
unrealircd_channel_modes = "cCdfGHikKLlmMNnOPpQRrsSTtVzZ"
|
||||||
if any(md in mode for md in unrealircd_channel_modes):
|
if any(md in mode for md in unrealircd_channel_modes):
|
||||||
PchumLog.debug("Channel mode in string.")
|
PchumLog.debug("Channel mode in string.")
|
||||||
self._send_irc.mode(channel)
|
|
||||||
modes = list(self.mainwindow.modes)
|
modes = list(self.mainwindow.modes)
|
||||||
for md in unrealircd_channel_modes:
|
for md in unrealircd_channel_modes:
|
||||||
if mode.find(md) != -1: # -1 means not found
|
if mode.find(md) != -1: # -1 means not found
|
||||||
|
PchumLog.debug("md=" + md)
|
||||||
if mode[0] == "+":
|
if mode[0] == "+":
|
||||||
modes.extend(md)
|
modes.extend(md)
|
||||||
channel_mode = "+" + md
|
channel_mode = "+" + md
|
||||||
|
@ -744,10 +771,12 @@ class PesterIRC(QtCore.QThread):
|
||||||
PchumLog.warning(
|
PchumLog.warning(
|
||||||
"Can't remove channel mode that isn't set."
|
"Can't remove channel mode that isn't set."
|
||||||
)
|
)
|
||||||
self.userPresentUpdate.emit("", channel, f"{channel_mode}:{op}")
|
self.userPresentUpdate.emit(
|
||||||
PchumLog.debug("pre-mode=%s", mode)
|
"", channel, channel_mode + ":%s" % (op)
|
||||||
|
)
|
||||||
|
PchumLog.debug("pre-mode=" + str(mode))
|
||||||
mode = mode.replace(md, "")
|
mode = mode.replace(md, "")
|
||||||
PchumLog.debug("post-mode=%s", mode)
|
PchumLog.debug("post-mode=" + str(mode))
|
||||||
modes.sort()
|
modes.sort()
|
||||||
self.mainwindow.modes = "+" + "".join(modes)
|
self.mainwindow.modes = "+" + "".join(modes)
|
||||||
|
|
||||||
|
@ -757,14 +786,22 @@ class PesterIRC(QtCore.QThread):
|
||||||
if l in ["+", "-"]:
|
if l in ["+", "-"]:
|
||||||
cur = l
|
cur = l
|
||||||
else:
|
else:
|
||||||
modes.append(f"{cur}{l}")
|
modes.append("{}{}".format(cur, l))
|
||||||
for i, m in enumerate(modes):
|
for (i, m) in enumerate(modes):
|
||||||
|
|
||||||
# Server-set usermodes don't need to be passed.
|
# Server-set usermodes don't need to be passed.
|
||||||
if handles == [""] and not ("x" in m or "z" in m or "o" in m or "x" in m):
|
if (handles == [""]) & (("x" in m) | ("z" in m) | ("o" in m)) != True:
|
||||||
try:
|
try:
|
||||||
self.userPresentUpdate.emit(handles[i], channel, f"{m}:{op}")
|
self.userPresentUpdate.emit(handles[i], channel, m + ":%s" % (op))
|
||||||
except IndexError as e:
|
except IndexError as e:
|
||||||
PchumLog.exception("modeSetIndexError: %s", e)
|
PchumLog.exception("modeSetIndexError: %s" % e)
|
||||||
|
# print("i = " + i)
|
||||||
|
# print("m = " + m)
|
||||||
|
# self.parent.userPresentUpdate.emit(handles[i], channel, m+":%s" % (op))
|
||||||
|
# self.parent.userPresentUpdate.emit(handles[i], channel, m+":%s" % (op))
|
||||||
|
# Passing an empty handle here might cause a crash.
|
||||||
|
# except IndexError:
|
||||||
|
# self.parent.userPresentUpdate.emit("", channel, m+":%s" % (op))
|
||||||
|
|
||||||
def _invite(self, sender, _you, channel):
|
def _invite(self, sender, _you, channel):
|
||||||
"""'INVITE' message from server, someone invited us to a channel.
|
"""'INVITE' message from server, someone invited us to a channel.
|
||||||
|
@ -872,6 +909,7 @@ class PesterIRC(QtCore.QThread):
|
||||||
|
|
||||||
def _channelmodeis(self, _server, _handle, channel, modes, _mode_params=""):
|
def _channelmodeis(self, _server, _handle, channel, modes, _mode_params=""):
|
||||||
"""Numeric reply 324 RPL_CHANNELMODEIS, gives channel modes."""
|
"""Numeric reply 324 RPL_CHANNELMODEIS, gives channel modes."""
|
||||||
|
PchumLog.debug("324 RPL_CHANNELMODEIS %s: %s", channel, modes)
|
||||||
self.modesUpdated.emit(channel, modes)
|
self.modesUpdated.emit(channel, modes)
|
||||||
|
|
||||||
def _namreply(self, _server, _nick, _op, channel, names):
|
def _namreply(self, _server, _nick, _op, channel, names):
|
||||||
|
@ -929,9 +967,7 @@ class PesterIRC(QtCore.QThread):
|
||||||
|
|
||||||
def _reset_nick(self, oldnick):
|
def _reset_nick(self, oldnick):
|
||||||
"""Set our nick to a random pesterClient."""
|
"""Set our nick to a random pesterClient."""
|
||||||
random_number = int(
|
random_number = int(random.random() * 9999) # Random int in range 0 <---> 9999
|
||||||
random.random() * 9999 # Random int in range 0 <---> 9999
|
|
||||||
)
|
|
||||||
newnick = f"pesterClient{random_number}"
|
newnick = f"pesterClient{random_number}"
|
||||||
self._send_irc.nick(newnick)
|
self._send_irc.nick(newnick)
|
||||||
self.nickCollision.emit(oldnick, newnick)
|
self.nickCollision.emit(oldnick, newnick)
|
||||||
|
|
5
memos.py
5
memos.py
|
@ -973,6 +973,7 @@ class PesterMemo(PesterConvo):
|
||||||
self.userlist.addItem(u)
|
self.userlist.addItem(u)
|
||||||
|
|
||||||
def updateChanModes(self, modes, op):
|
def updateChanModes(self, modes, op):
|
||||||
|
PchumLog.debug("updateChanModes(%s, %s)", modes, op)
|
||||||
if not hasattr(self, "modes"):
|
if not hasattr(self, "modes"):
|
||||||
self.modes = ""
|
self.modes = ""
|
||||||
chanmodes = list(str(self.modes))
|
chanmodes = list(str(self.modes))
|
||||||
|
@ -1413,8 +1414,8 @@ class PesterMemo(PesterConvo):
|
||||||
|
|
||||||
@QtCore.pyqtSlot(QString, QString)
|
@QtCore.pyqtSlot(QString, QString)
|
||||||
def modesUpdated(self, channel, modes):
|
def modesUpdated(self, channel, modes):
|
||||||
c = str(channel)
|
PchumLog.debug(f"modesUpdated(%s, %s)", channel, modes)
|
||||||
if c.lower() == self.channel.lower():
|
if channel.lower() == self.channel.lower():
|
||||||
self.updateChanModes(modes, None)
|
self.updateChanModes(modes, None)
|
||||||
|
|
||||||
@QtCore.pyqtSlot(QString)
|
@QtCore.pyqtSlot(QString)
|
||||||
|
|
Loading…
Reference in a new issue