Auto-identify with NickServ

This commit is contained in:
Kiooeht 2014-01-12 00:14:16 -08:00
parent ecade05310
commit db9caf210e
6 changed files with 99 additions and 5 deletions

View file

@ -23,7 +23,8 @@ CHANGELOG
* Userlist search - oakwhiz * Userlist search - oakwhiz
* Chanserv in menus - Cerxi [binaryCabalist] * Chanserv in menus - Cerxi [binaryCabalist]
* Lua quirks * Lua quirks
* Multi-select memo chooser * Multi-select memo chooser - [alGore]
* Auto-identify with NickServ - Kiooeht [evacipatedBox]
* Bug fixes * Bug fixes
* Don't require pygame (it's kind of optional, you just don't get sound) - Kiooeht [evacipatedBox] * 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] * Allow add chum dialog to open after adding an existing chum - Kiooeht [evacipatedBox]

1
irc.py
View file

@ -176,6 +176,7 @@ class PesterIRC(QtCore.QThread):
except socket.error: except socket.error:
self.setConnectionBroken() self.setConnectionBroken()
self.mainwindow.closeConversations(True) self.mainwindow.closeConversations(True)
self.mainwindow.doAutoIdentify()
self.updateMood() self.updateMood()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def updateMood(self): def updateMood(self):

View file

@ -1001,7 +1001,7 @@ class PesterOptions(QtGui.QDialog):
self.tabs = QtGui.QButtonGroup(self) self.tabs = QtGui.QButtonGroup(self)
self.connect(self.tabs, QtCore.SIGNAL('buttonClicked(int)'), self.connect(self.tabs, QtCore.SIGNAL('buttonClicked(int)'),
self, QtCore.SLOT('changePage(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") if parent.advanced: tabNames.append("Advanced")
for t in tabNames: for t in tabNames:
button = QtGui.QPushButton(t) button = QtGui.QPushButton(t)
@ -1020,6 +1020,15 @@ class PesterOptions(QtGui.QDialog):
font.setPointSize(8) font.setPointSize(8)
bandwidthLabel.setFont(font) 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) self.tabcheck = QtGui.QCheckBox("Tabbed Conversations", self)
if self.config.tabs(): if self.config.tabs():
self.tabcheck.setChecked(True) self.tabcheck.setChecked(True)
@ -1259,8 +1268,6 @@ class PesterOptions(QtGui.QDialog):
layout_chumlist.addWidget(self.showemptycheck) layout_chumlist.addWidget(self.showemptycheck)
layout_chumlist.addWidget(self.showonlinenumbers) layout_chumlist.addWidget(self.showonlinenumbers)
layout_chumlist.addLayout(layout_3) layout_chumlist.addLayout(layout_3)
layout_chumlist.addWidget(self.bandwidthcheck)
layout_chumlist.addWidget(bandwidthLabel)
self.pages.addWidget(widget) self.pages.addWidget(widget)
# Conversations # Conversations
@ -1365,6 +1372,19 @@ class PesterOptions(QtGui.QDialog):
layout_theme.addWidget(self.ghostchum) layout_theme.addWidget(self.ghostchum)
self.pages.addWidget(widget) 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 # Advanced
if parent.advanced: if parent.advanced:
widget = QtGui.QWidget() widget = QtGui.QWidget()
@ -1411,6 +1431,10 @@ class PesterOptions(QtGui.QDialog):
self.notifyNewConvoCheck.setEnabled(True) self.notifyNewConvoCheck.setEnabled(True)
self.notifyMentionsCheck.setEnabled(True) self.notifyMentionsCheck.setEnabled(True)
@QtCore.pyqtSlot(int)
def autoNickServChange(self, state):
self.nickservpass.setEnabled(state != 0)
@QtCore.pyqtSlot(int) @QtCore.pyqtSlot(int)
def soundChange(self, state): def soundChange(self, state):
if state == 0: if state == 0:
@ -1648,7 +1672,7 @@ class PesterMemoList(QtGui.QDialog):
def SelectedMemos(self): def SelectedMemos(self):
return self.channelarea.selectedItems() return self.channelarea.selectedItems()
def HasSelection(self): def HasSelection(self):
return len(self.SelectedMemos()) > 0 or self.newmemoname() return len(self.SelectedMemos()) > 0 or self.newmemoname()

19
nickservmsgs.py Normal file
View file

@ -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

View file

@ -90,6 +90,7 @@ from irc import PesterIRC
from logviewer import PesterLogUserSelect, PesterLogViewer from logviewer import PesterLogUserSelect, PesterLogViewer
from bugreport import BugReporter from bugreport import BugReporter
from randomer import RandomHandler, RANDNICK from randomer import RandomHandler, RANDNICK
import nickservmsgs
# Rawr, fuck you OSX leopard # Rawr, fuck you OSX leopard
if not ostools.isOSXLeopard(): if not ostools.isOSXLeopard():
@ -1709,11 +1710,18 @@ class PesterWindow(MovingWindow):
else: else:
self.waitingMessages.answerMessage() self.waitingMessages.answerMessage()
def doAutoIdentify(self):
if self.userprofile.getAutoIdentify():
self.sendMessage.emit("identify " + self.userprofile.getNickServPass(), "NickServ")
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def connected(self): def connected(self):
if self.loadingscreen: if self.loadingscreen:
self.loadingscreen.done(QtGui.QDialog.Accepted) self.loadingscreen.done(QtGui.QDialog.Accepted)
self.loadingscreen = None self.loadingscreen = None
self.doAutoIdentify()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def blockSelectedChum(self): def blockSelectedChum(self):
curChumListing = self.chumList.currentItem() curChumListing = self.chumList.currentItem()
@ -1806,6 +1814,11 @@ class PesterWindow(MovingWindow):
self.randhandler.incoming(msg) self.randhandler.incoming(msg)
elif self.convos.has_key(h): elif self.convos.has_key(h):
self.newMessage(h, m) 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) @QtCore.pyqtSlot(QtCore.QString, QtCore.QString)
def deliverInvite(self, handle, channel): def deliverInvite(self, handle, channel):
msgbox = QtGui.QMessageBox() msgbox = QtGui.QMessageBox()
@ -2449,6 +2462,11 @@ class PesterWindow(MovingWindow):
self.leftChannel.emit("#pesterchum") self.leftChannel.emit("#pesterchum")
else: else:
self.joinChannel.emit("#pesterchum") 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 # advanced
## user mode ## user mode
if self.advanced: if self.advanced:
@ -2624,6 +2642,7 @@ class PesterWindow(MovingWindow):
@QtCore.pyqtSlot(QtCore.QString) @QtCore.pyqtSlot(QtCore.QString)
def myHandleChanged(self, handle): def myHandleChanged(self, handle):
if self.profile().handle == handle: if self.profile().handle == handle:
self.doAutoIdentify()
return return
else: else:
self.nickCollision(self.profile().handle, handle) self.nickCollision(self.profile().handle, handle)

View file

@ -395,6 +395,17 @@ class userProfile(object):
self.userprofile["mentions"] = [] self.userprofile["mentions"] = []
self.mentions = 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): def setMood(self, mood):
self.chat.mood = mood self.chat.mood = mood
def setTheme(self, theme): def setTheme(self, theme):
@ -435,6 +446,18 @@ class userProfile(object):
self.save() self.save()
def getTheme(self): def getTheme(self):
return self.theme 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): def save(self):
handle = self.chat.handle handle = self.chat.handle
if handle[0:12] == "pesterClient": if handle[0:12] == "pesterClient":
@ -447,6 +470,13 @@ class userProfile(object):
fp = open("%s/%s.js" % (self.profiledir, handle), 'w') fp = open("%s/%s.js" % (self.profiledir, handle), 'w')
fp.write(jsonoutput) fp.write(jsonoutput)
fp.close() 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 @staticmethod
def newUserProfile(chatprofile): def newUserProfile(chatprofile):
if os.path.exists("%s/%s.js" % (_datadir+"profiles", chatprofile.handle)): if os.path.exists("%s/%s.js" % (_datadir+"profiles", chatprofile.handle)):