2022-03-19 19:48:19 -04:00
|
|
|
import logging
|
2011-02-15 12:10:57 -05:00
|
|
|
import socket
|
2022-03-19 19:48:19 -04:00
|
|
|
import random
|
2022-06-04 20:02:53 -04:00
|
|
|
import time
|
2022-06-12 22:03:39 -04:00
|
|
|
import json
|
2022-09-01 23:34:37 -04:00
|
|
|
import ssl
|
2011-02-05 12:17:33 -05:00
|
|
|
|
2022-08-19 07:12:58 -04:00
|
|
|
try:
|
|
|
|
from PyQt6 import QtCore, QtGui
|
|
|
|
except ImportError:
|
|
|
|
print("PyQt5 fallback (irc.py)")
|
|
|
|
from PyQt5 import QtCore, QtGui
|
2022-03-19 19:48:19 -04:00
|
|
|
|
|
|
|
import ostools
|
2011-09-15 03:09:56 -04:00
|
|
|
from mood import Mood
|
|
|
|
from dataobjs import PesterProfile
|
2011-02-05 12:17:33 -05:00
|
|
|
from generic import PesterList
|
2011-05-26 03:40:30 -04:00
|
|
|
from version import _pcVersion
|
2011-02-05 12:17:33 -05:00
|
|
|
|
2022-03-19 19:48:19 -04:00
|
|
|
from oyoyo.client import IRCClient
|
|
|
|
from oyoyo.cmdhandler import DefaultCommandHandler
|
|
|
|
from oyoyo import helpers, services
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog = logging.getLogger("pchumLogger")
|
2022-03-19 19:48:19 -04:00
|
|
|
|
|
|
|
# Python 3
|
|
|
|
QString = str
|
2021-03-23 17:36:43 -04:00
|
|
|
|
2022-06-05 20:05:00 -04:00
|
|
|
# Copied from pesterchum.py
|
2022-10-07 16:51:40 -04:00
|
|
|
# CUSTOMBOTS = ["CALSPRITE", "RANDOMENCOUNTER"]
|
|
|
|
# BOTNAMES = ["NICKSERV", "CHANSERV", "MEMOSERV", "OPERSERV", "HELPSERV", "HOSTSERV", "BOTSERV"]
|
|
|
|
# BOTNAMES.extend(CUSTOMBOTS)
|
2022-06-05 20:05:00 -04:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
# if ostools.isOSXBundle():
|
2021-08-24 11:32:47 -04:00
|
|
|
# logging.basicConfig(level=logging.WARNING)
|
2022-10-07 16:51:40 -04:00
|
|
|
# else:
|
2021-08-24 11:32:47 -04:00
|
|
|
# # karxi; We do NOT need this set to INFO; it's very, very spammy.
|
|
|
|
# logging.basicConfig(level=logging.WARNING)
|
2011-02-05 12:17:33 -05:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-19 18:06:54 -05:00
|
|
|
class PesterIRC(QtCore.QThread):
|
2022-09-01 23:34:37 -04:00
|
|
|
def __init__(self, config, window, verify_hostname=True):
|
2011-02-19 18:06:54 -05:00
|
|
|
QtCore.QThread.__init__(self)
|
2011-02-05 12:17:33 -05:00
|
|
|
self.mainwindow = window
|
2011-02-13 21:01:58 -05:00
|
|
|
self.config = config
|
2022-08-14 14:44:28 -04:00
|
|
|
self.unresponsive = False
|
2011-02-21 14:07:59 -05:00
|
|
|
self.registeredIRC = False
|
2022-09-01 23:34:37 -04:00
|
|
|
self.verify_hostname = verify_hostname
|
2022-06-04 20:02:53 -04:00
|
|
|
self.metadata_supported = False
|
2011-02-21 14:07:59 -05:00
|
|
|
self.stopIRC = None
|
2011-09-28 19:16:01 -04:00
|
|
|
self.NickServ = services.NickServ()
|
|
|
|
self.ChanServ = services.ChanServ()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
def IRCConnect(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
self.cli = IRCClient(
|
|
|
|
PesterHandler,
|
|
|
|
host=self.config.server(),
|
|
|
|
port=self.config.port(),
|
|
|
|
ssl=self.config.ssl(),
|
|
|
|
nick=self.mainwindow.profile().handle,
|
|
|
|
username="pcc31",
|
|
|
|
realname="pcc31",
|
|
|
|
timeout=120,
|
|
|
|
)
|
2011-02-15 12:10:57 -05:00
|
|
|
self.cli.command_handler.parent = self
|
|
|
|
self.cli.command_handler.mainwindow = self.mainwindow
|
2022-09-01 23:34:37 -04:00
|
|
|
try:
|
|
|
|
self.cli.connect(self.verify_hostname)
|
|
|
|
except ssl.SSLCertVerificationError as e:
|
|
|
|
# Ask if users wants to connect anyway
|
|
|
|
self.askToConnect.emit(e)
|
|
|
|
raise e
|
2011-02-21 14:07:59 -05:00
|
|
|
self.conn = self.cli.conn()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-19 18:06:54 -05:00
|
|
|
def run(self):
|
2011-02-21 14:07:59 -05:00
|
|
|
try:
|
|
|
|
self.IRCConnect()
|
2022-06-12 22:03:39 -04:00
|
|
|
except OSError as se:
|
2011-02-21 14:07:59 -05:00
|
|
|
self.stopIRC = se
|
|
|
|
return
|
2022-06-12 22:03:39 -04:00
|
|
|
while True:
|
2011-02-21 14:07:59 -05:00
|
|
|
res = True
|
2011-02-19 18:06:54 -05:00
|
|
|
try:
|
2021-08-10 16:45:48 -04:00
|
|
|
PchumLog.debug("updateIRC()")
|
2022-08-14 14:44:28 -04:00
|
|
|
self.mainwindow.sincerecv = 0
|
2011-02-19 21:38:06 -05:00
|
|
|
res = self.updateIRC()
|
2021-03-23 17:36:43 -04:00
|
|
|
except socket.timeout as se:
|
2021-08-10 16:45:48 -04:00
|
|
|
PchumLog.debug("timeout in thread %s" % (self))
|
2011-02-19 21:38:06 -05:00
|
|
|
self.cli.close()
|
2022-06-12 22:03:39 -04:00
|
|
|
self.stopIRC = "%s, %s" % (type(se), se)
|
2011-02-19 21:38:06 -05:00
|
|
|
return
|
2022-06-16 14:25:24 -04:00
|
|
|
except (OSError, IndexError, ValueError) as se:
|
2022-06-12 22:03:39 -04:00
|
|
|
self.stopIRC = "%s, %s" % (type(se), se)
|
2021-08-10 16:45:48 -04:00
|
|
|
PchumLog.debug("socket error, exiting thread")
|
2011-02-19 18:06:54 -05:00
|
|
|
return
|
2011-02-19 21:38:06 -05:00
|
|
|
else:
|
|
|
|
if not res:
|
2021-08-10 16:45:48 -04:00
|
|
|
PchumLog.debug("false Yield: %s, returning" % res)
|
2011-02-19 21:38:06 -05:00
|
|
|
return
|
2011-04-25 04:04:09 -04:00
|
|
|
|
2011-02-18 03:17:13 -05:00
|
|
|
def setConnected(self):
|
2011-02-18 21:02:54 -05:00
|
|
|
self.registeredIRC = True
|
2011-02-18 03:17:13 -05:00
|
|
|
self.connected.emit()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-19 18:06:54 -05:00
|
|
|
def setConnectionBroken(self):
|
2022-03-18 05:55:01 -04:00
|
|
|
PchumLog.critical("setconnection broken")
|
2022-07-05 15:45:16 -04:00
|
|
|
self.disconnectIRC()
|
2022-10-07 16:51:40 -04:00
|
|
|
# self.brokenConnection = True # Unused
|
|
|
|
|
2011-02-19 18:06:54 -05:00
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def updateIRC(self):
|
|
|
|
try:
|
2021-03-23 17:36:43 -04:00
|
|
|
res = next(self.conn)
|
|
|
|
except socket.timeout as se:
|
2011-02-19 18:06:54 -05:00
|
|
|
if self.registeredIRC:
|
2011-02-19 21:38:06 -05:00
|
|
|
return True
|
2011-02-19 18:06:54 -05:00
|
|
|
else:
|
|
|
|
raise se
|
2022-07-05 15:45:16 -04:00
|
|
|
except OSError as se:
|
2011-02-19 18:06:54 -05:00
|
|
|
raise se
|
2022-10-07 16:51:40 -04:00
|
|
|
except (OSError, ValueError, IndexError) as se:
|
2022-06-12 22:03:39 -04:00
|
|
|
raise se
|
2011-02-19 18:06:54 -05:00
|
|
|
except StopIteration:
|
2011-02-21 14:07:59 -05:00
|
|
|
self.conn = self.cli.conn()
|
2011-02-19 21:38:06 -05:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return res
|
2011-02-19 18:06:54 -05:00
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
@QtCore.pyqtSlot(PesterProfile)
|
|
|
|
def getMood(self, *chums):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
self.cli.command_handler.getMood(*chums)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
@QtCore.pyqtSlot(PesterList)
|
|
|
|
def getMoods(self, chums):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
self.cli.command_handler.getMood(*chums)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString, QString)
|
2011-06-09 03:42:56 -04:00
|
|
|
def sendNotice(self, text, handle):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
h = str(handle)
|
|
|
|
t = str(text)
|
|
|
|
try:
|
|
|
|
helpers.notice(self.cli, h, t)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString, QString)
|
2011-02-05 12:17:33 -05:00
|
|
|
def sendMessage(self, text, handle):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
h = str(handle)
|
|
|
|
textl = [str(text)]
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-09-10 09:27:21 -04:00
|
|
|
def splittext(l):
|
|
|
|
if len(l[0]) > 450:
|
2022-10-07 16:51:40 -04:00
|
|
|
space = l[0].rfind(" ", 0, 430)
|
2022-09-10 09:27:21 -04:00
|
|
|
if space == -1:
|
|
|
|
space = 450
|
2022-10-07 16:51:40 -04:00
|
|
|
elif l[0][space + 1 : space + 5] == "</c>":
|
|
|
|
space = space + 4
|
|
|
|
a = l[0][0 : space + 1]
|
|
|
|
b = l[0][space + 1 :]
|
2022-09-10 09:27:21 -04:00
|
|
|
if a.count("<c") > a.count("</c>"):
|
|
|
|
# oh god ctags will break!! D=
|
|
|
|
hanging = []
|
|
|
|
usedends = []
|
|
|
|
c = a.rfind("<c")
|
|
|
|
while c != -1:
|
|
|
|
d = a.find("</c>", c)
|
|
|
|
while d in usedends:
|
2022-10-07 16:51:40 -04:00
|
|
|
d = a.find("</c>", d + 1)
|
|
|
|
if d != -1:
|
|
|
|
usedends.append(d)
|
2022-09-10 09:27:21 -04:00
|
|
|
else:
|
2022-10-07 16:51:40 -04:00
|
|
|
f = a.find(">", c) + 1
|
2022-09-10 09:27:21 -04:00
|
|
|
hanging.append(a[c:f])
|
2022-10-07 16:51:40 -04:00
|
|
|
c = a.rfind("<c", 0, c)
|
2011-06-09 19:46:36 -04:00
|
|
|
|
2022-09-10 09:27:21 -04:00
|
|
|
# end all ctags in first part
|
2022-10-07 16:51:40 -04:00
|
|
|
for i in range(a.count("<c") - a.count("</c>")):
|
2022-09-10 09:27:21 -04:00
|
|
|
a = a + "</c>"
|
2022-10-07 16:51:40 -04:00
|
|
|
# start them up again in the second part
|
2022-09-10 09:27:21 -04:00
|
|
|
for c in hanging:
|
|
|
|
b = c + b
|
|
|
|
if len(b) > 0:
|
|
|
|
return [a] + splittext([b])
|
|
|
|
else:
|
|
|
|
return [a]
|
2011-02-13 20:32:02 -05:00
|
|
|
else:
|
2022-09-10 09:27:21 -04:00
|
|
|
return l
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-09-10 09:27:21 -04:00
|
|
|
textl = splittext(textl)
|
|
|
|
try:
|
|
|
|
for t in textl:
|
|
|
|
helpers.msg(self.cli, h, t)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
|
|
|
@QtCore.pyqtSlot(
|
|
|
|
QString,
|
|
|
|
QString,
|
|
|
|
)
|
2022-06-02 17:15:45 -04:00
|
|
|
def sendCTCP(self, handle, text):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
try:
|
|
|
|
helpers.ctcp(self.cli, handle, text)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString, bool)
|
2011-02-05 12:17:33 -05:00
|
|
|
def startConvo(self, handle, initiated):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
h = str(handle)
|
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.msg(
|
|
|
|
self.cli, h, "COLOR >%s" % (self.mainwindow.profile().colorcmd())
|
|
|
|
)
|
2022-09-10 09:27:21 -04:00
|
|
|
if initiated:
|
|
|
|
helpers.msg(self.cli, h, "PESTERCHUM:BEGIN")
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString)
|
2011-02-05 12:17:33 -05:00
|
|
|
def endConvo(self, handle):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
h = str(handle)
|
|
|
|
try:
|
|
|
|
helpers.msg(self.cli, h, "PESTERCHUM:CEASE")
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def updateProfile(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
me = self.mainwindow.profile()
|
|
|
|
handle = me.handle
|
|
|
|
try:
|
|
|
|
helpers.nick(self.cli, handle)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
|
|
|
self.mainwindow.closeConversations(True)
|
|
|
|
self.mainwindow.doAutoIdentify()
|
|
|
|
self.mainwindow.autoJoinDone = False
|
|
|
|
self.mainwindow.doAutoJoins()
|
|
|
|
self.updateMood()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def updateMood(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
me = self.mainwindow.profile()
|
|
|
|
# Moods via metadata
|
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.metadata(self.cli, "*", "set", "mood", str(me.mood.value()))
|
2022-09-10 09:27:21 -04:00
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
|
|
|
# Backwards compatibility
|
|
|
|
try:
|
|
|
|
helpers.msg(self.cli, "#pesterchum", "MOOD >%d" % (me.mood.value()))
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def updateColor(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
|
|
|
# PchumLog.debug("irc updateColor (outgoing)")
|
|
|
|
# me = self.mainwindow.profile()
|
2022-09-10 09:27:21 -04:00
|
|
|
# Update color metadata field
|
2011-02-15 12:10:57 -05:00
|
|
|
try:
|
2022-09-10 09:27:21 -04:00
|
|
|
color = self.mainwindow.profile().color
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.metadata(self.cli, "*", "set", "color", str(color.name()))
|
2022-07-05 15:45:16 -04:00
|
|
|
except OSError as e:
|
2022-03-18 05:55:01 -04:00
|
|
|
PchumLog.warning(e)
|
2011-02-15 12:10:57 -05:00
|
|
|
self.setConnectionBroken()
|
2022-09-10 09:27:21 -04:00
|
|
|
# Send color messages
|
|
|
|
for h in list(self.mainwindow.convos.keys()):
|
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.msg(
|
|
|
|
self.cli,
|
|
|
|
h,
|
|
|
|
"COLOR >%s" % (self.mainwindow.profile().colorcmd()),
|
|
|
|
)
|
2022-09-10 09:27:21 -04:00
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString)
|
2011-02-05 12:17:33 -05:00
|
|
|
def blockedChum(self, handle):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
h = str(handle)
|
|
|
|
try:
|
|
|
|
helpers.msg(self.cli, h, "PESTERCHUM:BLOCK")
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString)
|
2011-02-05 12:17:33 -05:00
|
|
|
def unblockedChum(self, handle):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
h = str(handle)
|
|
|
|
try:
|
|
|
|
helpers.msg(self.cli, h, "PESTERCHUM:UNBLOCK")
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString)
|
2011-02-05 12:17:33 -05:00
|
|
|
def requestNames(self, channel):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
c = str(channel)
|
|
|
|
try:
|
|
|
|
helpers.names(self.cli, c)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def requestChannelList(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
try:
|
|
|
|
helpers.channel_list(self.cli)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString)
|
2011-02-05 12:17:33 -05:00
|
|
|
def joinChannel(self, channel):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
c = str(channel)
|
|
|
|
try:
|
|
|
|
helpers.join(self.cli, c)
|
|
|
|
helpers.mode(self.cli, c, "", None)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString)
|
2011-02-05 12:17:33 -05:00
|
|
|
def leftChannel(self, channel):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
c = str(channel)
|
|
|
|
try:
|
|
|
|
helpers.part(self.cli, c)
|
|
|
|
self.cli.command_handler.joined = False
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString, QString)
|
2011-02-06 01:02:39 -05:00
|
|
|
def kickUser(self, handle, channel):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
l = handle.split(":")
|
|
|
|
c = str(channel)
|
|
|
|
h = str(l[0])
|
|
|
|
if len(l) > 1:
|
|
|
|
reason = str(l[1])
|
|
|
|
if len(l) > 2:
|
2022-10-07 16:51:40 -04:00
|
|
|
for x in l[2:]:
|
|
|
|
reason += str(":") + str(x)
|
2022-09-10 09:27:21 -04:00
|
|
|
else:
|
|
|
|
reason = ""
|
|
|
|
try:
|
|
|
|
helpers.kick(self.cli, h, c, reason)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString, QString, QString)
|
2011-02-06 19:50:21 -05:00
|
|
|
def setChannelMode(self, channel, mode, command):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
c = str(channel)
|
|
|
|
m = str(mode)
|
|
|
|
cmd = str(command)
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog.debug("c=%s\nm=%s\ncmd=%s" % (c, m, cmd))
|
2022-09-10 09:27:21 -04:00
|
|
|
if cmd == "":
|
|
|
|
cmd = None
|
|
|
|
try:
|
|
|
|
helpers.mode(self.cli, c, m, cmd)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString)
|
2011-05-12 02:36:03 -04:00
|
|
|
def channelNames(self, channel):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
c = str(channel)
|
|
|
|
try:
|
|
|
|
helpers.names(self.cli, c)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString, QString)
|
2011-05-19 09:49:21 -04:00
|
|
|
def inviteChum(self, handle, channel):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
h = str(handle)
|
|
|
|
c = str(channel)
|
|
|
|
try:
|
|
|
|
helpers.invite(self.cli, h, c)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2011-02-05 12:17:33 -05:00
|
|
|
|
2011-06-23 12:02:20 -04:00
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def pingServer(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
self.cli.send("PING :B33")
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2011-06-23 12:02:20 -04:00
|
|
|
|
2011-06-28 19:26:13 -04:00
|
|
|
@QtCore.pyqtSlot(bool)
|
|
|
|
def setAway(self, away=True):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
try:
|
|
|
|
if away:
|
|
|
|
self.cli.send("AWAY Idle")
|
|
|
|
else:
|
|
|
|
self.cli.send("AWAY")
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2011-06-28 19:26:13 -04:00
|
|
|
|
2021-03-23 17:36:43 -04:00
|
|
|
@QtCore.pyqtSlot(QString, QString)
|
2011-06-29 13:19:22 -04:00
|
|
|
def killSomeQuirks(self, channel, handle):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-09-10 09:27:21 -04:00
|
|
|
c = str(channel)
|
|
|
|
h = str(handle)
|
|
|
|
try:
|
|
|
|
helpers.ctcp(self.cli, c, "NOQUIRKS", h)
|
|
|
|
except OSError as e:
|
|
|
|
PchumLog.warning(e)
|
|
|
|
self.setConnectionBroken()
|
2022-07-05 15:45:16 -04:00
|
|
|
|
|
|
|
@QtCore.pyqtSlot()
|
|
|
|
def disconnectIRC(self):
|
2022-10-07 16:51:40 -04:00
|
|
|
if hasattr(self, "cli"):
|
2022-07-05 15:45:16 -04:00
|
|
|
helpers.quit(self.cli, _pcVersion + " <3")
|
|
|
|
self.cli._end = True
|
|
|
|
self.cli.close()
|
2011-06-29 13:19:22 -04:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
moodUpdated = QtCore.pyqtSignal("QString", Mood)
|
|
|
|
colorUpdated = QtCore.pyqtSignal("QString", QtGui.QColor)
|
|
|
|
messageReceived = QtCore.pyqtSignal("QString", "QString")
|
|
|
|
memoReceived = QtCore.pyqtSignal("QString", "QString", "QString")
|
|
|
|
noticeReceived = QtCore.pyqtSignal("QString", "QString")
|
|
|
|
inviteReceived = QtCore.pyqtSignal("QString", "QString")
|
|
|
|
timeCommand = QtCore.pyqtSignal("QString", "QString", "QString")
|
|
|
|
namesReceived = QtCore.pyqtSignal("QString", PesterList)
|
2011-02-05 12:17:33 -05:00
|
|
|
channelListReceived = QtCore.pyqtSignal(PesterList)
|
2022-10-07 16:51:40 -04:00
|
|
|
nickCollision = QtCore.pyqtSignal("QString", "QString")
|
|
|
|
getSvsnickedOn = QtCore.pyqtSignal("QString", "QString")
|
|
|
|
myHandleChanged = QtCore.pyqtSignal("QString")
|
|
|
|
chanInviteOnly = QtCore.pyqtSignal("QString")
|
|
|
|
modesUpdated = QtCore.pyqtSignal("QString", "QString")
|
2011-02-05 12:17:33 -05:00
|
|
|
connected = QtCore.pyqtSignal()
|
2022-09-01 23:34:37 -04:00
|
|
|
askToConnect = QtCore.pyqtSignal(Exception)
|
2022-10-07 16:51:40 -04:00
|
|
|
userPresentUpdate = QtCore.pyqtSignal("QString", "QString", "QString")
|
|
|
|
cannotSendToChan = QtCore.pyqtSignal("QString", "QString")
|
2011-06-20 19:18:47 -04:00
|
|
|
tooManyPeeps = QtCore.pyqtSignal()
|
2022-10-07 16:51:40 -04:00
|
|
|
quirkDisable = QtCore.pyqtSignal("QString", "QString", "QString")
|
|
|
|
forbiddenchannel = QtCore.pyqtSignal("QString", "QString")
|
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
class PesterHandler(DefaultCommandHandler):
|
2011-05-09 20:19:44 -04:00
|
|
|
def notice(self, nick, chan, msg):
|
2022-10-07 16:51:40 -04:00
|
|
|
handle = nick[0 : nick.find("!")]
|
|
|
|
PchumLog.info('---> recv "NOTICE %s :%s"' % (handle, msg))
|
|
|
|
if (
|
|
|
|
handle == "ChanServ"
|
|
|
|
and chan == self.parent.mainwindow.profile().handle
|
|
|
|
and msg[0:2] == "[#"
|
|
|
|
):
|
|
|
|
self.parent.memoReceived.emit(msg[1 : msg.index("]")], handle, msg)
|
2011-05-09 20:19:44 -04:00
|
|
|
else:
|
|
|
|
self.parent.noticeReceived.emit(handle, msg)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-06-04 19:08:38 -04:00
|
|
|
def metadata(self, target, nick, key, visibility, value):
|
|
|
|
# The format of the METADATA server notication is:
|
|
|
|
# METADATA <Target> <Key> <Visibility> <Value>
|
2022-09-01 20:05:46 -04:00
|
|
|
if key.lower() == "mood":
|
|
|
|
try:
|
|
|
|
mood = Mood(int(value))
|
|
|
|
self.parent.moodUpdated.emit(nick, mood)
|
|
|
|
except ValueError:
|
|
|
|
PchumLog.warning("Invalid mood value, %s, %s" % (nick, mood))
|
|
|
|
elif key.lower() == "color":
|
2022-10-07 16:51:40 -04:00
|
|
|
color = QtGui.QColor(value) # Invalid color becomes rgb 0,0,0
|
2022-09-01 20:05:46 -04:00
|
|
|
self.parent.colorUpdated.emit(nick, color)
|
2022-06-05 20:05:00 -04:00
|
|
|
|
|
|
|
def tagmsg(self, prefix, tags, *args):
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog.info("TAGMSG: %s %s %s" % (prefix, tags, str(args)))
|
|
|
|
message_tags = tags[1:].split(";")
|
2022-06-05 20:05:00 -04:00
|
|
|
for m in message_tags:
|
|
|
|
if m.startswith("+pesterchum"):
|
|
|
|
# Pesterchum tag
|
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
key, value = m.split("=")
|
2022-06-05 20:05:00 -04:00
|
|
|
except ValueError:
|
|
|
|
return
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog.info("Pesterchum tag: %s=%s" % (key, value))
|
2022-06-06 15:10:31 -04:00
|
|
|
# PESTERCHUM: syntax check
|
2022-10-07 16:51:40 -04:00
|
|
|
if (
|
|
|
|
(value == "BEGIN")
|
2022-06-06 15:10:31 -04:00
|
|
|
or (value == "BLOCK")
|
2022-06-07 18:19:56 -04:00
|
|
|
or (value == "CEASE")
|
|
|
|
or (value == "BLOCK")
|
|
|
|
or (value == "BLOCKED")
|
|
|
|
or (value == "UNBLOCK")
|
|
|
|
or (value == "IDLE")
|
2022-10-07 16:51:40 -04:00
|
|
|
or (value == "ME")
|
|
|
|
):
|
2022-06-06 15:10:31 -04:00
|
|
|
# Process like it's a PESTERCHUM: PRIVMSG
|
|
|
|
msg = "PESTERCHUM:" + value
|
|
|
|
self.privmsg(prefix, args[0], msg)
|
|
|
|
elif value.startswith("COLOR>"):
|
|
|
|
# Process like it's a COLOR >0,0,0 PRIVMSG
|
2022-10-07 16:51:40 -04:00
|
|
|
msg = value.replace(">", " >")
|
2022-06-06 15:10:31 -04:00
|
|
|
self.privmsg(prefix, args[0], msg)
|
|
|
|
elif value.startswith("TIME>"):
|
|
|
|
# Process like it's a PESTERCHUM:TIME> PRIVMSG
|
|
|
|
msg = "PESTERCHUM:" + value
|
|
|
|
self.privmsg(prefix, args[0], msg)
|
|
|
|
else:
|
2022-06-05 20:05:00 -04:00
|
|
|
# Invalid syntax
|
|
|
|
PchumLog.warning("TAGMSG with invalid syntax.")
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-06-12 22:03:39 -04:00
|
|
|
def error(self, *params):
|
|
|
|
# Server is ending connection.
|
2022-10-07 16:51:40 -04:00
|
|
|
reason = ""
|
2022-06-12 22:03:39 -04:00
|
|
|
for x in params:
|
2022-10-07 16:51:40 -04:00
|
|
|
if (x != None) and (x != ""):
|
|
|
|
reason += x + " "
|
2022-06-12 22:03:39 -04:00
|
|
|
self.parent.stopIRC = reason.strip()
|
2022-07-05 15:45:16 -04:00
|
|
|
self.parent.disconnectIRC()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-05 12:17:33 -05:00
|
|
|
def privmsg(self, nick, chan, msg):
|
2022-10-07 16:51:40 -04:00
|
|
|
handle = nick[0 : nick.find("!")]
|
2011-02-07 13:40:05 -05:00
|
|
|
if len(msg) == 0:
|
|
|
|
return
|
2022-06-02 17:15:45 -04:00
|
|
|
|
|
|
|
# CTCP
|
|
|
|
# ACTION, IRC /me (The CTCP kind)
|
2022-10-07 16:51:40 -04:00
|
|
|
if msg[0:8] == "\x01ACTION ":
|
|
|
|
msg = "/me" + msg[7:-1]
|
2022-06-02 17:15:45 -04:00
|
|
|
# CTCPs that don't need to be shown
|
2022-10-07 16:51:40 -04:00
|
|
|
elif msg[0] == "\x01":
|
|
|
|
PchumLog.info('---> recv "CTCP %s :%s"' % (handle, msg[1:-1]))
|
2022-06-02 17:15:45 -04:00
|
|
|
# VERSION, return version
|
|
|
|
if msg[1:-1].startswith("VERSION"):
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.ctcp_reply(
|
|
|
|
self.parent.cli, handle, "VERSION", "Pesterchum %s" % (_pcVersion)
|
|
|
|
)
|
|
|
|
# CLIENTINFO, return supported CTCP commands.
|
2022-06-02 17:15:45 -04:00
|
|
|
elif msg[1:-1].startswith("CLIENTINFO"):
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.ctcp_reply(
|
|
|
|
self.parent.cli,
|
|
|
|
handle,
|
|
|
|
"CLIENTINFO",
|
|
|
|
"ACTION VERSION CLIENTINFO PING SOURCE NOQUIRKS GETMOOD",
|
|
|
|
)
|
2022-06-02 17:15:45 -04:00
|
|
|
# PING, return pong
|
|
|
|
elif msg[1:-1].startswith("PING"):
|
|
|
|
if len(msg[1:-1].split("PING ")) > 1:
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.ctcp_reply(
|
|
|
|
self.parent.cli, handle, "PING", msg[1:-1].split("PING ")[1]
|
|
|
|
)
|
2022-06-02 17:15:45 -04:00
|
|
|
else:
|
|
|
|
helpers.ctcp_reply(self.parent.cli, handle, "PING")
|
|
|
|
# SOURCE, return source
|
|
|
|
elif msg[1:-1].startswith("SOURCE"):
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.ctcp_reply(
|
|
|
|
self.parent.cli,
|
|
|
|
handle,
|
|
|
|
"SOURCE",
|
|
|
|
"https://github.com/Dpeta/pesterchum-alt-servers",
|
|
|
|
)
|
2022-06-02 17:15:45 -04:00
|
|
|
# ???
|
2011-06-29 13:19:22 -04:00
|
|
|
elif msg[1:-1].startswith("NOQUIRKS") and chan[0] == "#":
|
2022-10-07 16:51:40 -04:00
|
|
|
op = nick[0 : nick.find("!")]
|
2011-06-29 13:19:22 -04:00
|
|
|
self.parent.quirkDisable.emit(chan, msg[10:-1], op)
|
2022-06-02 17:15:45 -04:00
|
|
|
# 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))
|
2011-02-05 12:17:33 -05:00
|
|
|
return
|
2016-12-11 04:01:48 -05:00
|
|
|
|
2016-12-10 20:55:42 -05:00
|
|
|
if chan != "#pesterchum":
|
|
|
|
# We don't need anywhere near that much spam.
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog.info('---> recv "PRIVMSG %s :%s"' % (handle, msg))
|
2016-12-11 04:01:48 -05:00
|
|
|
|
|
|
|
if chan == "#pesterchum":
|
2011-02-05 12:17:33 -05:00
|
|
|
# follow instructions
|
|
|
|
if msg[0:6] == "MOOD >":
|
|
|
|
try:
|
|
|
|
mood = Mood(int(msg[6:]))
|
|
|
|
except ValueError:
|
|
|
|
mood = Mood(0)
|
|
|
|
self.parent.moodUpdated.emit(handle, mood)
|
|
|
|
elif msg[0:7] == "GETMOOD":
|
|
|
|
mychumhandle = self.mainwindow.profile().handle
|
|
|
|
mymood = self.mainwindow.profile().mood.value()
|
|
|
|
if msg.find(mychumhandle, 8) != -1:
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.msg(self.client, "#pesterchum", "MOOD >%d" % (mymood))
|
|
|
|
elif chan[0] == "#":
|
2011-02-05 12:17:33 -05:00
|
|
|
if msg[0:16] == "PESTERCHUM:TIME>":
|
|
|
|
self.parent.timeCommand.emit(chan, handle, msg[16:])
|
|
|
|
else:
|
|
|
|
self.parent.memoReceived.emit(chan, handle, msg)
|
|
|
|
else:
|
|
|
|
# private message
|
|
|
|
# silently ignore messages to yourself.
|
|
|
|
if handle == self.mainwindow.profile().handle:
|
|
|
|
return
|
|
|
|
if msg[0:7] == "COLOR >":
|
|
|
|
colors = msg[7:].split(",")
|
|
|
|
try:
|
|
|
|
colors = [int(d) for d in colors]
|
2021-04-16 09:37:38 -04:00
|
|
|
except ValueError as e:
|
2021-08-10 16:45:48 -04:00
|
|
|
PchumLog.warning(e)
|
2022-10-07 16:51:40 -04:00
|
|
|
colors = [0, 0, 0]
|
2021-08-10 16:45:48 -04:00
|
|
|
PchumLog.debug("colors: " + str(colors))
|
2011-02-05 12:17:33 -05:00
|
|
|
color = QtGui.QColor(*colors)
|
|
|
|
self.parent.colorUpdated.emit(handle, color)
|
|
|
|
else:
|
|
|
|
self.parent.messageReceived.emit(handle, msg)
|
2011-02-15 12:10:57 -05:00
|
|
|
|
2022-08-14 14:44:28 -04:00
|
|
|
def pong(self, *args):
|
|
|
|
# source, server, token
|
2022-10-07 16:51:40 -04:00
|
|
|
# print("PONG", source, server, token)
|
|
|
|
# self.parent.mainwindow.lastrecv = time.time()
|
|
|
|
# print("PONG TIME: %s" % self.parent.mainwindow.lastpong)
|
2022-08-14 14:44:28 -04:00
|
|
|
pass
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
def welcome(self, server, nick, msg):
|
2011-02-18 03:17:13 -05:00
|
|
|
self.parent.setConnected()
|
2022-10-07 16:51:40 -04:00
|
|
|
# mychumhandle = self.mainwindow.profile().handle
|
2011-02-15 12:10:57 -05:00
|
|
|
mymood = self.mainwindow.profile().mood.value()
|
2022-09-01 20:05:46 -04:00
|
|
|
color = self.mainwindow.profile().color
|
2011-09-13 00:03:05 -04:00
|
|
|
if not self.mainwindow.config.lowBandwidth():
|
2022-09-01 20:05:46 -04:00
|
|
|
# Negotiate capabilities
|
|
|
|
helpers.cap(self.client, "REQ", "message-tags")
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.cap(
|
|
|
|
self.client, "REQ", "draft/metadata-notify-2"
|
|
|
|
) # <--- Not required in the unreal5 module implementation
|
|
|
|
helpers.cap(
|
|
|
|
self.client, "REQ", "pesterchum-tag"
|
|
|
|
) # <--- Currently not using this
|
|
|
|
time.sleep(0.413 + 0.097) # <--- somehow, this actually helps.
|
2011-09-13 00:03:05 -04:00
|
|
|
helpers.join(self.client, "#pesterchum")
|
2022-06-04 19:08:38 -04:00
|
|
|
# Moods via metadata
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.metadata(self.client, "*", "sub", "mood")
|
|
|
|
helpers.metadata(self.client, "*", "set", "mood", str(mymood))
|
2022-09-01 20:05:46 -04:00
|
|
|
# Color via metadata
|
2022-10-07 16:51:40 -04:00
|
|
|
helpers.metadata(self.client, "*", "sub", "color")
|
|
|
|
helpers.metadata(self.client, "*", "set", "color", str(color.name()))
|
2022-06-04 19:08:38 -04:00
|
|
|
# Backwards compatible moods
|
2011-09-13 00:03:05 -04:00
|
|
|
helpers.msg(self.client, "#pesterchum", "MOOD >%d" % (mymood))
|
2022-06-05 20:05:00 -04:00
|
|
|
|
2022-06-12 22:03:39 -04:00
|
|
|
def erroneusnickname(self, *args):
|
|
|
|
# Server is not allowing us to connect.
|
|
|
|
reason = "Handle is not allowed on this server.\n"
|
|
|
|
for x in args:
|
2022-10-07 16:51:40 -04:00
|
|
|
if (x != None) and (x != ""):
|
|
|
|
reason += x + " "
|
2022-06-12 22:03:39 -04:00
|
|
|
self.parent.stopIRC = reason.strip()
|
2022-07-05 15:45:16 -04:00
|
|
|
self.parent.disconnectIRC()
|
2022-06-12 22:03:39 -04:00
|
|
|
|
2022-06-04 19:08:38 -04:00
|
|
|
def keyvalue(self, target, handle_us, handle_owner, key, visibility, *value):
|
|
|
|
# The format of the METADATA server notication is:
|
|
|
|
# METADATA <Target> <Key> <Visibility> <Value>
|
|
|
|
if key == "mood":
|
|
|
|
mood = Mood(int(value[0]))
|
|
|
|
self.parent.moodUpdated.emit(handle_owner, mood)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-06-04 19:08:38 -04:00
|
|
|
def metadatasubok(self, *params):
|
|
|
|
PchumLog.info("metadatasubok: " + str(params))
|
|
|
|
|
|
|
|
def nomatchingkey(self, target, our_handle, failed_handle, key, *error):
|
|
|
|
# Try to get moods the old way if metadata fails.
|
|
|
|
PchumLog.info("nomatchingkey: " + failed_handle)
|
|
|
|
chumglub = "GETMOOD "
|
|
|
|
try:
|
|
|
|
helpers.msg(self.client, "#pesterchum", chumglub + failed_handle)
|
2022-07-05 15:45:16 -04:00
|
|
|
except OSError as e:
|
2022-06-06 17:03:12 -04:00
|
|
|
PchumLog.warning(e)
|
|
|
|
self.parent.setConnectionBroken()
|
|
|
|
|
|
|
|
def keynotset(self, target, our_handle, failed_handle, key, *error):
|
|
|
|
# Try to get moods the old way if metadata fails.
|
|
|
|
PchumLog.info("nomatchingkey: " + failed_handle)
|
|
|
|
chumglub = "GETMOOD "
|
|
|
|
try:
|
|
|
|
helpers.msg(self.client, "#pesterchum", chumglub + failed_handle)
|
2022-07-05 15:45:16 -04:00
|
|
|
except OSError as e:
|
2022-06-06 17:03:12 -04:00
|
|
|
PchumLog.warning(e)
|
|
|
|
self.parent.setConnectionBroken()
|
|
|
|
|
|
|
|
def keynopermission(self, target, our_handle, failed_handle, key, *error):
|
|
|
|
# Try to get moods the old way if metadata fails.
|
|
|
|
PchumLog.info("nomatchingkey: " + failed_handle)
|
|
|
|
chumglub = "GETMOOD "
|
|
|
|
try:
|
|
|
|
helpers.msg(self.client, "#pesterchum", chumglub + failed_handle)
|
2022-07-05 15:45:16 -04:00
|
|
|
except OSError as e:
|
2022-06-04 19:08:38 -04:00
|
|
|
PchumLog.warning(e)
|
|
|
|
self.parent.setConnectionBroken()
|
2022-06-04 19:28:00 -04:00
|
|
|
|
|
|
|
def featurelist(self, target, handle, *params):
|
2022-07-05 15:45:16 -04:00
|
|
|
# Better to do this via CAP ACK/CAP NEK
|
2022-06-04 19:28:00 -04:00
|
|
|
# RPL_ISUPPORT
|
|
|
|
features = params[:-1]
|
|
|
|
PchumLog.info("Server featurelist: " + str(features))
|
2022-06-04 20:02:53 -04:00
|
|
|
for x in features:
|
|
|
|
if x.upper().startswith("METADATA"):
|
|
|
|
PchumLog.info("Server supports metadata.")
|
|
|
|
self.parent.metadata_supported = True
|
2022-07-05 15:45:16 -04:00
|
|
|
|
|
|
|
def cap(self, server, nick, subcommand, tag):
|
|
|
|
PchumLog.info("CAP %s %s %s %s" % (server, nick, subcommand, tag))
|
2022-10-07 16:51:40 -04:00
|
|
|
# if tag == "message-tags":
|
2022-07-05 15:45:16 -04:00
|
|
|
# if subcommand == "ACK":
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
def nicknameinuse(self, server, cmd, nick, msg):
|
2022-10-07 16:51:40 -04:00
|
|
|
newnick = "pesterClient%d" % (random.randint(100, 999))
|
2011-02-15 12:10:57 -05:00
|
|
|
helpers.nick(self.client, newnick)
|
2011-02-05 12:17:33 -05:00
|
|
|
self.parent.nickCollision.emit(nick, newnick)
|
2022-07-05 15:45:16 -04:00
|
|
|
|
|
|
|
def nickcollision(self, server, cmd, nick, msg):
|
2022-10-07 16:51:40 -04:00
|
|
|
newnick = "pesterClient%d" % (random.randint(100, 999))
|
2022-07-05 15:45:16 -04:00
|
|
|
helpers.nick(self.client, newnick)
|
|
|
|
self.parent.nickCollision.emit(nick, newnick)
|
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
def quit(self, nick, reason):
|
2022-10-07 16:51:40 -04:00
|
|
|
handle = nick[0 : nick.find("!")]
|
|
|
|
PchumLog.info('---> recv "QUIT %s: %s"' % (handle, reason))
|
2011-08-29 04:56:44 -04:00
|
|
|
if handle == self.parent.mainwindow.randhandler.randNick:
|
|
|
|
self.parent.mainwindow.randhandler.setRunning(False)
|
2011-07-17 04:58:19 -04:00
|
|
|
server = self.parent.mainwindow.config.server()
|
2022-10-07 16:51:40 -04:00
|
|
|
baseserver = server[server.rfind(".", 0, server.rfind(".")) :]
|
2011-07-17 04:58:19 -04:00
|
|
|
if reason.count(baseserver) == 2:
|
|
|
|
self.parent.userPresentUpdate.emit(handle, "", "netsplit")
|
|
|
|
else:
|
|
|
|
self.parent.userPresentUpdate.emit(handle, "", "quit")
|
2011-02-06 01:02:39 -05:00
|
|
|
self.parent.moodUpdated.emit(handle, Mood("offline"))
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-06-13 16:37:07 -04:00
|
|
|
def kick(self, opnick, channel, handle, reason):
|
2022-10-07 16:51:40 -04:00
|
|
|
op = opnick[0 : opnick.find("!")]
|
2011-06-13 16:37:07 -04:00
|
|
|
self.parent.userPresentUpdate.emit(handle, channel, "kick:%s:%s" % (op, reason))
|
2011-02-06 01:02:39 -05:00
|
|
|
# ok i shouldnt be overloading that but am lazy
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
def part(self, nick, channel, reason="nanchos"):
|
2022-10-07 16:51:40 -04:00
|
|
|
handle = nick[0 : nick.find("!")]
|
|
|
|
PchumLog.info('---> recv "PART %s: %s"' % (handle, channel))
|
2011-02-05 12:17:33 -05:00
|
|
|
self.parent.userPresentUpdate.emit(handle, channel, "left")
|
|
|
|
if channel == "#pesterchum":
|
|
|
|
self.parent.moodUpdated.emit(handle, Mood("offline"))
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
def join(self, nick, channel):
|
2022-10-07 16:51:40 -04:00
|
|
|
handle = nick[0 : nick.find("!")]
|
|
|
|
PchumLog.info('---> recv "JOIN %s: %s"' % (handle, channel))
|
2011-02-05 12:17:33 -05:00
|
|
|
self.parent.userPresentUpdate.emit(handle, channel, "join")
|
|
|
|
if channel == "#pesterchum":
|
2011-08-29 04:56:44 -04:00
|
|
|
if handle == self.parent.mainwindow.randhandler.randNick:
|
|
|
|
self.parent.mainwindow.randhandler.setRunning(True)
|
2011-02-05 12:17:33 -05:00
|
|
|
self.parent.moodUpdated.emit(handle, Mood("chummy"))
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-05-25 01:51:51 -04:00
|
|
|
def mode(self, op, channel, mode, *handles):
|
2021-08-24 09:49:50 -04:00
|
|
|
PchumLog.debug("op=" + str(op))
|
|
|
|
PchumLog.debug("channel=" + str(channel))
|
|
|
|
PchumLog.debug("mode=" + str(mode))
|
|
|
|
PchumLog.debug("*handles=" + str(handles))
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
if len(handles) <= 0:
|
|
|
|
handles = [""]
|
|
|
|
opnick = op[0 : op.find("!")]
|
2021-08-24 09:49:50 -04:00
|
|
|
PchumLog.debug("opnick=" + opnick)
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
# if op == channel or channel == self.parent.mainwindow.profile().handle:
|
2021-08-24 09:49:50 -04:00
|
|
|
# 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
|
2021-08-24 11:32:47 -04:00
|
|
|
# No clue how stable this is but since it doesn't seem to cause a crash it's probably an improvement.
|
2021-08-24 09:49:50 -04:00
|
|
|
# This might be clunky with non-unrealircd IRC servers
|
|
|
|
channel_mode = ""
|
2022-10-07 16:51:40 -04:00
|
|
|
unrealircd_channel_modes = [
|
|
|
|
"c",
|
|
|
|
"C",
|
|
|
|
"d",
|
|
|
|
"f",
|
|
|
|
"G",
|
|
|
|
"H",
|
|
|
|
"i",
|
|
|
|
"k",
|
|
|
|
"K",
|
|
|
|
"L",
|
|
|
|
"l",
|
|
|
|
"m",
|
|
|
|
"M",
|
|
|
|
"N",
|
|
|
|
"n",
|
|
|
|
"O",
|
|
|
|
"P",
|
|
|
|
"p",
|
|
|
|
"Q",
|
|
|
|
"R",
|
|
|
|
"r",
|
|
|
|
"s",
|
|
|
|
"S",
|
|
|
|
"T",
|
|
|
|
"t",
|
|
|
|
"V",
|
|
|
|
"z",
|
|
|
|
"Z",
|
|
|
|
]
|
2021-08-24 09:49:50 -04:00
|
|
|
if any(md in mode for md in unrealircd_channel_modes):
|
|
|
|
PchumLog.debug("Channel mode in string.")
|
2011-05-12 02:28:07 -04:00
|
|
|
modes = list(self.parent.mainwindow.modes)
|
2021-08-24 09:49:50 -04:00
|
|
|
for md in unrealircd_channel_modes:
|
2022-10-07 16:51:40 -04:00
|
|
|
if mode.find(md) != -1: # -1 means not found
|
2021-08-24 09:49:50 -04:00
|
|
|
PchumLog.debug("md=" + md)
|
|
|
|
if mode[0] == "+":
|
|
|
|
modes.extend(md)
|
2022-10-07 16:51:40 -04:00
|
|
|
channel_mode = "+" + md
|
2021-08-24 09:49:50 -04:00
|
|
|
elif mode[0] == "-":
|
|
|
|
try:
|
|
|
|
modes.remove(md)
|
|
|
|
channel_mode = "-" + md
|
|
|
|
except ValueError:
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog.warning(
|
|
|
|
"Can't remove channel mode that isn't set."
|
|
|
|
)
|
2021-08-24 09:49:50 -04:00
|
|
|
pass
|
2022-10-07 16:51:40 -04:00
|
|
|
self.parent.userPresentUpdate.emit(
|
|
|
|
"", channel, channel_mode + ":%s" % (op)
|
|
|
|
)
|
2021-08-24 09:49:50 -04:00
|
|
|
PchumLog.debug("pre-mode=" + str(mode))
|
|
|
|
mode = mode.replace(md, "")
|
|
|
|
PchumLog.debug("post-mode=" + str(mode))
|
2011-05-12 02:28:07 -04:00
|
|
|
modes.sort()
|
|
|
|
self.parent.mainwindow.modes = "+" + "".join(modes)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-05-25 01:51:51 -04:00
|
|
|
modes = []
|
|
|
|
cur = "+"
|
|
|
|
for l in mode:
|
2022-10-07 16:51:40 -04:00
|
|
|
if l in ["+", "-"]:
|
|
|
|
cur = l
|
2011-05-25 01:51:51 -04:00
|
|
|
else:
|
|
|
|
modes.append("%s%s" % (cur, l))
|
2021-08-24 09:49:50 -04:00
|
|
|
PchumLog.debug("handles=" + str(handles))
|
|
|
|
PchumLog.debug("enumerate(modes) = " + str(list(enumerate(modes))))
|
2022-10-07 16:51:40 -04:00
|
|
|
for (i, m) in enumerate(modes):
|
2021-08-24 09:49:50 -04:00
|
|
|
|
|
|
|
# Server-set usermodes don't need to be passed.
|
2022-10-07 16:51:40 -04:00
|
|
|
if (handles == [""]) & (
|
|
|
|
("x" in m) | ("z" in m) | ("o" in m) | ("x" in m)
|
|
|
|
) != True:
|
2022-03-17 00:36:14 -04:00
|
|
|
try:
|
2022-10-07 16:51:40 -04:00
|
|
|
self.parent.userPresentUpdate.emit(
|
|
|
|
handles[i], channel, m + ":%s" % (op)
|
|
|
|
)
|
2022-03-17 00:36:14 -04:00
|
|
|
except IndexError as e:
|
|
|
|
PchumLog.exception("modeSetIndexError: %s" % e)
|
2022-10-07 16:51:40 -04:00
|
|
|
# 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))
|
2021-08-24 09:49:50 -04:00
|
|
|
# Passing an empty handle here might cause a crash.
|
2022-10-07 16:51:40 -04:00
|
|
|
# except IndexError:
|
|
|
|
# self.parent.userPresentUpdate.emit("", channel, m+":%s" % (op))
|
|
|
|
|
2022-07-05 15:45:16 -04:00
|
|
|
def nick(self, oldnick, newnick, hopcount=0):
|
2022-08-17 05:24:50 -04:00
|
|
|
PchumLog.info("%s, %s" % (oldnick, newnick))
|
|
|
|
# svsnick
|
2022-07-05 15:45:16 -04:00
|
|
|
if oldnick == self.mainwindow.profile().handle:
|
|
|
|
# Server changed our handle, svsnick?
|
|
|
|
self.parent.getSvsnickedOn.emit(oldnick, newnick)
|
|
|
|
|
2022-08-17 05:24:50 -04:00
|
|
|
# etc.
|
2022-10-07 16:51:40 -04:00
|
|
|
oldhandle = oldnick[0 : oldnick.find("!")]
|
|
|
|
if (oldhandle == self.mainwindow.profile().handle) or (
|
|
|
|
newnick == self.mainwindow.profile().handle
|
|
|
|
):
|
|
|
|
# print('hewwo')
|
2011-03-06 22:02:47 -05:00
|
|
|
self.parent.myHandleChanged.emit(newnick)
|
2011-02-05 12:17:33 -05:00
|
|
|
newchum = PesterProfile(newnick, chumdb=self.mainwindow.chumdb)
|
2011-02-15 12:10:57 -05:00
|
|
|
self.parent.moodUpdated.emit(oldhandle, Mood("offline"))
|
|
|
|
self.parent.userPresentUpdate.emit("%s:%s" % (oldhandle, newnick), "", "nick")
|
2011-02-05 12:17:33 -05:00
|
|
|
if newnick in self.mainwindow.chumList.chums:
|
|
|
|
self.getMood(newchum)
|
2011-08-29 04:56:44 -04:00
|
|
|
if oldhandle == self.parent.mainwindow.randhandler.randNick:
|
2022-10-07 16:51:40 -04:00
|
|
|
self.parent.mainwindow.randhandler.setRunning(False)
|
2011-08-29 04:56:44 -04:00
|
|
|
elif newnick == self.parent.mainwindow.randhandler.randNick:
|
2022-10-07 16:51:40 -04:00
|
|
|
self.parent.mainwindow.randhandler.setRunning(True)
|
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
def namreply(self, server, nick, op, channel, names):
|
|
|
|
namelist = names.split(" ")
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog.info('---> recv "NAMES %s: %d names"' % (channel, len(namelist)))
|
|
|
|
if not hasattr(self, "channelnames"):
|
2011-02-15 12:10:57 -05:00
|
|
|
self.channelnames = {}
|
2011-06-09 05:23:11 -04:00
|
|
|
if channel not in self.channelnames:
|
2011-02-15 12:10:57 -05:00
|
|
|
self.channelnames[channel] = []
|
|
|
|
self.channelnames[channel].extend(namelist)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
|
|
|
# def ison(self, server, nick, nicks):
|
2021-02-23 10:21:57 -05:00
|
|
|
# nicklist = nicks.split(" ")
|
|
|
|
# getglub = "GETMOOD "
|
2021-08-10 16:45:48 -04:00
|
|
|
# PchumLog.info("---> recv \"ISON :%s\"" % nicks)
|
2021-02-23 10:21:57 -05:00
|
|
|
# for nick_it in nicklist:
|
|
|
|
# self.parent.moodUpdated.emit(nick_it, Mood(0))
|
|
|
|
# if nick_it in self.parent.mainwindow.namesdb["#pesterchum"]:
|
|
|
|
# getglub += nick_it
|
|
|
|
# if getglub != "GETMOOD ":
|
|
|
|
# helpers.msg(self.client, "#pesterchum", getglub)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
def endofnames(self, server, nick, channel, msg):
|
2022-08-17 05:24:50 -04:00
|
|
|
try:
|
|
|
|
namelist = self.channelnames[channel]
|
|
|
|
except KeyError:
|
|
|
|
# EON seems to return with wrong capitalization sometimes?
|
|
|
|
for cn in self.channelnames.keys():
|
|
|
|
if channel.lower() == cn.lower():
|
|
|
|
channel = cn
|
|
|
|
namelist = self.channelnames[channel]
|
2011-02-15 12:10:57 -05:00
|
|
|
pl = PesterList(namelist)
|
|
|
|
del self.channelnames[channel]
|
|
|
|
self.parent.namesReceived.emit(channel, pl)
|
2022-10-07 16:51:40 -04:00
|
|
|
if channel == "#pesterchum" and (
|
|
|
|
not hasattr(self, "joined") or not self.joined
|
|
|
|
):
|
2011-06-13 11:13:56 -04:00
|
|
|
self.joined = True
|
2022-10-07 16:51:40 -04:00
|
|
|
self.parent.mainwindow.randhandler.setRunning(
|
|
|
|
self.parent.mainwindow.randhandler.randNick in namelist
|
|
|
|
)
|
2011-06-09 05:23:11 -04:00
|
|
|
chums = self.mainwindow.chumList.chums
|
2022-10-07 16:51:40 -04:00
|
|
|
# self.isOn(*chums)
|
2021-02-23 10:21:57 -05:00
|
|
|
lesschums = []
|
|
|
|
for c in chums:
|
|
|
|
chandle = c.handle
|
|
|
|
if chandle in namelist:
|
|
|
|
lesschums.append(c)
|
|
|
|
self.getMood(*lesschums)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
def liststart(self, server, handle, *info):
|
|
|
|
self.channel_list = []
|
2016-11-13 01:12:58 -05:00
|
|
|
info = list(info)
|
2022-10-07 16:51:40 -04:00
|
|
|
self.channel_field = info.index("Channel") # dunno if this is protocol
|
|
|
|
PchumLog.info('---> recv "CHANNELS: %s ' % (self.channel_field))
|
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
def list(self, server, handle, *info):
|
|
|
|
channel = info[self.channel_field]
|
2011-03-31 17:57:30 -04:00
|
|
|
usercount = info[1]
|
2011-02-15 12:10:57 -05:00
|
|
|
if channel not in self.channel_list and channel != "#pesterchum":
|
2011-03-31 17:57:30 -04:00
|
|
|
self.channel_list.append((channel, usercount))
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog.info('---> recv "CHANNELS: %s ' % (channel))
|
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
def listend(self, server, handle, msg):
|
|
|
|
pl = PesterList(self.channel_list)
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog.info('---> recv "CHANNELS END"')
|
2011-02-15 12:10:57 -05:00
|
|
|
self.parent.channelListReceived.emit(pl)
|
|
|
|
self.channel_list = []
|
2011-04-25 04:04:09 -04:00
|
|
|
|
2011-05-12 02:46:53 -04:00
|
|
|
def umodeis(self, server, handle, modes):
|
|
|
|
self.parent.mainwindow.modes = modes
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-05-19 09:49:21 -04:00
|
|
|
def invite(self, sender, you, channel):
|
2022-10-07 16:51:40 -04:00
|
|
|
handle = sender.split("!")[0]
|
2011-05-19 09:49:21 -04:00
|
|
|
self.parent.inviteReceived.emit(handle, channel)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-05-19 09:49:21 -04:00
|
|
|
def inviteonlychan(self, server, handle, channel, msg):
|
|
|
|
self.parent.chanInviteOnly.emit(channel)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2022-06-30 03:59:34 -04:00
|
|
|
# channelmodeis can have six arguments.
|
2022-03-17 00:41:42 -04:00
|
|
|
def channelmodeis(self, server, handle, channel, modes, mode_params=""):
|
2011-05-20 14:45:41 -04:00
|
|
|
self.parent.modesUpdated.emit(channel, modes)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-05-27 01:58:58 -04:00
|
|
|
def cannotsendtochan(self, server, handle, channel, msg):
|
|
|
|
self.parent.cannotSendToChan.emit(channel, msg)
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-06-20 19:18:47 -04:00
|
|
|
def toomanypeeps(self, *stuff):
|
|
|
|
self.parent.tooManyPeeps.emit()
|
2022-10-07 16:51:40 -04:00
|
|
|
|
|
|
|
# def badchanmask(channel, *args):
|
2022-06-30 04:15:06 -04:00
|
|
|
# # Channel name is not valid.
|
|
|
|
# msg = ' '.join(args)
|
|
|
|
# self.parent.forbiddenchannel.emit(channel, msg)
|
2022-06-30 03:59:34 -04:00
|
|
|
def forbiddenchannel(self, server, handle, channel, msg):
|
|
|
|
# Channel is forbidden.
|
|
|
|
self.parent.forbiddenchannel.emit(channel, msg)
|
|
|
|
self.parent.userPresentUpdate.emit(handle, channel, "left")
|
2022-10-07 16:51:40 -04:00
|
|
|
|
2011-06-23 12:02:20 -04:00
|
|
|
def ping(self, prefix, server):
|
2022-10-07 16:51:40 -04:00
|
|
|
# self.parent.mainwindow.lastping = time.time()
|
|
|
|
self.client.send("PONG", server)
|
2011-06-23 12:02:20 -04:00
|
|
|
|
2011-02-15 12:10:57 -05:00
|
|
|
def getMood(self, *chums):
|
2022-07-05 15:45:16 -04:00
|
|
|
"""Get mood via metadata if supported"""
|
|
|
|
|
2022-06-04 20:02:53 -04:00
|
|
|
# Get via metadata or via legacy method
|
|
|
|
if self.parent.metadata_supported == True:
|
|
|
|
# Metadata
|
|
|
|
for c in chums:
|
|
|
|
chandle = c.handle
|
|
|
|
try:
|
|
|
|
helpers.metadata(self.client, chandle, "get", "mood")
|
2022-07-05 15:45:16 -04:00
|
|
|
except OSError as e:
|
2022-06-04 20:02:53 -04:00
|
|
|
PchumLog.warning(e)
|
|
|
|
self.parent.setConnectionBroken()
|
|
|
|
else:
|
|
|
|
# Legacy
|
2022-10-07 16:51:40 -04:00
|
|
|
PchumLog.warning(
|
|
|
|
"Server doesn't seem to support metadata, using legacy GETMOOD."
|
|
|
|
)
|
2022-06-04 20:02:53 -04:00
|
|
|
chumglub = "GETMOOD "
|
|
|
|
for c in chums:
|
|
|
|
chandle = c.handle
|
2022-10-07 16:51:40 -04:00
|
|
|
if len(chumglub + chandle) >= 350:
|
2022-06-04 20:02:53 -04:00
|
|
|
try:
|
|
|
|
helpers.msg(self.client, "#pesterchum", chumglub)
|
2022-07-05 15:45:16 -04:00
|
|
|
except OSError as e:
|
2022-06-04 20:02:53 -04:00
|
|
|
PchumLog.warning(e)
|
|
|
|
self.parent.setConnectionBroken()
|
|
|
|
chumglub = "GETMOOD "
|
|
|
|
chumglub += chandle
|
|
|
|
if chumglub != "GETMOOD ":
|
|
|
|
try:
|
|
|
|
helpers.msg(self.client, "#pesterchum", chumglub)
|
2022-07-05 15:45:16 -04:00
|
|
|
except OSError as e:
|
2022-06-04 20:02:53 -04:00
|
|
|
PchumLog.warning(e)
|
|
|
|
self.parent.setConnectionBroken()
|
2011-04-25 04:04:09 -04:00
|
|
|
|
2022-10-07 16:51:40 -04:00
|
|
|
# def isOn(self, *chums):
|
2021-02-23 10:21:57 -05:00
|
|
|
# isonNicks = ""
|
|
|
|
# for c in chums:
|
|
|
|
# chandle = c.handle
|
|
|
|
# if len(chandle) >= 200:
|
|
|
|
# try:
|
|
|
|
# self.client.send("ISON", ":%s" % (isonNicks))
|
2022-07-05 15:45:16 -04:00
|
|
|
# except OSError:
|
2021-02-23 10:21:57 -05:00
|
|
|
# self.parent.setConnectionBroken()
|
|
|
|
# isonNicks = ""
|
|
|
|
# isonNicks += " " + chandle
|
|
|
|
# if isonNicks != "":
|
|
|
|
# try:
|
|
|
|
# self.client.send("ISON", ":%s" % (isonNicks))
|
2022-07-05 15:45:16 -04:00
|
|
|
# except OSError:
|
2021-02-23 10:21:57 -05:00
|
|
|
# self.parent.setConnectionBroken()
|