163 class IrcChannelWidget(QWidget, Ui_IrcChannelWidget): |
165 class IrcChannelWidget(QWidget, Ui_IrcChannelWidget): |
164 """ |
166 """ |
165 Class implementing the IRC channel widget. |
167 Class implementing the IRC channel widget. |
166 |
168 |
167 @signal sendData(str) emitted to send a message to the channel |
169 @signal sendData(str) emitted to send a message to the channel |
|
170 @signal sendCtcpReply(str, str) emitted to send a CTCP reply |
168 @signal channelClosed(str) emitted after the user has left the channel |
171 @signal channelClosed(str) emitted after the user has left the channel |
169 @signal openPrivateChat(str) emitted to open a "channel" for private messages |
172 @signal openPrivateChat(str) emitted to open a "channel" for private messages |
170 """ |
173 """ |
171 sendData = pyqtSignal(str) |
174 sendData = pyqtSignal(str) |
|
175 sendCtcpReply = pyqtSignal(str, str) |
172 channelClosed = pyqtSignal(str) |
176 channelClosed = pyqtSignal(str) |
173 openPrivateChat = pyqtSignal(str) |
177 openPrivateChat = pyqtSignal(str) |
174 |
178 |
175 UrlRe = re.compile(r"""((?:http|ftp|https):\/\/[\w\-_]+(?:\.[\w\-_]+)+""" |
179 UrlRe = re.compile(r"""((?:http|ftp|https):\/\/[\w\-_]+(?:\.[\w\-_]+)+""" |
176 r"""(?:[\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)""") |
180 r"""(?:[\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)""") |
443 # group(1) sender user name |
447 # group(1) sender user name |
444 # group(2) sender user@host |
448 # group(2) sender user@host |
445 # group(3) target nick |
449 # group(3) target nick |
446 # group(4) message |
450 # group(4) message |
447 if match.group(3).lower() == self.__name: |
451 if match.group(3).lower() == self.__name: |
|
452 if match.group(4).startswith("\x01"): |
|
453 return self.__handleCtcp(match) |
|
454 |
448 self.addMessage(match.group(1), match.group(4)) |
455 self.addMessage(match.group(1), match.group(4)) |
449 if self.__private and not self.topicLabel.text(): |
456 if self.__private and not self.topicLabel.text(): |
450 self.setPrivateInfo("{0} - {1}".format(match.group(1), match.group(2))) |
457 self.setPrivateInfo("{0} - {1}".format(match.group(1), match.group(2))) |
451 return True |
458 return True |
452 |
459 |
904 @return flag indicating whether the message was handled (boolean) |
911 @return flag indicating whether the message was handled (boolean) |
905 """ |
912 """ |
906 self.__addManagementMessage(self.trUtf8("Help"), |
913 self.__addManagementMessage(self.trUtf8("Help"), |
907 "{0} {1}".format(match.group(1), ircFilter(match.group(2)))) |
914 "{0} {1}".format(match.group(1), ircFilter(match.group(2)))) |
908 return True |
915 return True |
|
916 |
|
917 |
|
918 def __handleCtcp(self, match): |
|
919 """ |
|
920 Private method to handle a CTCP channel command. |
|
921 |
|
922 @param reference to the match object |
|
923 @return flag indicating, if the message was handled (boolean) |
|
924 """ |
|
925 # group(1) sender user name |
|
926 # group(2) sender user@host |
|
927 # group(3) target nick |
|
928 # group(4) message |
|
929 if match.group(4).startswith("\x01"): |
|
930 ctcpCommand = match.group(4)[1:].split("\x01", 1)[0] |
|
931 if " " in ctcpCommand: |
|
932 ctcpRequest, ctcpArg = ctcpCommand.split(" ", 1) |
|
933 else: |
|
934 ctcpRequest, ctcpArg = ctcpCommand, "" |
|
935 ctcpRequest = ctcpRequest.lower() |
|
936 if ctcpRequest == "version": |
|
937 msg = "Eric IRC client {0}, {1}".format(Version, Copyright) |
|
938 self.__addManagementMessage(self.trUtf8("CTCP"), |
|
939 self.trUtf8("Received Version request from {0}.").format( |
|
940 match.group(1))) |
|
941 self.sendCtcpReply.emit(match.group(1), "VERSION " + msg) |
|
942 elif ctcpRequest == "ping": |
|
943 self.__addManagementMessage(self.trUtf8("CTCP"), |
|
944 self.trUtf8("Received CTCP-PING request from {0}," |
|
945 " sending answer.").format(match.group(1))) |
|
946 self.sendCtcpReply.emit(match.group(1), "PING {0}".format(ctcpArg)) |
|
947 elif ctcpRequest == "clientinfo": |
|
948 self.__addManagementMessage(self.trUtf8("CTCP"), |
|
949 self.trUtf8("Received CTCP-CLIENTINFO request from {0}," |
|
950 " sending answer.").format(match.group(1))) |
|
951 self.sendCtcpReply.emit(match.group(1), |
|
952 "CLIENTINFO CLIENTINFO PING VERSION") |
|
953 else: |
|
954 self.__addManagementMessage(self.trUtf8("CTCP"), |
|
955 self.trUtf8("Received unknown CTCP-{0} request from {1}.").format( |
|
956 ctcpRequest, match.group(1))) |
|
957 return True |
|
958 |
|
959 return False |
909 |
960 |
910 def setUserPrivilegePrefix(self, prefixes): |
961 def setUserPrivilegePrefix(self, prefixes): |
911 """ |
962 """ |
912 Public method to set the user privilege to prefix mapping. |
963 Public method to set the user privilege to prefix mapping. |
913 |
964 |