from PyQt5.QtCore import QUrl, QThread, pyqtSignal, QObject, pyqtSlot, Qt import irc.client class ircConnectThread(QThread): sig = pyqtSignal(str) nick_sig = pyqtSignal(str, str) join_sig = pyqtSignal(str) def __init__(self): QThread.__init__(self) self.reactor = irc.client.Reactor() self.server = self.reactor.server() def __del__(self): self.wait() def run(self): try: self.c = self.server.connect("irc.blatech.net", 6667, "wtest") except irc.client.ServerConnectionError: print(sys.exc_info()[1]) raise SystemExit(1) # self.sig.connect(IrcWindow.updateTextArea) print("start") self.c.add_global_handler("welcome", self.on_connect) self.c.add_global_handler("pubmsg", self.on_pubmsg) self.c.add_global_handler("privmsg", self.on_privmsg) self.c.add_global_handler("join", self.on_join) self.c.add_global_handler("namreply", self.on_names) self.reactor.process_forever() def on_connect(self, connection, event): if irc.client.is_channel("#wtest"): connection.join("#wtest") return def on_pubmsg(self, connection, event): self.sig.emit(event.source + ": " + event.arguments[0]) def on_privmsg(self, connection, event): self.sig.emit(event.source + ": " + event.arguments[0]) def on_join(self, connection, event): print(event) nick = event.source.split("!")[0] self.nick_sig.emit(event.target, event.source.split("!")[0]) self.sig.emit(event.source + " joined " + event.target) def on_names(self, connection, event): print(event) for nick in event.arguments[2].split(" "): if (nick.strip() != ""): self.nick_sig.emit(event.arguments[1], nick) @pyqtSlot(str, str) def send_msg(self, channel, message): if (message.startswith("/join")): self.handle_join(message) else: self.server.privmsg(channel, message) print(message) def handle_join(self, message): print(message) self.c.join(message.split(" ")[1]) self.join_sig.emit(message.split(" ")[1])