Added good error handling in the case that there is no words file.

This commit is contained in:
Jeremy Fincher 2004-08-23 20:17:59 +00:00
parent 25b21895d9
commit eccb7bacdb

View File

@ -133,6 +133,16 @@ class HangmanGame:
class Words(callbacks.Privmsg): class Words(callbacks.Privmsg):
def callCommand(self, command, irc, msg, args):
# We'll catch the IOError here.
try:
callbacks.Privmsg.callCommand(self, command, irc, msg, args)
except EnvironmentError, e:
irc.error('I couldn\'t open the words file. This plugin expects '
'a words file (i.e., a file with one word per line, in '
'sorted order) to be at %s. Contact the owner of this '
'bot to remedy this situation.' %
self.registryValue('file'))
def crossword(self, irc, msg, args): def crossword(self, irc, msg, args):
"""<word> """<word>
@ -219,10 +229,9 @@ class Words(callbacks.Privmsg):
game.unused = copy.copy(self.validLetters) game.unused = copy.copy(self.validLetters)
try: try:
game.hidden = game.getWord() game.hidden = game.getWord()
except IOError, e: except EnvironmentError, e:
self.games[channel] = None del self.games[channel]
irc.error(str(e)) raise
return
game.guess = re.sub('[%s]' % string.ascii_lowercase, '_', game.guess = re.sub('[%s]' % string.ascii_lowercase, '_',
game.hidden) game.hidden)
self._hangmanReply(irc, channel, self._hangmanReply(irc, channel,
@ -315,7 +324,5 @@ class Words(callbacks.Privmsg):
Class = Words Class = Words
### TODO: Write a script to make the database.
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: