From df3e1a392488c626245209816a0405c39d8396d5 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Wed, 19 Apr 2017 17:14:58 +0100 Subject: Handle quit messages --- Channel.py | 1 - IrcConnection.py | 3 +++ IrcHandler.py | 11 ++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Channel.py b/Channel.py index 332e175..29810bc 100644 --- a/Channel.py +++ b/Channel.py @@ -43,7 +43,6 @@ class Channel(): def remove_user(self, nick): del(self.users[nick]) - # self.users.remove(user) def get_view(self): return self.view diff --git a/IrcConnection.py b/IrcConnection.py index 45c41c1..1de189f 100644 --- a/IrcConnection.py +++ b/IrcConnection.py @@ -10,6 +10,7 @@ class ircConnectThread(QThread): join_sig = pyqtSignal(str) topic_sig = pyqtSignal(str, str) namreply_sig = pyqtSignal(str, str) + quit_sig = pyqtSignal(str, str) def __init__(self, handler): QThread.__init__(self) self.reactor = irc.client.Reactor() @@ -75,7 +76,9 @@ class ircConnectThread(QThread): print(event) def on_quit(self, connection, event): + nick = event.source.split("!")[0] print(event) + self.quit_sig.emit(nick, event.arguments[0]) def on_kick(self, connection, event): print(event) diff --git a/IrcHandler.py b/IrcHandler.py index 52c9b1c..4fb494d 100644 --- a/IrcHandler.py +++ b/IrcHandler.py @@ -113,7 +113,6 @@ class IrcHandler(QObject): def handle_part(self, channelStr, user): if (channelStr in self.channels): channel = self.channels.get(channelStr) - print(channel.get_users()) user_list = channel.get_view().findChild(QQuickItem, "nick_list") chat_area = channel.get_view().findChild(QQuickItem, "chat_area") if (user != self.get_nick()): @@ -121,6 +120,15 @@ class IrcHandler(QObject): channel.remove_user(user) chat_area.append(user + " left " + channelStr) + def handle_quit(self, nickStr, quit_msg): + for channel_name, channel in self.channels.items(): + if (nickStr in channel.get_users()): + channel.remove_user(nickStr) + user_list = channel.get_view().findChild(QQuickItem, "nick_list") + chat_area = channel.get_view().findChild(QQuickItem, "chat_area") + user_list.remove_nick(nickStr) + chat_area.append(nickStr + " quit (" + quit_msg + ")") + def handle_topic(self, channelStr, topic): if (channelStr in self.channels): channel = self.channels.get(channelStr) @@ -133,6 +141,7 @@ class IrcHandler(QObject): self.irc.namreply_sig.connect(self.handle_nicks) self.irc.nick_sig.connect(self.handle_join) self.irc.part_sig.connect(self.handle_part) + self.irc.quit_sig.connect(self.handle_quit) self.irc.topic_sig.connect(self.handle_topic) # self.irc.join_sig.connect(self.join_channel) self.irc.start() -- cgit v1.2.3