1
0
Fork 0
mirror of synced 2024-09-28 23:41:41 +12:00

CHanged the hangman usage to check lower, to make cases not sensitive

This commit is contained in:
phxntxm 2016-08-16 10:30:04 -05:00
parent c8730a3b6f
commit 7735bbc081

View file

@ -1,12 +1,8 @@
from discord.ext import commands
from discord.ext.commands.cooldowns import BucketType
import discord
from .utils import config
from .utils import checks
import re
import random
class Game:
def __init__(self, word, creator):
@ -22,10 +18,12 @@ class Game:
def guess_letter(self, letter):
# No matter what, add this to guessed letters so we only have to do one check if a letter was already guessed
self.guessed_letters.append(letter)
if letter in self.word:
if letter.lower() in self.word.lower():
# Replace every occurence of the guessed letter, with the correct letter
# Use the one in the word instead of letter, due to capitalization
self.blanks = "".join(word_letter if letter.lower() == word_letter.lower() else self.blanks[i] for i, word_letter in enumerate(self.word))
self.blanks = "".join(
word_letter if letter.lower() == word_letter.lower() else self.blanks[i] for i, word_letter in
enumerate(self.word))
return True
else:
self.fails += 1
@ -46,14 +44,14 @@ class Game:
def failed(self):
return self.fails == 7
def __str__(self):
# Here's our fancy formatting for the hangman picture
# Each position in the hangman picture is either a space, or part of the man, based on how many fails there are
man = " ——\n"
man += " | |\n"
man += " {} |\n".format("o" if self.fails > 0 else " ")
man += " {}{}{} |\n".format("/" if self.fails > 1 else " ", "|" if self.fails > 2 else " ", "\\" if self.fails > 3 else " ")
man += " {}{}{} |\n".format("/" if self.fails > 1 else " ", "|" if self.fails > 2 else " ",
"\\" if self.fails > 3 else " ")
man += " {} |\n".format("|" if self.fails > 4 else " ")
man += " {} {} |\n".format("/" if self.fails > 5 else " ", "\\" if self.fails > 6 else " ")
man += " |\n"
@ -63,6 +61,7 @@ class Game:
fmt += "```\nGuesses: {}\nWord: {}```".format(", ".join(self.failed_letters), " ".join(self.blanks))
return fmt
class Hangman:
def __init__(self, bot):
self.bot = bot
@ -74,7 +73,6 @@ class Hangman:
self.games[ctx.message.server.id] = game
return game
@commands.group(aliases=['hm'], pass_context=True, no_pm=True, invoke_without_command=True)
@commands.cooldown(1, 30, BucketType.user)
@checks.custom_perms(send_messages=True)
@ -138,10 +136,12 @@ class Hangman:
self.games[ctx.message.server.id] = "placeholder"
# We want to send this message instead of just PM'ing the creator, as some people have PM's turned off/ don't pay attention to them
await self.bot.say("I have just PM'd you {}, please respond there with the phrase you want to start a new hangman game with".format(ctx.message.author.display_name))
await self.bot.say(
"I have just PM'd you {}, please respond there with the phrase you want to start a new hangman game with".format(
ctx.message.author.display_name))
# The only reason we save this variable, is so that we can retrieve the PrivateChannel for it, for use in our wait_for_message command
_msg = await self.bot.whisper("Please respond with the phrase you would like to use for your new hangman game\n"
"Please note that it must be under 30 characters long")
"Please note that it must be under 30 characters long")
msg = await self.bot.wait_for_message(timeout=60.0, channel=_msg.channel, check=check)
if not msg:
@ -151,7 +151,9 @@ class Hangman:
else:
game = self.create(msg.content, ctx)
# Let them know the game has started, then print the current game so that the blanks are shown
await self.bot.say("Alright, a hangman game has just started, you can start guessing now!\n{}".format(str(game)))
await self.bot.say(
"Alright, a hangman game has just started, you can start guessing now!\n{}".format(str(game)))
def setup(bot):
bot.add_cog(Hangman(bot))