From 5422ca830c2d5f2845c837cccf00a42f4e310fa6 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Wed, 19 Apr 2017 12:25:54 +0100 Subject: Improve user handling, fixes crash bug on /parts --- IrcHandler.py | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'IrcHandler.py') diff --git a/IrcHandler.py b/IrcHandler.py index ff2053b..7e0618c 100644 --- a/IrcHandler.py +++ b/IrcHandler.py @@ -3,6 +3,8 @@ from PyQt5.QtQuick import QQuickView, QQuickItem, QQuickWindow import IrcConnection import Channel +import User + class IrcHandler(QObject): sig = pyqtSignal(str,str) join_sig = pyqtSignal(str) @@ -62,7 +64,7 @@ class IrcHandler(QObject): self.join_channel(channel) else: self.sig.emit(current_channel, text) - self.window.update_chat(current_channel, text) + self.window.update_chat(current_channel, self.nick + ": " + text) self.window.reset_input(current_channel) @@ -70,39 +72,53 @@ class IrcHandler(QObject): def handle_msg(self, channelStr, nick, msg): if channelStr in self.channels: channel = self.channels[channelStr] - chat_area = channel.get_view().findChild(QQuickItem, "chat_area") - chat_area.append(nick + ": " + msg) + self.window.update_chat(channelStr , nick + ": " + msg) @pyqtSlot(str, str) - def handle_nicks(self, channelStr, users): - userlist = users.split(" ")[0:-1] + def handle_nicks(self, channelStr, nicks): + nick_listStr = nicks.split(" ")[0:-1] if (channelStr in self.channels): channel = self.channels.get(channelStr) - channel.set_users(userlist) - user_list = channel.get_view().findChild(QQuickItem, "nick_list") - for user in userlist: - user_list.add_nick(user) - def handle_join(self, channelStr, user): + user_list = channel.get_view().findChild(QQuickItem, "nick_list") + for nickStr in nick_listStr: + if (nickStr[0] in ["@", "+", "~", "%"]): + mode = nickStr[0] + nickStr = nickStr[1:] + else: + mode = "" + user = User.User(nickStr, mode) + channel.add_user(user) + user_list.add_nick(nickStr, mode) + + def handle_join(self, channelStr, nickStr): if (channelStr in self.channels): channel = self.channels.get(channelStr) - channel.add_user(user) + user_list = channel.get_view().findChild(QQuickItem, "nick_list") chat_area = channel.get_view().findChild(QQuickItem, "chat_area") - if (user != self.get_nick()): - user_list.add_nick(user) - chat_area.append(user + " joined " + channelStr) + if (nickStr != self.get_nick()): + if (nickStr[0] in ["@", "+", "~", "%"]): + mode = nickStr[0] + nickStr = nickStr[1:] + else: + mode = "" + user = User.User(nickStr, mode) + channel.add_user(user) + user_list.add_nick(nickStr, mode) + chat_area.append(nickStr + " joined " + channelStr) def handle_part(self, channelStr, user): if (channelStr in self.channels): channel = self.channels.get(channelStr) - channel.remove_user(user) + 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()): user_list.remove_nick(user) + channel.remove_user(user) chat_area.append(user + " left " + channelStr) def connect_to_irc(self, view): -- cgit v1.2.3