CTCP additions

This commit is contained in:
Dpeta 2022-06-02 23:15:45 +02:00
parent 3051b01bf9
commit 5f6cda821b
3 changed files with 51 additions and 20 deletions

60
irc.py
View file

@ -164,6 +164,16 @@ class PesterIRC(QtCore.QThread):
except socket.error as e: except socket.error as e:
PchumLog.warning(e) PchumLog.warning(e)
self.setConnectionBroken() self.setConnectionBroken()
@QtCore.pyqtSlot(QString, QString,)
def sendCTCP(self, handle, text):
#cmd = text.split(' ')[0]
#msg = text.replace(cmd + ' ', '')
#msg = msg.replace(cmd, '')
try:
helpers.ctcp(self.cli, handle, text)
except socket.error 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):
h = str(handle) h = str(handle)
@ -369,12 +379,6 @@ class PesterIRC(QtCore.QThread):
class PesterHandler(DefaultCommandHandler): class PesterHandler(DefaultCommandHandler):
def notice(self, nick, chan, msg): def notice(self, nick, chan, msg):
#try:
# msg = msg.decode('utf-8')
#except UnicodeDecodeError:
# msg = msg.decode('iso-8859-1', 'ignore')
#nick = nick.decode('utf-8')
#chan = chan.decode('utf-8')
handle = nick[0:nick.find("!")] handle = nick[0:nick.find("!")]
PchumLog.info("---> recv \"NOTICE %s :%s\"" % (handle, msg)) PchumLog.info("---> recv \"NOTICE %s :%s\"" % (handle, msg))
if handle == "ChanServ" and chan == self.parent.mainwindow.profile().handle and msg[0:2] == "[#": if handle == "ChanServ" and chan == self.parent.mainwindow.profile().handle and msg[0:2] == "[#":
@ -382,28 +386,46 @@ class PesterHandler(DefaultCommandHandler):
else: else:
self.parent.noticeReceived.emit(handle, msg) self.parent.noticeReceived.emit(handle, msg)
def privmsg(self, nick, chan, msg): def privmsg(self, nick, chan, msg):
#try: handle = nick[0:nick.find("!")]
# msg = msg.decode('utf-8')
#except UnicodeDecodeError:
# msg = msg.decode('iso-8859-1', 'ignore')
# display msg, do other stuff
if len(msg) == 0: if len(msg) == 0:
return return
# silently ignore CTCP
# Notice IRC /me (The CTCP kind) # CTCP
# ACTION, IRC /me (The CTCP kind)
if msg[0:8] == '\x01ACTION ': if msg[0:8] == '\x01ACTION ':
msg = '/me' + msg[7:-1] msg = '/me' + msg[7:-1]
# silently ignore the rest of the CTCPs # CTCPs that don't need to be shown
if msg[0] == '\x01': elif msg[0] == '\x01':
handle = nick[0:nick.find("!")] PchumLog.info("---> recv \"CTCP %s :%s\"" % (handle, msg[1:-1]))
PchumLog.warning("---> recv \"CTCP %s :%s\"" % (handle, msg[1:-1])) # VERSION, return version
if msg[1:-1] == "VERSION": if msg[1:-1].startswith("VERSION"):
helpers.ctcp_reply(self.parent.cli, handle, "VERSION", "Pesterchum %s" % (_pcVersion)) helpers.ctcp_reply(self.parent.cli, handle, "VERSION", "Pesterchum %s" % (_pcVersion))
# CLIENTINFO, return supported CTCP commands.
elif msg[1:-1].startswith("CLIENTINFO"):
helpers.ctcp_reply(self.parent.cli, handle, "CLIENTINFO",
"ACTION VERSION CLIENTINFO PING SOURCE NOQUIRKS GETMOOD")
# PING, return pong
elif msg[1:-1].startswith("PING"):
if len(msg[1:-1].split("PING ")) > 1:
helpers.ctcp_reply(self.parent.cli, handle, "PING", msg[1:-1].split("PING ")[1])
else:
helpers.ctcp_reply(self.parent.cli, handle, "PING")
# SOURCE, return source
elif msg[1:-1].startswith("SOURCE"):
helpers.ctcp_reply(self.parent.cli, handle, "SOURCE", "https://github.com/Dpeta/pesterchum-alt-servers")
# ???
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.parent.quirkDisable.emit(chan, msg[10:-1], op)
# GETMOOD via CTCP
elif msg[1:-1].startswith("GETMOOD"):
# GETMOOD via CTCP
# Maybe we can do moods like this in the future...
mymood = self.mainwindow.profile().mood.value()
helpers.ctcp_reply(self.parent.cli, handle, "MOOD >%d" % (mymood))
# Backwards compatibility
helpers.msg(self.client, "#pesterchum", "MOOD >%d" % (mymood))
return return
handle = nick[0:nick.find("!")]
if chan != "#pesterchum": if chan != "#pesterchum":
# We don't need anywhere near that much spam. # We don't need anywhere near that much spam.

View file

@ -56,7 +56,12 @@ def mode(cli, channel, mode, options=None):
cli.send(cmd) cli.send(cmd)
def ctcp(cli, handle, cmd, msg=""): def ctcp(cli, handle, cmd, msg=""):
cli.send("PRIVMSG", handle, "\x01%s %s\x01" % (cmd, msg)) # Space breaks protocol if msg is absent
if msg=="":
cli.send("PRIVMSG", handle, "\x01%s\x01" % (cmd))
else:
cli.send("PRIVMSG", handle, "\x01%s %s\x01" % (cmd, msg))
def ctcp_reply(cli, handle, cmd, msg=""): def ctcp_reply(cli, handle, cmd, msg=""):
notice(cli, str(handle), "\x01%s %s\x01" % (cmd.upper(), msg)) notice(cli, str(handle), "\x01%s %s\x01" % (cmd.upper(), msg))

View file

@ -3529,6 +3529,7 @@ class PesterWindow(MovingWindow):
newConvoStarted = QtCore.pyqtSignal('QString', bool, name="newConvoStarted") newConvoStarted = QtCore.pyqtSignal('QString', bool, name="newConvoStarted")
sendMessage = QtCore.pyqtSignal('QString', 'QString') sendMessage = QtCore.pyqtSignal('QString', 'QString')
sendNotice = QtCore.pyqtSignal('QString', 'QString') sendNotice = QtCore.pyqtSignal('QString', 'QString')
sendCTCP = QtCore.pyqtSignal('QString', 'QString')
convoClosed = QtCore.pyqtSignal('QString') convoClosed = QtCore.pyqtSignal('QString')
profileChanged = QtCore.pyqtSignal() profileChanged = QtCore.pyqtSignal()
animationSetting = QtCore.pyqtSignal(bool) animationSetting = QtCore.pyqtSignal(bool)
@ -3694,6 +3695,8 @@ Click this message to never see this again.")
'sendMessage(QString, QString)'), 'sendMessage(QString, QString)'),
('sendNotice(QString, QString)', ('sendNotice(QString, QString)',
'sendNotice(QString, QString)'), 'sendNotice(QString, QString)'),
('sendCTCP(QString, QString)',
'sendCTCP(QString, QString)'),
('newConvoStarted(QString, bool)', ('newConvoStarted(QString, bool)',
'startConvo(QString, bool)'), 'startConvo(QString, bool)'),
('convoClosed(QString)', ('convoClosed(QString)',
@ -3767,6 +3770,7 @@ Click this message to never see this again.")
# IRC --> Main window # IRC --> Main window
return ((widget.sendMessage, irc.sendMessage), return ((widget.sendMessage, irc.sendMessage),
(widget.sendNotice, irc.sendNotice), (widget.sendNotice, irc.sendNotice),
(widget.sendCTCP, irc.sendCTCP),
(widget.newConvoStarted, irc.startConvo), (widget.newConvoStarted, irc.startConvo),
(widget.convoClosed, irc.endConvo), (widget.convoClosed, irc.endConvo),
(widget.profileChanged, irc.updateProfile), (widget.profileChanged, irc.updateProfile),