Pretty functional now!!

This commit is contained in:
Dpeta 2023-02-03 22:46:48 +01:00
parent 9f319b7054
commit 9d7ffee465
No known key found for this signature in database
GPG key ID: 51227517CEA0030C
4 changed files with 197 additions and 332 deletions

506
irc.py
View file

@ -91,10 +91,7 @@ class PesterIRC(QtCore.QThread):
self.timeout = 120 self.timeout = 120
self.blocking = True self.blocking = True
self._end = False self._end = False
self.command_handler = self
self.parent = self
self.send_irc = scripts.irc.outgoing.SendIRC() self.send_irc = scripts.irc.outgoing.SendIRC()
def get_ssl_context(self): def get_ssl_context(self):
@ -364,14 +361,14 @@ class PesterIRC(QtCore.QThread):
"""Get mood via metadata if supported""" """Get mood via metadata if supported"""
# Get via metadata or via legacy method # Get via metadata or via legacy method
if self.parent.metadata_supported: if self.metadata_supported:
# Metadata # Metadata
for chum in chums: for chum in chums:
try: try:
self.send_irc.metadata(chum.handle, "get", "mood") self.send_irc.metadata(chum.handle, "get", "mood")
except OSError as e: except OSError as e:
PchumLog.warning(e) PchumLog.warning(e)
self.parent.setConnectionBroken() self.setConnectionBroken()
else: else:
# Legacy # Legacy
PchumLog.warning( PchumLog.warning(
@ -381,259 +378,157 @@ class PesterIRC(QtCore.QThread):
for chum in chums: for chum in chums:
if len(chumglub + chum.handle) >= 350: if len(chumglub + chum.handle) >= 350:
try: try:
self.send_irc.msg("#pesterchum", chumglub) self.send_irc.privmsg("#pesterchum", chumglub)
except OSError as e: except OSError as e:
PchumLog.warning(e) PchumLog.warning(e)
self.parent.setConnectionBroken() self.setConnectionBroken()
chumglub = "GETMOOD " chumglub = "GETMOOD "
# No point in GETMOOD-ing services # No point in GETMOOD-ing services
if chum.handle.casefold() not in SERVICES: if chum.handle.casefold() not in SERVICES:
chumglub += chum.handle chumglub += chum.handle
if chumglub != "GETMOOD ": if chumglub != "GETMOOD ":
try: try:
self.send_irc.msg("#pesterchum", chumglub) self.send_irc.privmsg("#pesterchum", chumglub)
except OSError as e: except OSError as e:
PchumLog.warning(e) PchumLog.warning(e)
self.parent.setConnectionBroken() self.setConnectionBroken()
@QtCore.pyqtSlot(PesterList) @QtCore.pyqtSlot(PesterList)
def getMoods(self, chums): def getMoods(self, chums):
if hasattr(self, "cli"): self.getMood(*chums)
self.command_handler.getMood(*chums)
@QtCore.pyqtSlot(QString, QString) @QtCore.pyqtSlot(QString, QString)
def sendNotice(self, text, handle): def sendNotice(self, text, handle):
if hasattr(self, "cli"): self.send_irc.notice(handle, text)
h = str(handle)
t = str(text)
try:
self.send_irc.notice(h, t)
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString, QString) @QtCore.pyqtSlot(QString, QString)
def sendMessage(self, text, handle): def sendMessage(self, text, handle):
if hasattr(self, "cli"): h = str(handle)
h = str(handle) textl = [str(text)]
textl = [str(text)]
def splittext(l): def splittext(l):
if len(l[0]) > 450: if len(l[0]) > 450:
space = l[0].rfind(" ", 0, 430) space = l[0].rfind(" ", 0, 430)
if space == -1: if space == -1:
space = 450 space = 450
elif l[0][space + 1 : space + 5] == "</c>": elif l[0][space + 1 : space + 5] == "</c>":
space = space + 4 space = space + 4
a = l[0][0 : space + 1] a = l[0][0 : space + 1]
b = l[0][space + 1 :] b = l[0][space + 1 :]
if a.count("<c") > a.count("</c>"): if a.count("<c") > a.count("</c>"):
# oh god ctags will break!! D= # oh god ctags will break!! D=
hanging = [] hanging = []
usedends = [] usedends = []
c = a.rfind("<c") c = a.rfind("<c")
while c != -1: while c != -1:
d = a.find("</c>", c) d = a.find("</c>", c)
while d in usedends: while d in usedends:
d = a.find("</c>", d + 1) d = a.find("</c>", d + 1)
if d != -1: if d != -1:
usedends.append(d) usedends.append(d)
else: else:
f = a.find(">", c) + 1 f = a.find(">", c) + 1
hanging.append(a[c:f]) hanging.append(a[c:f])
c = a.rfind("<c", 0, c) c = a.rfind("<c", 0, c)
# end all ctags in first part # end all ctags in first part
for _ in range(a.count("<c") - a.count("</c>")): for _ in range(a.count("<c") - a.count("</c>")):
a = a + "</c>" a = a + "</c>"
# start them up again in the second part # start them up again in the second part
for c in hanging: for c in hanging:
b = c + b b = c + b
if len(b) > 0: if len(b) > 0:
return [a] + splittext([b]) return [a] + splittext([b])
else:
return [a]
else: else:
return l return [a]
else:
return l
textl = splittext(textl) textl = splittext(textl)
try: try:
for t in textl: for t in textl:
self.send_irc.msg(h, t) self.send_irc.privmsg(h, t)
except OSError as e: except OSError as e:
PchumLog.warning(e) PchumLog.warning(e)
self.setConnectionBroken() self.setConnectionBroken()
@QtCore.pyqtSlot( @QtCore.pyqtSlot(
QString, QString,
QString, QString,
) )
def sendCTCP(self, handle, text): def sendCTCP(self, handle, text):
if hasattr(self, "cli"): self.send_irc.ctcp(handle, text)
try:
self.send_irc.ctcp(handle, text)
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString, bool) @QtCore.pyqtSlot(QString, bool)
def startConvo(self, handle, initiated): def startConvo(self, handle, initiated):
if hasattr(self, "cli"): self.send_irc.privmsg(handle, "COLOR >%s" % (self.mainwindow.profile().colorcmd()))
h = str(handle) if initiated:
try: self.send_irc.privmsg(handle, "PESTERCHUM:BEGIN")
self.send_irc.msg(h, "COLOR >%s" % (self.mainwindow.profile().colorcmd())
)
if initiated:
self.send_irc.msg(h, "PESTERCHUM:BEGIN")
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString) @QtCore.pyqtSlot(QString)
def endConvo(self, handle): def endConvo(self, handle):
if hasattr(self, "cli"): self.send_irc.privmsg(handle, "PESTERCHUM:CEASE")
h = str(handle)
try:
self.send_irc.msg(h, "PESTERCHUM:CEASE")
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def updateProfile(self): def updateProfile(self):
if hasattr(self, "cli"): me = self.mainwindow.profile()
me = self.mainwindow.profile() handle = me.handle
handle = me.handle self.send_irc.nick(handle)
try: self.mainwindow.closeConversations(True)
self.send_irc.nick(handle) self.mainwindow.doAutoIdentify()
except OSError as e: self.mainwindow.autoJoinDone = False
PchumLog.warning(e) self.mainwindow.doAutoJoins()
self.setConnectionBroken() self.updateMood()
self.mainwindow.closeConversations(True)
self.mainwindow.doAutoIdentify()
self.mainwindow.autoJoinDone = False
self.mainwindow.doAutoJoins()
self.updateMood()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def updateMood(self): def updateMood(self):
if hasattr(self, "cli"): me = self.mainwindow.profile()
me = self.mainwindow.profile() # Moods via metadata
# Moods via metadata self.send_irc.metadata("*", "set", "mood", str(me.mood.value()))
try: # Backwards compatibility
self.send_irc.metadata("*", "set", "mood", str(me.mood.value())) self.send_irc.privmsg("#pesterchum", "MOOD >%d" % (me.mood.value()))
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
# Backwards compatibility
try:
self.send_irc.msg("#pesterchum", "MOOD >%d" % (me.mood.value()))
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def updateColor(self): def updateColor(self):
if hasattr(self, "cli"): # Update color metadata field
# PchumLog.debug("irc updateColor (outgoing)") color = self.mainwindow.profile().color
# me = self.mainwindow.profile() self.send_irc.metadata("*", "set", "color", str(color.name()))
# Update color metadata field # Send color messages
try: for h in list(self.mainwindow.convos.keys()):
color = self.mainwindow.profile().color self.send_irc.privmsg(
self.send_irc.metadata("*", "set", "color", str(color.name())) h,
except OSError as e: "COLOR >%s" % (self.mainwindow.profile().colorcmd()),
PchumLog.warning(e) )
self.setConnectionBroken()
# Send color messages
for h in list(self.mainwindow.convos.keys()):
try:
self.send_irc.msg(
h,
"COLOR >%s" % (self.mainwindow.profile().colorcmd()),
)
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString) @QtCore.pyqtSlot(QString)
def blockedChum(self, handle): def blockedChum(self, handle):
if hasattr(self, "cli"): self.send_irc.privmsg(handle, "PESTERCHUM:BLOCK")
h = str(handle)
try:
self.send_irc.msg(h, "PESTERCHUM:BLOCK")
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString) @QtCore.pyqtSlot(QString)
def unblockedChum(self, handle): def unblockedChum(self, handle):
if hasattr(self, "cli"): self.send_irc.privmsg(handle, "PESTERCHUM:UNBLOCK")
h = str(handle)
try:
self.send_irc.msg(h, "PESTERCHUM:UNBLOCK")
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString) @QtCore.pyqtSlot(QString)
def requestNames(self, channel): def requestNames(self, channel):
if hasattr(self, "cli"): self.send_irc.names(channel)
c = str(channel)
try:
self.send_irc.names(c)
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def requestChannelList(self): def requestChannelList(self):
if hasattr(self, "cli"): self.send_irc.list()
try:
self.send_irc.channel_list(self)
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString) @QtCore.pyqtSlot(QString)
def joinChannel(self, channel): def joinChannel(self, channel):
if hasattr(self, "cli"): self.send_irc.join(channel)
c = str(channel) self.send_irc.mode(channel)
try:
self.send_irc.join(c)
self.send_irc.mode(c, "", None)
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString) @QtCore.pyqtSlot(QString)
def leftChannel(self, channel): def leftChannel(self, channel):
if hasattr(self, "cli"): self.send_irc.part(channel)
c = str(channel) self.joined = False
try:
self.send_irc.part(c)
self.command_handler.joined = False
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString, QString) @QtCore.pyqtSlot(QString, QString, QString)
def kickUser(self, handle, channel): def kickUser(self, channel, user, reason=""):
if hasattr(self, "cli"): self.send_irc.kick(channel, user, reason)
l = handle.split(":")
c = str(channel)
h = str(l[0])
if len(l) > 1:
reason = str(l[1])
if len(l) > 2:
for x in l[2:]:
reason += ":" + str(x)
else:
reason = ""
try:
self.send_irc.kick(channel, h, reason)
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString, QString, QString) @QtCore.pyqtSlot(QString, QString, QString)
def setChannelMode(self, channel, mode, command): def setChannelMode(self, channel, mode, command):
@ -641,74 +536,44 @@ class PesterIRC(QtCore.QThread):
@QtCore.pyqtSlot(QString) @QtCore.pyqtSlot(QString)
def channelNames(self, channel): def channelNames(self, channel):
if hasattr(self, "cli"): self.send_irc.names(channel)
c = str(channel)
try:
self.send_irc.names(c)
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString, QString) @QtCore.pyqtSlot(QString, QString)
def inviteChum(self, handle, channel): def inviteChum(self, handle, channel):
if hasattr(self, "cli"): self.send_irc.invite(handle, channel)
h = str(handle)
c = str(channel)
try:
self.send_irc.invite(h, c)
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def pingServer(self): def pingServer(self):
try: self.send_irc.ping("B33")
self.send_irc.ping("B33")
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(bool) @QtCore.pyqtSlot(bool)
def setAway(self, away=True): def setAway(self, away=True):
try: if away:
if away: self.away("Idle")
self.away("Idle") else:
else: self.away()
self.away()
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot(QString, QString) @QtCore.pyqtSlot(QString, QString)
def killSomeQuirks(self, channel, handle): def killSomeQuirks(self, channel, handle):
if hasattr(self, "cli"): self.send_irc.ctcp(channel, "NOQUIRKS", handle)
c = str(channel)
h = str(handle)
try:
self.send_irc.ctcp(c, "NOQUIRKS", h)
except OSError as e:
PchumLog.warning(e)
self.setConnectionBroken()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def disconnectIRC(self): def disconnectIRC(self):
if hasattr(self, "cli"): self.send_irc.quit(f"{_pcVersion} <3")
self.send_irc.quit(_pcVersion + " <3") self._end = True
self._end = True self.close()
self.close()
def notice(self, nick, chan, msg): def notice(self, nick, chan, msg):
handle = nick[0 : nick.find("!")] handle = nick[0 : nick.find("!")]
PchumLog.info('---> recv "NOTICE {} :{}"'.format(handle, msg)) PchumLog.info('---> recv "NOTICE {} :{}"'.format(handle, msg))
if ( if (
handle == "ChanServ" handle == "ChanServ"
and chan == self.parent.mainwindow.profile().handle and chan == self.mainwindow.profile().handle
and msg[0:2] == "[#" and msg[0:2] == "[#"
): ):
self.parent.memoReceived.emit(msg[1 : msg.index("]")], handle, msg) self.memoReceived.emit(msg[1 : msg.index("]")], handle, msg)
else: else:
self.parent.noticeReceived.emit(handle, msg) self.noticeReceived.emit(handle, msg)
def metadata(self, target, nick, key, visibility, value): def metadata(self, target, nick, key, visibility, value):
# The format of the METADATA server notication is: # The format of the METADATA server notication is:
@ -716,12 +581,12 @@ class PesterIRC(QtCore.QThread):
if key.lower() == "mood": if key.lower() == "mood":
try: try:
mood = Mood(int(value)) mood = Mood(int(value))
self.parent.moodUpdated.emit(nick, mood) self.moodUpdated.emit(nick, mood)
except ValueError: except ValueError:
PchumLog.warning("Invalid mood value, {}, {}".format(nick, mood)) PchumLog.warning("Invalid mood value, {}, {}".format(nick, mood))
elif key.lower() == "color": elif key.lower() == "color":
color = QtGui.QColor(value) # Invalid color becomes rgb 0,0,0 color = QtGui.QColor(value) # Invalid color becomes rgb 0,0,0
self.parent.colorUpdated.emit(nick, color) self.colorUpdated.emit(nick, color)
def tagmsg(self, prefix, tags, *args): def tagmsg(self, prefix, tags, *args):
PchumLog.info("TAGMSG: {} {} {}".format(prefix, tags, str(args))) PchumLog.info("TAGMSG: {} {} {}".format(prefix, tags, str(args)))
@ -764,14 +629,14 @@ class PesterIRC(QtCore.QThread):
# Server is ending connection. # Server is ending connection.
reason = "" reason = ""
for x in params: for x in params:
if (x != None) and (x != ""): if x:
reason += x + " " reason += x + " "
self.parent.stopIRC = reason.strip() self.stopIRC = reason.strip()
self.parent.disconnectIRC() self.disconnectIRC()
def privmsg(self, nick, chan, msg): def privmsg(self, nick, chan, msg):
handle = nick[0 : nick.find("!")] handle = nick[0 : nick.find("!")]
if len(msg) == 0: if not msg: # Length 0
return return
# CTCP # CTCP
@ -809,7 +674,7 @@ class PesterIRC(QtCore.QThread):
# ??? # ???
elif msg[1:-1].startswith("NOQUIRKS") and chan[0] == "#": elif msg[1:-1].startswith("NOQUIRKS") and chan[0] == "#":
op = nick[0 : nick.find("!")] op = nick[0 : nick.find("!")]
self.parent.quirkDisable.emit(chan, msg[10:-1], op) self.quirkDisable.emit(chan, msg[10:-1], op)
# GETMOOD via CTCP # GETMOOD via CTCP
elif msg[1:-1].startswith("GETMOOD"): elif msg[1:-1].startswith("GETMOOD"):
# GETMOOD via CTCP # GETMOOD via CTCP
@ -817,7 +682,7 @@ class PesterIRC(QtCore.QThread):
mymood = self.mainwindow.profile().mood.value() mymood = self.mainwindow.profile().mood.value()
self.send_irc.ctcp(handle, "MOOD >%d" % (mymood)) self.send_irc.ctcp(handle, "MOOD >%d" % (mymood))
# Backwards compatibility # Backwards compatibility
self.send_irc.msg("#pesterchum", "MOOD >%d" % (mymood)) self.send_irc.privmsg("#pesterchum", "MOOD >%d" % (mymood))
return return
if chan != "#pesterchum": if chan != "#pesterchum":
@ -831,17 +696,17 @@ class PesterIRC(QtCore.QThread):
mood = Mood(int(msg[6:])) mood = Mood(int(msg[6:]))
except ValueError: except ValueError:
mood = Mood(0) mood = Mood(0)
self.parent.moodUpdated.emit(handle, mood) self.moodUpdated.emit(handle, mood)
elif msg[0:7] == "GETMOOD": elif msg[0:7] == "GETMOOD":
mychumhandle = self.mainwindow.profile().handle mychumhandle = self.mainwindow.profile().handle
mymood = self.mainwindow.profile().mood.value() mymood = self.mainwindow.profile().mood.value()
if msg.find(mychumhandle, 8) != -1: if msg.find(mychumhandle, 8) != -1:
self.send_irc.msg("#pesterchum", "MOOD >%d" % (mymood)) self.send_irc.privmsg("#pesterchum", "MOOD >%d" % (mymood))
elif chan[0] == "#": elif chan[0] == "#":
if msg[0:16] == "PESTERCHUM:TIME>": if msg[0:16] == "PESTERCHUM:TIME>":
self.parent.timeCommand.emit(chan, handle, msg[16:]) self.timeCommand.emit(chan, handle, msg[16:])
else: else:
self.parent.memoReceived.emit(chan, handle, msg) self.memoReceived.emit(chan, handle, msg)
else: else:
# private message # private message
# silently ignore messages to yourself. # silently ignore messages to yourself.
@ -856,19 +721,12 @@ class PesterIRC(QtCore.QThread):
colors = [0, 0, 0] colors = [0, 0, 0]
PchumLog.debug("colors: " + str(colors)) PchumLog.debug("colors: " + str(colors))
color = QtGui.QColor(*colors) color = QtGui.QColor(*colors)
self.parent.colorUpdated.emit(handle, color) self.colorUpdated.emit(handle, color)
else: else:
self.parent.messageReceived.emit(handle, msg) self.messageReceived.emit(handle, msg)
def pong(self, *args):
# source, server, token
# print("PONG", source, server, token)
# self.parent.mainwindow.lastrecv = time.time()
# print("PONG TIME: %s" % self.parent.mainwindow.lastpong)
pass
def welcome(self, server, nick, msg): def welcome(self, server, nick, msg):
self.parent.setConnected() self.setConnected()
# mychumhandle = self.mainwindow.profile().handle # mychumhandle = self.mainwindow.profile().handle
mymood = self.mainwindow.profile().mood.value() mymood = self.mainwindow.profile().mood.value()
color = self.mainwindow.profile().color color = self.mainwindow.profile().color
@ -890,7 +748,7 @@ class PesterIRC(QtCore.QThread):
self.send_irc.metadata("*", "sub", "color") self.send_irc.metadata("*", "sub", "color")
self.send_irc.metadata("*", "set", "color", str(color.name())) self.send_irc.metadata("*", "set", "color", str(color.name()))
# Backwards compatible moods # Backwards compatible moods
self.send_irc.msg("#pesterchum", "MOOD >%d" % (mymood)) self.send_irc.privmsg("#pesterchum", "MOOD >%d" % (mymood))
def erroneusnickname(self, *args): def erroneusnickname(self, *args):
# Server is not allowing us to connect. # Server is not allowing us to connect.
@ -898,18 +756,18 @@ class PesterIRC(QtCore.QThread):
for x in args: for x in args:
if (x != None) and (x != ""): if (x != None) and (x != ""):
reason += x + " " reason += x + " "
self.parent.stopIRC = reason.strip() self.stopIRC = reason.strip()
self.parent.disconnectIRC() self.disconnectIRC()
def keyvalue(self, target, handle_us, handle_owner, key, visibility, *value): def keyvalue(self, target, handle_us, handle_owner, key, visibility, *value):
# The format of the METADATA server notication is: # The format of the METADATA server notication is:
# METADATA <Target> <Key> <Visibility> <Value> # METADATA <Target> <Key> <Visibility> <Value>
if key == "mood": if key == "mood":
mood = Mood(int(value[0])) mood = Mood(int(value[0]))
self.parent.moodUpdated.emit(handle_owner, mood) self.moodUpdated.emit(handle_owner, mood)
def metadatasubok(self, *params): def metadatasubok(self, *params):
PchumLog.info("metadatasubok: " + str(params)) PchumLog.info("metadatasubok: %s", params)
def nomatchingkey(self, target, our_handle, failed_handle, key, *error): def nomatchingkey(self, target, our_handle, failed_handle, key, *error):
# Try to get moods the old way if metadata fails. # Try to get moods the old way if metadata fails.
@ -917,30 +775,30 @@ class PesterIRC(QtCore.QThread):
# No point in GETMOOD-ing services # No point in GETMOOD-ing services
if failed_handle.casefold() not in SERVICES: if failed_handle.casefold() not in SERVICES:
try: try:
self.send_irc.msg("#pesterchum", f"GETMOOD {failed_handle}") self.send_irc.privmsg("#pesterchum", f"GETMOOD {failed_handle}")
except OSError as e: except OSError as e:
PchumLog.warning(e) PchumLog.warning(e)
self.parent.setConnectionBroken() self.setConnectionBroken()
def keynotset(self, target, our_handle, failed_handle, key, *error): def keynotset(self, target, our_handle, failed_handle, key, *error):
# Try to get moods the old way if metadata fails. # Try to get moods the old way if metadata fails.
PchumLog.info("nomatchingkey: " + failed_handle) PchumLog.info("nomatchingkey: " + failed_handle)
chumglub = "GETMOOD " chumglub = "GETMOOD "
try: try:
self.send_irc.msg("#pesterchum", chumglub + failed_handle) self.send_irc.privmsg("#pesterchum", chumglub + failed_handle)
except OSError as e: except OSError as e:
PchumLog.warning(e) PchumLog.warning(e)
self.parent.setConnectionBroken() self.setConnectionBroken()
def keynopermission(self, target, our_handle, failed_handle, key, *error): def keynopermission(self, target, our_handle, failed_handle, key, *error):
# Try to get moods the old way if metadata fails. # Try to get moods the old way if metadata fails.
PchumLog.info("nomatchingkey: " + failed_handle) PchumLog.info("nomatchingkey: " + failed_handle)
chumglub = "GETMOOD " chumglub = "GETMOOD "
try: try:
self.send_irc.msg("#pesterchum", chumglub + failed_handle) self.send_irc.privmsg("#pesterchum", chumglub + failed_handle)
except OSError as e: except OSError as e:
PchumLog.warning(e) PchumLog.warning(e)
self.parent.setConnectionBroken() self.setConnectionBroken()
def featurelist(self, target, handle, *params): def featurelist(self, target, handle, *params):
# Better to do this via CAP ACK/CAP NEK # Better to do this via CAP ACK/CAP NEK
@ -950,7 +808,7 @@ class PesterIRC(QtCore.QThread):
for x in features: for x in features:
if x.upper().startswith("METADATA"): if x.upper().startswith("METADATA"):
PchumLog.info("Server supports metadata.") PchumLog.info("Server supports metadata.")
self.parent.metadata_supported = True self.metadata_supported = True
def cap(self, server, nick, subcommand, tag): def cap(self, server, nick, subcommand, tag):
PchumLog.info("CAP {} {} {} {}".format(server, nick, subcommand, tag)) PchumLog.info("CAP {} {} {} {}".format(server, nick, subcommand, tag))
@ -960,29 +818,29 @@ class PesterIRC(QtCore.QThread):
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))
self.send_irc.nick(newnick) self.send_irc.nick(newnick)
self.parent.nickCollision.emit(nick, newnick) self.nickCollision.emit(nick, newnick)
def nickcollision(self, server, cmd, nick, msg): def nickcollision(self, server, cmd, nick, msg):
newnick = "pesterClient%d" % (random.randint(100, 999)) newnick = "pesterClient%d" % (random.randint(100, 999))
self.send_irc.nick(newnick) self.send_irc.nick(newnick)
self.parent.nickCollision.emit(nick, newnick) self.nickCollision.emit(nick, newnick)
def quit(self, nick, reason): def quit(self, nick, reason):
handle = nick[0 : nick.find("!")] handle = nick[0 : nick.find("!")]
PchumLog.info('---> recv "QUIT {}: {}"'.format(handle, reason)) PchumLog.info('---> recv "QUIT {}: {}"'.format(handle, reason))
if handle == self.parent.mainwindow.randhandler.randNick: if handle == self.mainwindow.randhandler.randNick:
self.parent.mainwindow.randhandler.setRunning(False) self.mainwindow.randhandler.setRunning(False)
server = self.parent.mainwindow.config.server() server = self.mainwindow.config.server()
baseserver = server[server.rfind(".", 0, server.rfind(".")) :] baseserver = server[server.rfind(".", 0, server.rfind(".")) :]
if reason.count(baseserver) == 2: if reason.count(baseserver) == 2:
self.parent.userPresentUpdate.emit(handle, "", "netsplit") self.userPresentUpdate.emit(handle, "", "netsplit")
else: else:
self.parent.userPresentUpdate.emit(handle, "", "quit") self.userPresentUpdate.emit(handle, "", "quit")
self.parent.moodUpdated.emit(handle, Mood("offline")) self.moodUpdated.emit(handle, Mood("offline"))
def kick(self, opnick, channel, handle, reason): def kick(self, opnick, channel, handle, reason):
op = opnick[0 : opnick.find("!")] op = opnick[0 : opnick.find("!")]
self.parent.userPresentUpdate.emit( self.userPresentUpdate.emit(
handle, channel, "kick:{}:{}".format(op, reason) handle, channel, "kick:{}:{}".format(op, reason)
) )
# ok i shouldnt be overloading that but am lazy # ok i shouldnt be overloading that but am lazy
@ -990,18 +848,18 @@ class PesterIRC(QtCore.QThread):
def part(self, nick, channel, reason="nanchos"): def part(self, nick, channel, reason="nanchos"):
handle = nick[0 : nick.find("!")] handle = nick[0 : nick.find("!")]
PchumLog.info('---> recv "PART {}: {}"'.format(handle, channel)) PchumLog.info('---> recv "PART {}: {}"'.format(handle, channel))
self.parent.userPresentUpdate.emit(handle, channel, "left") self.userPresentUpdate.emit(handle, channel, "left")
if channel == "#pesterchum": if channel == "#pesterchum":
self.parent.moodUpdated.emit(handle, Mood("offline")) self.moodUpdated.emit(handle, Mood("offline"))
def join(self, nick, channel): def join(self, nick, channel):
handle = nick[0 : nick.find("!")] handle = nick[0 : nick.find("!")]
PchumLog.info('---> recv "JOIN {}: {}"'.format(handle, channel)) PchumLog.info('---> recv "JOIN {}: {}"'.format(handle, channel))
self.parent.userPresentUpdate.emit(handle, channel, "join") self.userPresentUpdate.emit(handle, channel, "join")
if channel == "#pesterchum": if channel == "#pesterchum":
if handle == self.parent.mainwindow.randhandler.randNick: if handle == self.mainwindow.randhandler.randNick:
self.parent.mainwindow.randhandler.setRunning(True) self.mainwindow.randhandler.setRunning(True)
self.parent.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):
PchumLog.debug("op=" + str(op)) PchumLog.debug("op=" + str(op))
@ -1019,8 +877,8 @@ class PesterIRC(QtCore.QThread):
# So "MODE #channel +ro handleHandle" will set +r to channel #channel as well as set +o to handleHandle # 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. # 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: # if op == channel or channel == self.mainwindow.profile().handle:
# modes = list(self.parent.mainwindow.modes) # modes = list(self.mainwindow.modes)
# if modes and modes[0] == "+": modes = modes[1:] # if modes and modes[0] == "+": modes = modes[1:]
# if mode[0] == "+": # if mode[0] == "+":
# for m in mode[1:]: # for m in mode[1:]:
@ -1033,7 +891,7 @@ class PesterIRC(QtCore.QThread):
# except ValueError: # except ValueError:
# pass # pass
# modes.sort() # modes.sort()
# self.parent.mainwindow.modes = "+" + "".join(modes) # self.mainwindow.modes = "+" + "".join(modes)
# EXPIRIMENTAL FIX # EXPIRIMENTAL FIX
# No clue how stable this is but since it doesn't seem to cause a crash it's probably an improvement. # No clue how stable this is but since it doesn't seem to cause a crash it's probably an improvement.
@ -1071,7 +929,7 @@ class PesterIRC(QtCore.QThread):
] ]
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.")
modes = list(self.parent.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) PchumLog.debug("md=" + md)
@ -1086,14 +944,14 @@ 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.parent.userPresentUpdate.emit( self.userPresentUpdate.emit(
"", channel, channel_mode + ":%s" % (op) "", channel, channel_mode + ":%s" % (op)
) )
PchumLog.debug("pre-mode=" + str(mode)) PchumLog.debug("pre-mode=" + str(mode))
mode = mode.replace(md, "") mode = mode.replace(md, "")
PchumLog.debug("post-mode=" + str(mode)) PchumLog.debug("post-mode=" + str(mode))
modes.sort() modes.sort()
self.parent.mainwindow.modes = "+" + "".join(modes) self.mainwindow.modes = "+" + "".join(modes)
modes = [] modes = []
cur = "+" cur = "+"
@ -1111,25 +969,25 @@ class PesterIRC(QtCore.QThread):
("x" in m) | ("z" in m) | ("o" in m) | ("x" in m) ("x" in m) | ("z" in m) | ("o" in m) | ("x" in m)
) != True: ) != True:
try: try:
self.parent.userPresentUpdate.emit( self.userPresentUpdate.emit(
handles[i], channel, m + ":%s" % (op) 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("i = " + i)
# print("m = " + m) # print("m = " + m)
# self.parent.userPresentUpdate.emit(handles[i], channel, m+":%s" % (op)) # self.userPresentUpdate.emit(handles[i], channel, m+":%s" % (op))
# self.parent.userPresentUpdate.emit(handles[i], channel, m+":%s" % (op)) # self.userPresentUpdate.emit(handles[i], channel, m+":%s" % (op))
# Passing an empty handle here might cause a crash. # Passing an empty handle here might cause a crash.
# except IndexError: # except IndexError:
# self.parent.userPresentUpdate.emit("", channel, m+":%s" % (op)) # self.userPresentUpdate.emit("", channel, m+":%s" % (op))
def nick(self, oldnick, newnick, hopcount=0): def nick(self, oldnick, newnick, hopcount=0):
PchumLog.info("{}, {}".format(oldnick, newnick)) PchumLog.info("{}, {}".format(oldnick, newnick))
# svsnick # svsnick
if oldnick == self.mainwindow.profile().handle: if oldnick == self.mainwindow.profile().handle:
# Server changed our handle, svsnick? # Server changed our handle, svsnick?
self.parent.getSvsnickedOn.emit(oldnick, newnick) self.getSvsnickedOn.emit(oldnick, newnick)
# etc. # etc.
oldhandle = oldnick[0 : oldnick.find("!")] oldhandle = oldnick[0 : oldnick.find("!")]
@ -1137,18 +995,18 @@ class PesterIRC(QtCore.QThread):
newnick == self.mainwindow.profile().handle newnick == self.mainwindow.profile().handle
): ):
# print('hewwo') # print('hewwo')
self.parent.myHandleChanged.emit(newnick) self.myHandleChanged.emit(newnick)
newchum = PesterProfile(newnick, chumdb=self.mainwindow.chumdb) newchum = PesterProfile(newnick, chumdb=self.mainwindow.chumdb)
self.parent.moodUpdated.emit(oldhandle, Mood("offline")) self.moodUpdated.emit(oldhandle, Mood("offline"))
self.parent.userPresentUpdate.emit( self.userPresentUpdate.emit(
"{}:{}".format(oldhandle, newnick), "", "nick" "{}:{}".format(oldhandle, newnick), "", "nick"
) )
if newnick in self.mainwindow.chumList.chums: if newnick in self.mainwindow.chumList.chums:
self.getMood(newchum) self.getMood(newchum)
if oldhandle == self.parent.mainwindow.randhandler.randNick: if oldhandle == self.mainwindow.randhandler.randNick:
self.parent.mainwindow.randhandler.setRunning(False) self.mainwindow.randhandler.setRunning(False)
elif newnick == self.parent.mainwindow.randhandler.randNick: elif newnick == self.mainwindow.randhandler.randNick:
self.parent.mainwindow.randhandler.setRunning(True) self.mainwindow.randhandler.setRunning(True)
def namreply(self, server, nick, op, channel, names): def namreply(self, server, nick, op, channel, names):
namelist = names.split(" ") namelist = names.split(" ")
@ -1164,11 +1022,11 @@ class PesterIRC(QtCore.QThread):
# getglub = "GETMOOD " # getglub = "GETMOOD "
# PchumLog.info("---> recv \"ISON :%s\"" % nicks) # PchumLog.info("---> recv \"ISON :%s\"" % nicks)
# for nick_it in nicklist: # for nick_it in nicklist:
# self.parent.moodUpdated.emit(nick_it, Mood(0)) # self.moodUpdated.emit(nick_it, Mood(0))
# if nick_it in self.parent.mainwindow.namesdb["#pesterchum"]: # if nick_it in self.mainwindow.namesdb["#pesterchum"]:
# getglub += nick_it # getglub += nick_it
# if getglub != "GETMOOD ": # if getglub != "GETMOOD ":
# self.send_irc.msg("#pesterchum", getglub) # self.send_irc.privmsg("#pesterchum", getglub)
def endofnames(self, server, nick, channel, msg): def endofnames(self, server, nick, channel, msg):
try: try:
@ -1181,13 +1039,13 @@ class PesterIRC(QtCore.QThread):
namelist = self.channelnames[channel] namelist = self.channelnames[channel]
pl = PesterList(namelist) pl = PesterList(namelist)
del self.channelnames[channel] del self.channelnames[channel]
self.parent.namesReceived.emit(channel, pl) self.namesReceived.emit(channel, pl)
if channel == "#pesterchum" and ( if channel == "#pesterchum" and (
not hasattr(self, "joined") or not self.joined not hasattr(self, "joined") or not self.joined
): ):
self.joined = True self.joined = True
self.parent.mainwindow.randhandler.setRunning( self.mainwindow.randhandler.setRunning(
self.parent.mainwindow.randhandler.randNick in namelist self.mainwindow.randhandler.randNick in namelist
) )
chums = self.mainwindow.chumList.chums chums = self.mainwindow.chumList.chums
# self.isOn(*chums) # self.isOn(*chums)
@ -1214,37 +1072,37 @@ class PesterIRC(QtCore.QThread):
def listend(self, server, handle, msg): def listend(self, server, handle, msg):
pl = PesterList(self.channel_list) pl = PesterList(self.channel_list)
PchumLog.info('---> recv "CHANNELS END"') PchumLog.info('---> recv "CHANNELS END"')
self.parent.channelListReceived.emit(pl) self.channelListReceived.emit(pl)
self.channel_list = [] self.channel_list = []
def umodeis(self, server, handle, modes): def umodeis(self, server, handle, modes):
self.parent.mainwindow.modes = modes self.mainwindow.modes = modes
def invite(self, sender, you, channel): def invite(self, sender, you, channel):
handle = sender.split("!")[0] handle = sender.split("!")[0]
self.parent.inviteReceived.emit(handle, channel) self.inviteReceived.emit(handle, channel)
def inviteonlychan(self, server, handle, channel, msg): def inviteonlychan(self, server, handle, channel, msg):
self.parent.chanInviteOnly.emit(channel) self.chanInviteOnly.emit(channel)
# channelmodeis can have six arguments. # channelmodeis can have six arguments.
def channelmodeis(self, server, handle, channel, modes, mode_params=""): def channelmodeis(self, server, handle, channel, modes, mode_params=""):
self.parent.modesUpdated.emit(channel, modes) self.modesUpdated.emit(channel, modes)
def cannotsendtochan(self, server, handle, channel, msg): def cannotsendtochan(self, server, handle, channel, msg):
self.parent.cannotSendToChan.emit(channel, msg) self.cannotSendToChan.emit(channel, msg)
def toomanypeeps(self, *stuff): def toomanypeeps(self, *stuff):
self.parent.tooManyPeeps.emit() self.tooManyPeeps.emit()
# def badchanmask(channel, *args): # def badchanmask(channel, *args):
# # Channel name is not valid. # # Channel name is not valid.
# msg = ' '.join(args) # msg = ' '.join(args)
# self.parent.forbiddenchannel.emit(channel, msg) # self.forbiddenchannel.emit(channel, msg)
def forbiddenchannel(self, server, handle, channel, msg): def forbiddenchannel(self, server, handle, channel, msg):
# Channel is forbidden. # Channel is forbidden.
self.parent.forbiddenchannel.emit(channel, msg) self.forbiddenchannel.emit(channel, msg)
self.parent.userPresentUpdate.emit(handle, channel, "left") self.userPresentUpdate.emit(handle, channel, "left")
def ping(self, prefix, token): def ping(self, prefix, token):
"""Respond to server PING with PONG.""" """Respond to server PING with PONG."""

View file

@ -1871,9 +1871,7 @@ class PesterMemo(PesterConvo):
self, "Ban User", "Enter the reason you are banning this user (optional):" self, "Ban User", "Enter the reason you are banning this user (optional):"
) )
if ok: if ok:
self.mainwindow.kickUser.emit( self.mainwindow.kickUser.emit(currentHandle, reason, self.channel)
"{}:{}".format(currentHandle, reason), self.channel
)
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def opSelectedUser(self): def opSelectedUser(self):

View file

@ -4188,7 +4188,7 @@ class PesterWindow(MovingWindow):
trayIconSignal = QtCore.pyqtSignal(int) trayIconSignal = QtCore.pyqtSignal(int)
blockedChum = QtCore.pyqtSignal("QString") blockedChum = QtCore.pyqtSignal("QString")
unblockedChum = QtCore.pyqtSignal("QString") unblockedChum = QtCore.pyqtSignal("QString")
kickUser = QtCore.pyqtSignal("QString", "QString") kickUser = QtCore.pyqtSignal("QString", "QString", "QString")
joinChannel = QtCore.pyqtSignal("QString") joinChannel = QtCore.pyqtSignal("QString")
leftChannel = QtCore.pyqtSignal("QString") leftChannel = QtCore.pyqtSignal("QString")
setChannelMode = QtCore.pyqtSignal("QString", "QString", "QString") setChannelMode = QtCore.pyqtSignal("QString", "QString", "QString")
@ -4381,7 +4381,7 @@ class MainProgram(QtCore.QObject):
("requestChannelList()", "requestChannelList()"), ("requestChannelList()", "requestChannelList()"),
("joinChannel(QString)", "joinChannel(QString)"), ("joinChannel(QString)", "joinChannel(QString)"),
("leftChannel(QString)", "leftChannel(QString)"), ("leftChannel(QString)", "leftChannel(QString)"),
("kickUser(QString, QString)", "kickUser(QString, QString)"), ("kickUser(QString, QString, QString)", "kickUser(QString, QString, QString)"),
( (
"setChannelMode(QString, QString, QString)", "setChannelMode(QString, QString, QString)",
"setChannelMode(QString, QString, QString)", "setChannelMode(QString, QString, QString)",

View file

@ -57,7 +57,7 @@ class SendIRC:
"""Send USER command to communicate username and realname to server.""" """Send USER command to communicate username and realname to server."""
self.send("USER", username, "0", "*", text=realname) self.send("USER", username, "0", "*", text=realname)
def msg(self, target, text): def privmsg(self, target, text):
"""Send PRIVMSG command to send a message.""" """Send PRIVMSG command to send a message."""
for line in text.split("\n"): for line in text.split("\n"):
self.send("PRIVMSG", target, text=line) self.send("PRIVMSG", target, text=line)
@ -73,7 +73,7 @@ class SendIRC:
else: else:
self.send(f"KICK {channel} {user}") self.send(f"KICK {channel} {user}")
def mode(self, target, modestring, mode_arguments=""): def mode(self, target, modestring="", mode_arguments=""):
"""Set or remove modes from target.""" """Set or remove modes from target."""
outgoing_mode = " ".join([target, modestring, mode_arguments]).strip() outgoing_mode = " ".join([target, modestring, mode_arguments]).strip()
self.send("MODE", outgoing_mode) self.send("MODE", outgoing_mode)
@ -83,7 +83,7 @@ class SendIRC:
outgoing_ctcp = " ".join( outgoing_ctcp = " ".join(
[command, msg] [command, msg]
).strip() # Extra spaces break protocol, so strip. ).strip() # Extra spaces break protocol, so strip.
self.msg(target, f"\x01{outgoing_ctcp}\x01") self.privmsg(target, f"\x01{outgoing_ctcp}\x01")
def metadata(self, target, subcommand, *params): def metadata(self, target, subcommand, *params):
"""Send Metadata command to get or set metadata. """Send Metadata command to get or set metadata.
@ -128,3 +128,12 @@ class SendIRC:
self.send("AWAY", text=text) self.send("AWAY", text=text)
else: else:
self.send("AWAY") self.send("AWAY")
def list(self):
"""Send LIST command to get list of channels."""
self.send("LIST")
def quit(self, reason=""):
"""Send QUIT to terminate connection."""
self.send("QUIT", text=reason)