From db9caf210e25aad6321afe8983ac92fd8f16f547 Mon Sep 17 00:00:00 2001 From: Kiooeht Date: Sun, 12 Jan 2014 00:14:16 -0800 Subject: [PATCH] Auto-identify with NickServ --- CHANGELOG.mkdn | 3 ++- irc.py | 1 + menus.py | 32 ++++++++++++++++++++++++++++---- nickservmsgs.py | 19 +++++++++++++++++++ pesterchum.py | 19 +++++++++++++++++++ profile.py | 30 ++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 nickservmsgs.py diff --git a/CHANGELOG.mkdn b/CHANGELOG.mkdn index 4007639..6ba8856 100644 --- a/CHANGELOG.mkdn +++ b/CHANGELOG.mkdn @@ -23,7 +23,8 @@ CHANGELOG * Userlist search - oakwhiz * Chanserv in menus - Cerxi [binaryCabalist] * Lua quirks -* Multi-select memo chooser +* Multi-select memo chooser - [alGore] +* Auto-identify with NickServ - Kiooeht [evacipatedBox] * Bug fixes * Don't require pygame (it's kind of optional, you just don't get sound) - Kiooeht [evacipatedBox] * Allow add chum dialog to open after adding an existing chum - Kiooeht [evacipatedBox] diff --git a/irc.py b/irc.py index 0fe8e26..4cec0a5 100644 --- a/irc.py +++ b/irc.py @@ -176,6 +176,7 @@ class PesterIRC(QtCore.QThread): except socket.error: self.setConnectionBroken() self.mainwindow.closeConversations(True) + self.mainwindow.doAutoIdentify() self.updateMood() @QtCore.pyqtSlot() def updateMood(self): diff --git a/menus.py b/menus.py index f791356..37d3bb7 100644 --- a/menus.py +++ b/menus.py @@ -1001,7 +1001,7 @@ class PesterOptions(QtGui.QDialog): self.tabs = QtGui.QButtonGroup(self) self.connect(self.tabs, QtCore.SIGNAL('buttonClicked(int)'), self, QtCore.SLOT('changePage(int)')) - tabNames = ["Chum List", "Conversations", "Interface", "Sound", "Notifications", "Logging", "Idle/Updates", "Theme"] + tabNames = ["Chum List", "Conversations", "Interface", "Sound", "Notifications", "Logging", "Idle/Updates", "Theme", "Connection"] if parent.advanced: tabNames.append("Advanced") for t in tabNames: button = QtGui.QPushButton(t) @@ -1020,6 +1020,15 @@ class PesterOptions(QtGui.QDialog): font.setPointSize(8) bandwidthLabel.setFont(font) + self.autonickserv = QtGui.QCheckBox("Auto-Identify with NickServ", self) + self.autonickserv.setChecked(parent.userprofile.getAutoIdentify()) + self.connect(self.autonickserv, QtCore.SIGNAL('stateChanged(int)'), + self, QtCore.SLOT('autoNickServChange(int)')) + self.nickservpass = QtGui.QLineEdit(self) + self.nickservpass.setPlaceholderText("NickServ Password") + self.nickservpass.setEchoMode(QtGui.QLineEdit.PasswordEchoOnEdit) + self.nickservpass.setText(parent.userprofile.getNickServPass()) + self.tabcheck = QtGui.QCheckBox("Tabbed Conversations", self) if self.config.tabs(): self.tabcheck.setChecked(True) @@ -1259,8 +1268,6 @@ class PesterOptions(QtGui.QDialog): layout_chumlist.addWidget(self.showemptycheck) layout_chumlist.addWidget(self.showonlinenumbers) layout_chumlist.addLayout(layout_3) - layout_chumlist.addWidget(self.bandwidthcheck) - layout_chumlist.addWidget(bandwidthLabel) self.pages.addWidget(widget) # Conversations @@ -1365,6 +1372,19 @@ class PesterOptions(QtGui.QDialog): layout_theme.addWidget(self.ghostchum) self.pages.addWidget(widget) + # Connection + widget = QtGui.QWidget() + layout_connect = QtGui.QVBoxLayout(widget) + layout_connect.setAlignment(QtCore.Qt.AlignTop) + layout_connect.addWidget(self.bandwidthcheck) + layout_connect.addWidget(bandwidthLabel) + layout_connect.addWidget(self.autonickserv) + layout_indent = QtGui.QVBoxLayout() + layout_indent.addWidget(self.nickservpass) + layout_indent.setContentsMargins(22,0,0,0) + layout_connect.addLayout(layout_indent) + self.pages.addWidget(widget) + # Advanced if parent.advanced: widget = QtGui.QWidget() @@ -1411,6 +1431,10 @@ class PesterOptions(QtGui.QDialog): self.notifyNewConvoCheck.setEnabled(True) self.notifyMentionsCheck.setEnabled(True) + @QtCore.pyqtSlot(int) + def autoNickServChange(self, state): + self.nickservpass.setEnabled(state != 0) + @QtCore.pyqtSlot(int) def soundChange(self, state): if state == 0: @@ -1648,7 +1672,7 @@ class PesterMemoList(QtGui.QDialog): def SelectedMemos(self): return self.channelarea.selectedItems() - + def HasSelection(self): return len(self.SelectedMemos()) > 0 or self.newmemoname() diff --git a/nickservmsgs.py b/nickservmsgs.py new file mode 100644 index 0000000..f03709f --- /dev/null +++ b/nickservmsgs.py @@ -0,0 +1,19 @@ +# Hardcoded messages that NickServ sends and what to display to the user instead + +messages = { + "Your nick isn't registered.": + "", # display the same + "Password accepted - you are now recognized.": + "", # display the same + "If you do not change within one minute, I will change your nick.": + "You have 1 minute to identify.", + "If you do not change within 20 seconds, I will change your nick.": + "You have 20 seconds to identify." +} + +def translate(msg): + if msg in messages: + if messages[msg] == "": + return msg + return messages[msg] + return None diff --git a/pesterchum.py b/pesterchum.py index b9ff0f4..c64cefe 100644 --- a/pesterchum.py +++ b/pesterchum.py @@ -90,6 +90,7 @@ from irc import PesterIRC from logviewer import PesterLogUserSelect, PesterLogViewer from bugreport import BugReporter from randomer import RandomHandler, RANDNICK +import nickservmsgs # Rawr, fuck you OSX leopard if not ostools.isOSXLeopard(): @@ -1709,11 +1710,18 @@ class PesterWindow(MovingWindow): else: self.waitingMessages.answerMessage() + def doAutoIdentify(self): + if self.userprofile.getAutoIdentify(): + self.sendMessage.emit("identify " + self.userprofile.getNickServPass(), "NickServ") + @QtCore.pyqtSlot() def connected(self): if self.loadingscreen: self.loadingscreen.done(QtGui.QDialog.Accepted) self.loadingscreen = None + + self.doAutoIdentify() + @QtCore.pyqtSlot() def blockSelectedChum(self): curChumListing = self.chumList.currentItem() @@ -1806,6 +1814,11 @@ class PesterWindow(MovingWindow): self.randhandler.incoming(msg) elif self.convos.has_key(h): self.newMessage(h, m) + elif h.upper() == "NICKSERV" and "PESTERCHUM:" not in m: + m = nickservmsgs.translate(m) + if m: + t = self.tm.Toast("NickServ:", m) + t.show() @QtCore.pyqtSlot(QtCore.QString, QtCore.QString) def deliverInvite(self, handle, channel): msgbox = QtGui.QMessageBox() @@ -2449,6 +2462,11 @@ class PesterWindow(MovingWindow): self.leftChannel.emit("#pesterchum") else: self.joinChannel.emit("#pesterchum") + # nickserv + autoidentify = self.optionmenu.autonickserv.isChecked() + nickservpass = self.optionmenu.nickservpass.text() + self.userprofile.setAutoIdentify(autoidentify) + self.userprofile.setNickServPass(str(nickservpass)) # advanced ## user mode if self.advanced: @@ -2624,6 +2642,7 @@ class PesterWindow(MovingWindow): @QtCore.pyqtSlot(QtCore.QString) def myHandleChanged(self, handle): if self.profile().handle == handle: + self.doAutoIdentify() return else: self.nickCollision(self.profile().handle, handle) diff --git a/profile.py b/profile.py index a271aae..c266330 100644 --- a/profile.py +++ b/profile.py @@ -395,6 +395,17 @@ class userProfile(object): self.userprofile["mentions"] = [] self.mentions = self.userprofile["mentions"] + with open(_datadir+"passwd.js") as fp: + try: + self.passwd = json.load(fp) + except ValueError, e: + self.passwd = {} + self.autoidentify = False + self.nickservpass = "" + if self.chat.handle in self.passwd: + self.autoidentify = self.passwd[self.chat.handle]["auto"] + self.nickservpass = self.passwd[self.chat.handle]["pw"] + def setMood(self, mood): self.chat.mood = mood def setTheme(self, theme): @@ -435,6 +446,18 @@ class userProfile(object): self.save() def getTheme(self): return self.theme + def getAutoIdentify(self): + return self.autoidentify + def setAutoIdentify(self, b): + self.autoidentify = b + self.passwd[self.chat.handle]["auto"] = b + self.saveNickServPass() + def getNickServPass(self): + return self.nickservpass + def setNickServPass(self, pw): + self.nickservpass = pw + self.passwd[self.chat.handle]["pw"] = pw + self.saveNickServPass() def save(self): handle = self.chat.handle if handle[0:12] == "pesterClient": @@ -447,6 +470,13 @@ class userProfile(object): fp = open("%s/%s.js" % (self.profiledir, handle), 'w') fp.write(jsonoutput) fp.close() + def saveNickServPass(self): + try: + jsonoutput = json.dumps(self.passwd, indent=4) + except ValueError, e: + raise e + with open(_datadir+"passwd.js", 'w') as fp: + fp.write(jsonoutput) @staticmethod def newUserProfile(chatprofile): if os.path.exists("%s/%s.js" % (_datadir+"profiles", chatprofile.handle)):