mirror of https://github.com/Mikaela/Limnoria.git
Fixed a bug
This commit is contained in:
parent
18c49c9a56
commit
20984842f3
|
@ -180,7 +180,7 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||
raise callbacks.ArgumentError
|
||||
for word in args:
|
||||
if word.translate(string.ascii, string.ascii_letters):
|
||||
irc.error(msg, 'Word must contain only letters.')
|
||||
irc.error('Word must contain only letters.')
|
||||
return
|
||||
else:
|
||||
addWord(self.dbHandler.getDb(), word, commit=True)
|
||||
|
@ -196,16 +196,16 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||
db = self.dbHandler.getDb()
|
||||
cursor = db.cursor()
|
||||
if '%' in word:
|
||||
irc.error(msg, '"%" isn\'t allowed in the word.')
|
||||
irc.error('"%" isn\'t allowed in the word.')
|
||||
return
|
||||
cursor.execute("""SELECT word FROM words
|
||||
WHERE word LIKE %s
|
||||
ORDER BY word""", word)
|
||||
words = [t[0] for t in cursor.fetchall()]
|
||||
if words:
|
||||
irc.reply(msg, utils.commaAndify(words))
|
||||
irc.reply(utils.commaAndify(words))
|
||||
else:
|
||||
irc.reply(msg, 'No matching words were found.')
|
||||
irc.reply('No matching words were found.')
|
||||
|
||||
def anagram(self, irc, msg, args):
|
||||
"""<word>
|
||||
|
@ -220,16 +220,16 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||
sorted = ''.join(L)
|
||||
cursor.execute("""SELECT id FROM sorted_words WHERE word=%s""", sorted)
|
||||
if cursor.rowcount == 0:
|
||||
irc.reply(msg, 'That word has no anagrams I could find.')
|
||||
irc.reply('That word has no anagrams I could find.')
|
||||
else:
|
||||
id = cursor.fetchone()[0]
|
||||
cursor.execute("""SELECT words.word FROM words
|
||||
WHERE sorted_word_id=%s""", id)
|
||||
if cursor.rowcount > 1:
|
||||
words = [t[0] for t in cursor.fetchall()]
|
||||
irc.reply(msg, utils.commaAndify(words))
|
||||
irc.reply(utils.commaAndify(words))
|
||||
else:
|
||||
irc.reply(msg, 'That word has no anagrams I could find.')
|
||||
irc.reply('That word has no anagrams I could find.')
|
||||
|
||||
###
|
||||
# HANGMAN
|
||||
|
@ -253,11 +253,12 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||
Returns unused letters
|
||||
"""
|
||||
channel = msg.args[0]
|
||||
game = self.games[channel]
|
||||
if not game.gameOn:
|
||||
irc.error(msg, 'There is no hangman game going on right now.')
|
||||
return
|
||||
irc.reply(msg, '%s %s' % (game.prefix, ' '.join(game.unused)))
|
||||
if channel in self.games:
|
||||
game = self.games[channel]
|
||||
if game.gameOn:
|
||||
irc.reply('%s %s' % (game.prefix, ' '.join(game.unused)))
|
||||
return
|
||||
irc.error('There is no hangman game going on right now.')
|
||||
|
||||
def hangman(self, irc, msg, args):
|
||||
"""takes no arguments
|
||||
|
@ -280,7 +281,7 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||
game.unused = copy.copy(self.validLetters)
|
||||
game.hidden = game.getWord(self.dbHandler)
|
||||
game.guess = '_' * len(game.hidden)
|
||||
irc.reply(msg, '%sOkay ladies and gentlemen, you have '
|
||||
irc.reply('%sOkay ladies and gentlemen, you have '
|
||||
'a %s-letter word to find, you have %s!' %
|
||||
(game.prefix, len(game.hidden),
|
||||
game.triesLeft(game.tries)), prefixName=False)
|
||||
|
@ -292,7 +293,7 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||
self.endGame(channel)
|
||||
self.hangman(irc, msg, args)
|
||||
else:
|
||||
irc.error(msg, 'Sorry, there is already a game going on. '
|
||||
irc.error('Sorry, there is already a game going on. '
|
||||
'%s left before timeout.' % utils.nItems('second',
|
||||
int(game.timeout - secondsEllapsed)))
|
||||
|
||||
|
@ -303,9 +304,13 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||
the whole word and you are wrong, you automatically lose.
|
||||
"""
|
||||
channel = msg.args[0]
|
||||
game = self.games[channel]
|
||||
try:
|
||||
game = self.games[channel]
|
||||
except KeyError:
|
||||
irc.error('There is no hangman game going on right now.')
|
||||
return
|
||||
if not game.gameOn:
|
||||
irc.error(msg, 'There is no hangman game going on right now.')
|
||||
irc.error('There is no hangman game going on right now.')
|
||||
return
|
||||
letter = privmsgs.getArgs(args)
|
||||
game.timeGuess = time.time()
|
||||
|
@ -313,21 +318,21 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||
if letter in game.unused:
|
||||
del game.unused[game.unused.index(letter)]
|
||||
if letter in game.hidden:
|
||||
irc.reply(msg, '%sYes, there is %s %s' % (game.prefix,
|
||||
irc.reply('%sYes, there is %s %s' % (game.prefix,
|
||||
game.letterArticle(letter), `letter`), prefixName=False)
|
||||
game.guess = game.addLetter(letter, game.guess,
|
||||
game.letterPositions(letter, game.hidden))
|
||||
if game.guess == game.hidden:
|
||||
game.guessed = True
|
||||
else:
|
||||
irc.reply(msg,'%sNo, there is no %s' % (game.prefix,`letter`),
|
||||
irc.reply('%sNo, there is no %s' % (game.prefix,`letter`),
|
||||
prefixName=False)
|
||||
game.tries -= 1
|
||||
irc.reply(msg, '%s%s (%s left)' % (game.prefix, game.guess,
|
||||
irc.reply('%s%s (%s left)' % (game.prefix, game.guess,
|
||||
game.triesLeft(game.tries)), prefixName=False)
|
||||
# User input a valid character that has already been tried
|
||||
elif letter in self.validLetters:
|
||||
irc.error(msg, 'That letter has already been tried.')
|
||||
irc.error('That letter has already been tried.')
|
||||
# User tries to guess the whole word or entered an invalid input
|
||||
else:
|
||||
# The length of the word tried by the user and that of the hidden
|
||||
|
@ -337,23 +342,23 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||
if letter == game.hidden:
|
||||
game.guessed = True
|
||||
else:
|
||||
irc.reply(msg, '%syou did not guess the correct word '
|
||||
irc.reply('%syou did not guess the correct word '
|
||||
'and you lose a try' % game.prefix, prefixName=False)
|
||||
game.tries -= 1
|
||||
else:
|
||||
# User input an invalid character
|
||||
if len(letter) == 1:
|
||||
irc.error(msg, 'That is not a valid character.')
|
||||
irc.error('That is not a valid character.')
|
||||
# User input an invalid word (len(try) != len(hidden))
|
||||
else:
|
||||
irc.error(msg, 'That is not a valid word guess.')
|
||||
irc.error('That is not a valid word guess.')
|
||||
# Verify if the user won or lost
|
||||
if game.guessed and game.tries > 0:
|
||||
irc.reply(msg, '%sYou win! The word was indeed %s' %
|
||||
irc.reply('%sYou win! The word was indeed %s' %
|
||||
(game.prefix, game.hidden), prefixName=False)
|
||||
self.endGame(channel)
|
||||
elif not game.guessed and game.tries == 0:
|
||||
irc.reply(msg, '%sYou lose! The word was %s' %
|
||||
irc.reply('%sYou lose! The word was %s' %
|
||||
(game.prefix, game.hidden), prefixName=False)
|
||||
self.endGame(channel)
|
||||
###
|
||||
|
|
Loading…
Reference in New Issue