From eccb7bacdb6528f2a0313022875da7ee8aeb0a30 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 23 Aug 2004 20:17:59 +0000 Subject: [PATCH] Added good error handling in the case that there is no words file. --- plugins/Words.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/Words.py b/plugins/Words.py index 97851aec7..46810bbdc 100644 --- a/plugins/Words.py +++ b/plugins/Words.py @@ -133,6 +133,16 @@ class HangmanGame: 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): """ @@ -219,10 +229,9 @@ class Words(callbacks.Privmsg): game.unused = copy.copy(self.validLetters) try: game.hidden = game.getWord() - except IOError, e: - self.games[channel] = None - irc.error(str(e)) - return + except EnvironmentError, e: + del self.games[channel] + raise game.guess = re.sub('[%s]' % string.ascii_lowercase, '_', game.hidden) self._hangmanReply(irc, channel, @@ -315,7 +324,5 @@ class Words(callbacks.Privmsg): Class = Words -### TODO: Write a script to make the database. - # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: